-
Notifications
You must be signed in to change notification settings - Fork 6
/
cpu_vs_gpu_plot.py
executable file
·123 lines (98 loc) · 4.23 KB
/
cpu_vs_gpu_plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python
import argparse
import csv
import datetime
import matplotlib.dates
import matplotlib.pyplot
import matplotlib.ticker
import numpy as np
def read_data():
filenames = ['intel-sp.csv',
'intel-dp.csv',
'nvidia-sp.csv',
'nvidia-dp.csv']
legend_names = ['Intel CPU SP',
'Intel CPU DP',
'Nvidia GPU SP',
'Nvidia GPU DP']
colors = ['DodgerBlue','RoyalBlue',
'ForestGreen', 'DarkGreen']
linestyles = ['-', '-', '-', '-', '--', '--']
date_format = '%Y-%m-%d'
data = {}
for filename, legend_name, color, ls in zip(filenames, legend_names, colors, linestyles):
data[legend_name] = {'names': [],
'flops': [],
'dates': [],
'placement_offset': [],
'color': color,
'linestyle': ls,
'legend': legend_name}
with open(filename, 'r') as f:
reader = csv.reader(f)
for row in reader:
data[legend_name]['names'].append(row[0])
data[legend_name]['flops'].append(float(row[1]))
d = datetime.datetime.strptime(row[2].strip(' "'), date_format)
data[legend_name]['dates'].append(d)
data[legend_name]['placement_offset'].append(float(row[4]))
return data
def format_axes(ax, fontsize=8):
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.xaxis.set_ticks_position('bottom')
ax.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%Y'))
ax.yaxis.set_ticks_position('left')
x_minor_locator = matplotlib.dates.MonthLocator(interval=3)
y_major_locator = matplotlib.ticker.MultipleLocator(1000)
y_minor_locator = matplotlib.ticker.MultipleLocator(250)
ax.xaxis.set_minor_locator(x_minor_locator)
ax.yaxis.set_major_locator(y_major_locator)
ax.yaxis.set_minor_locator(y_minor_locator)
for item in (ax.get_xticklabels() + ax.get_yticklabels()):
item.set_fontsize(fontsize)
def text_with_background(ax, x, y, offset, s, color):
label_ygap = 200
t = ax.text(x, y + label_ygap + offset, s,
color=color,
fontsize=7,
horizontalalignment='right')
#t.set_bbox({'color': '1.0', 'alpha': 0.5})
def plot(output_filename):
data = read_data()
# matplotlib.pyplot.rcParams["font.family"] = "Droid Sans"
fig, ax = matplotlib.pyplot.subplots(nrows=1, ncols=1, figsize=(9, 6))
ax.set_axisbelow(True)
ax.yaxis.grid(color='lightgray', linestyle='dotted')
format_axes(ax)
ax.set_xlim(datetime.datetime(2000, 1, 1), datetime.datetime.today())
ax.set_ylim(0, 11000)
label_xgap = datetime.timedelta(100)
for name, series in data.items():
# plot series data
ax.plot(series['dates'], series['flops'], 'o-',
label=name,
color=series['color'],
markeredgecolor=series['color'],
linestyle=series['linestyle'],
linewidth=2.0)
# label series data points with architecture names
if name != 'Intel CPU SP':
for x, y, aname, offset in zip(series['dates'], series['flops'], series['names'], series['placement_offset']):
text_with_background(ax, x, y, offset, aname, 'Blue' if name == 'Intel CPU DP' else series['color'])
# label series
ax.text(series['dates'][-1] + label_xgap, series['flops'][-1], name,
verticalalignment='center',
color=series['color'],
weight='bold',
fontsize=10)
ax.set_xlabel('Release date', size=12)
ax.set_ylabel('Theoretical peak (GFLOPS)', size=11)
matplotlib.pyplot.savefig(output_filename, bbox_inches='tight', transparent=True)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='CPU vs GPU performance plot')
parser.add_argument('-o', '--output',
help='filename for plot output',
default='cpu_vs_gpu.pdf')
args = parser.parse_args()
plot(output_filename=args.output)