/articles/toma

To get this branch, use:
bzr branch http://darksoft.org/webbzr/articles/toma

« back to all changes in this revision

Viewing changes to figs/slide-gen/speedup-steps.py

  • Committer: Suren A. Chilingaryan
  • Date: 2018-09-19 03:32:56 UTC
  • Revision ID: csa@suren.me-20180919033256-w9y50i624l5rehny
Benchmarks and figures for slides

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
 
 
3
import sys
 
4
import numpy as np
 
5
import matplotlib as mpl
 
6
import matplotlib.pyplot as plt
 
7
import matplotlib.ticker as ticker
 
8
import matplotlib.gridspec as gridspec
 
9
 
 
10
font = 14
 
11
mpl.rcParams.update({'font.size': font})
 
12
 
 
13
 
 
14
ops = 3526656000.
 
15
 
 
16
#colors=['green', 'red']
 
17
#colors=['#05500a', '#ff676c']
 
18
#colors=['#05500a', 'lightyellow']
 
19
#colors=['#303030', '#2b83ba', 'limegreen', '#fdd5a5', '#d3ffd5', 'lightyellow']
 
20
#colors=['#303030', '#2b83ba', 'limegreen', '#fdd5a5', '#d3ffd5', 'lightyellow']
 
21
colors=['darkred', '#2b83ba', 'limegreen', '#fdd5a5', '#d3ffd5', 'lightyellow']
 
22
colors1=['darkgreen', 'darkred', '#fdd5a5', '#d3ffd5', 'lightyellow']
 
23
colors2=['limegreen', 'orange', '#d3ffd5', 'lightyellow']
 
24
 
 
25
 
 
26
 
 
27
 
 
28
titles = np.genfromtxt('../bench/gpu.txt', dtype = 'S32', delimiter=",", usecols = [0])
 
29
specs = np.genfromtxt('../bench/specs.txt', names = True, usecols = range(1,10))
 
30
# Convert structured numpy array to standard ndarray
 
31
specs = specs.view(np.float).reshape(specs.shape + (-1,))
 
32
texfl = specs[0]
 
33
years = specs[2]
 
34
flops = specs[3]
 
35
shmem = specs[4]
 
36
tconv = specs[5]
 
37
 
 
38
data = np.genfromtxt('../bench/tex.txt', names = True, usecols = range(1,10))
 
39
# Convert structured numpy array to standard ndarray
 
40
data = data.view(np.float).reshape(data.shape + (-1,))
 
41
# Convert to GUPS
 
42
tex_gups = np.vectorize(lambda v: ops / v / 1000 / 1000 if v > 0 else 0.)(data)
 
43
 
 
44
data = np.genfromtxt('../bench/alu.txt', names = True, usecols = range(1,10))
 
45
# Convert structured numpy array to standard ndarray
 
46
alu_gups = data.view(np.float).reshape(data.shape + (-1,))
 
47
 
 
48
#Extract
 
49
std = np.round(tex_gups[0])
 
50
tex_f1 = np.amax(tex_gups[0:12:4], axis=0)
 
51
tex_f2 = np.amax(tex_gups[1:12:4], axis=0)
 
52
tex_f4 = np.amax(tex_gups[2:12:4], axis=0)
 
53
tex_h4 = np.amax(tex_gups[3:12:4], axis=0)
 
54
 
 
55
#Standard
 
56
lin_simple = tex_f1
 
57
nn_simple = tex_f1
 
58
 
 
59
# Compute maximum for precise and approximate modes
 
60
plin_tex = np.amax([tex_f1, tex_f2], axis=0)
 
61
alin_tex = plin_tex
 
62
pnn_tex = np.amax([plin_tex, tex_f4], axis=0)
 
63
ann_tex = np.amax([pnn_tex, tex_h4], axis=0)
 
64
 
 
65
#Linear & Hybrid
 
66
lin_f1 = np.amax(alu_gups[0:8:4], axis=0)
 
67
lin_f2 = np.amax(alu_gups[1:8:4], axis=0)
 
68
lin_f4 = np.amax(alu_gups[2:8:4], axis=0)
 
69
lin_h4 = np.amax(alu_gups[3:8:4], axis=0)
 
70
 
 
71
#Individual
 
72
alu_fx = np.amax(alu_gups[0:3], axis=0)
 
73
alu_xx = np.amax(alu_gups[0:4], axis=0)
 
74
hyb_fx = np.amax(alu_gups[4:7], axis=0)
 
75
hyb_xx = np.amax(alu_gups[4:8], axis=0)
 
76
 
 
77
#oversampling & NN
 
78
ovs_f1 = alu_gups[8];
 
79
ovs_xx = np.amax(alu_gups[8:12], axis=0)
 
80
nn_f1 = alu_gups[12];
 
81
nn_fx = np.amax(alu_gups[12:15], axis=0)
 
82
#nn_hx = np.amax(alu_gups[15], axis=0)
 
83
nn_hx = alu_gups[15]
 
84
 
 
85
# Compute maximum for precise and approximate modes
 
86
plin = np.amax([lin_f1, lin_f2, lin_f4, plin_tex], axis=0)
 
87
alin = np.amax([plin, lin_h4, ovs_xx, alin_tex], axis=0)
 
88
pnn = np.amax([nn_fx, pnn_tex], axis=0)
 
89
ann = np.amax([pnn, nn_hx, ann_tex], axis=0)
 
90
 
 
91
# Single-slice mode
 
92
plin_slice = np.amax([tex_f1, lin_f1], axis=0)
 
93
alin_slice = np.amax([plin_slice, ovs_f1], axis=0)
 
94
pnn_slice = np.amax([tex_f1, nn_f1], axis=0)
 
95
ann_slice = pnn_slice
 
96
 
 
97
 
 
98
# Compute speed-up
 
99
#def speedup(x): return (x - std) / std
 
100
def speedup(x): return x / std
 
101
 
 
102
#print speedup(plin)
 
103
#print speedup(alin)
 
104
 
 
105
N = len(data[0])
 
106
idx = np.arange(N)
 
107
idx = np.fliplr([idx])[0]
 
108
 
 
109
#print idx
 
110
 
 
111
bar_width = 1.0
 
112
bar_gap = 0.2
 
113
group_gap = 0.6
 
114
 
 
115
mult = 2 * (bar_width + bar_gap) + group_gap;
 
116
 
 
117
def get_change(x, r): return [x[n]/x[n-1] for n in r]
 
118
flops_change = get_change(flops, range(1,6))
 
119
texfl_change = get_change(texfl, range(1,6))
 
120
shmem_change = get_change(shmem, range(1,6))
 
121
tconv_change = get_change(tconv, range(1,6))
 
122
std_change = get_change(std, range(1,6))
 
123
plin_change = get_change(plin, range(1,6))
 
124
pnn_change = get_change(pnn, range(1,6))
 
125
 
 
126
 
 
127
seq = range(5)
 
128
seq1 = range(6)
 
129
seq2 = range(3)
 
130
#seq = years[0:6]
 
131
 
 
132
def speedup0(x,y): return x / x[0]
 
133
 
 
134
 
 
135
fig = plt.figure(figsize=(10, 6)) 
 
136
gs = gridspec.GridSpec(1, 3, width_ratios=[3, 0, 3]) 
 
137
plots = [ plt.subplot(gs[0]), plt.subplot(gs[2]) ]
 
138
 
 
139
p = plots[0]
 
140
 
 
141
p.set_xticks(seq1)
 
142
p.set_xticklabels(titles[0:6])
 
143
p.set_ylabel('speed-up relative to GTX295 (times)')
 
144
p.set_ylim(0, 14)
 
145
p_spec = p.plot(seq1, speedup0(flops[0:6], flops[0:6]), "-o", color=colors[0], markersize=3)
 
146
p_tex = p.plot(seq1, speedup0(texfl[0:6], texfl[0:6]), "-o", color=colors[1], markersize=3)
 
147
p_shm = p.plot(seq1, speedup0(shmem[0:6], shmem[0:6]), "-o", color=colors[2], markersize=3)
 
148
p_cnv = p.plot(seq1, speedup0(tconv[0:6], tconv[0:6]), "-o", color=colors[3], markersize=3)
 
149
 
 
150
fig.subplots_adjust(bottom=0.3)
 
151
legend = plt.figlegend(
 
152
    (p_spec[0], p_tex[0], p_shm[0], p_cnv[0]), 
 
153
    ("FP throughput (Peak)", "Texture throuhgput (Peak)", "Shared memory bandwidth (Peak)", "Throughput of type-conversions (Peak)",), 
 
154
    loc='lower center', bbox_to_anchor=(0.44,0.04), ncol=2)
 
155
 
 
156
p = plots[1]
 
157
 
 
158
#p.set_xticks(seq2)
 
159
#p.set_xticklabels(titles[6:9])
 
160
#p.set_ylim(0, 10)
 
161
#p.set_ylabel('speed-up (times)')
 
162
#p_spec = p.plot(seq2, speedup0(flops[6:9], flops[6:9]), "-o", color=colors[0], markersize=3)
 
163
#p_std = p.plot(seq2, speedup0(std[6:9], flops[6:9]), "-o", color=colors[1], markersize=3)
 
164
#p_lin = p.plot(seq2, speedup0(plin[6:9], flops[6:9]), "-o", color=colors[2], markersize=3)
 
165
#p_nn = p.plot(seq2, speedup0(pnn[6:9], flops[6:9]), "-o", color=colors[3], markersize=3)
 
166
 
 
167
#p.set_xticks(seq)
 
168
#p.set_xticklabels(titles[1:6])
 
169
#p.set_ylim(1, 5)
 
170
#p_spec = p.plot(seq, flops_change, "-o", color=colors[0], markersize=3)
 
171
#p_std = p.plot(seq, std_change, "-o", color=colors[1], markersize=3)
 
172
#p_lin = p.plot(seq, plin_change, "-o", color=colors[2], markersize=3)
 
173
#p_nn = p.plot(seq, pnn_change, "-o", color=colors[3], markersize=3)
 
174
 
 
175
bar_width = 1.0
 
176
bar_gap = 0.2
 
177
group_gap = 1.8
 
178
 
 
179
mult = 4 * (bar_width + bar_gap) + group_gap;
 
180
 
 
181
p.set_ylabel('speed-up & slow-down relative\nto previous architecture (times)')
 
182
 
 
183
p.set_xticks(0.45 * mult + mult * np.arange(5))
 
184
p.set_xticklabels(titles[1:6])
 
185
 
 
186
@ticker.FuncFormatter
 
187
def yformatter(x, pos):
 
188
    return  ("%.1f" % (x + 1)) if  (x >= 0) else ("2/%u" % abs(2 * x - 2)) if (round(x) != x) else ("1/%u" % abs(x - 1))
 
189
 
 
190
p.set_ylim(-1, 2.1)
 
191
p.yaxis.set_major_formatter(yformatter)
 
192
 
 
193
 
 
194
def speedup1(x): return (x - 1) if (x >=1) else (-1/x + 1)
 
195
 
 
196
 
 
197
for idx in range(5):
 
198
    p_tconv = p.bar(mult * idx + 3 * (bar_width + bar_gap), speedup1(tconv_change[idx]), bar_width, color=colors[3], edgecolor='black')
 
199
    p_shmem = p.bar(mult * idx + 2 * (bar_width + bar_gap), speedup1(shmem_change[idx]), bar_width, color=colors[2], edgecolor='black')
 
200
    p_texfl = p.bar(mult * idx + 1 * (bar_width + bar_gap), speedup1(texfl_change[idx]), bar_width, color=colors[1], edgecolor='black')
 
201
    p_spec = p.bar(mult * idx + 0 * (bar_width + bar_gap), speedup1(flops_change[idx]), bar_width, color=colors[0], edgecolor='black')
 
202
 
 
203
 
 
204
 
 
205
va = [0,  -.05, 0, -.05, 0, -.05, 0 ]
 
206
for t, y in zip( plots[0].get_xticklabels( ), va ):
 
207
    t.set_y( y )
 
208
for t, y in zip( plots[1].get_xticklabels( ), va ):
 
209
    t.set_y( y )
 
210
 
 
211
 
 
212
plt.savefig('speedup-steps.png', dpi=300, bbox_inches='tight')#, bbox_extra_artists=(legend,))
 
213
 
 
214
plt.close()
 
215