/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/algorithms.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.pyplot as plt
 
6
 
 
7
ops = 3526656000.
 
8
 
 
9
#colors=['green', 'red']
 
10
#colors=['#05500a', '#ff676c']
 
11
colors=['#05500a', 'lightyellow']
 
12
 
 
13
#colors2=['black', '#011268', '#15601a', '#ff676c', 'lightyellow']
 
14
colors2=['#303030', '#2b83ba', 'limegreen', '#fdd5a5', '#d3ffd5', 'lightyellow']
 
15
 
 
16
 
 
17
titles = np.genfromtxt('../bench/gpu.txt', dtype = 'S32', delimiter=",", usecols = [0])
 
18
specs = np.genfromtxt('../bench/specs.txt', names = True, usecols = range(1,10))
 
19
# Convert structured numpy array to standard ndarray
 
20
specs = specs.view(np.float).reshape(specs.shape + (-1,))
 
21
 
 
22
data = np.genfromtxt('../bench/tex.txt', names = True, usecols = range(1,10))
 
23
# Convert structured numpy array to standard ndarray
 
24
data = data.view(np.float).reshape(data.shape + (-1,))
 
25
# Convert to GUPS
 
26
tex_gups = np.vectorize(lambda v: ops / v / 1000 / 1000 if v > 0 else 0.)(data)
 
27
 
 
28
data = np.genfromtxt('../bench/alu.txt', names = True, usecols = range(1,10))
 
29
# Convert structured numpy array to standard ndarray
 
30
alu_gups = data.view(np.float).reshape(data.shape + (-1,))
 
31
 
 
32
#Extract
 
33
std = np.round(tex_gups[0])
 
34
tex_f1 = np.amax(tex_gups[0:12:4], axis=0)
 
35
tex_f2 = np.amax(tex_gups[1:12:4], axis=0)
 
36
tex_f4 = np.amax(tex_gups[2:12:4], axis=0)
 
37
tex_h4 = np.amax(tex_gups[3:12:4], axis=0)
 
38
 
 
39
#Standard
 
40
lin_simple = tex_f1
 
41
nn_simple = tex_f1
 
42
 
 
43
# Compute maximum for precise and approximate modes
 
44
plin_tex = np.amax([tex_f1, tex_f2], axis=0)
 
45
alin_tex = plin_tex
 
46
pnn_tex = np.amax([plin_tex, tex_f4], axis=0)
 
47
ann_tex = np.amax([pnn_tex, tex_h4], axis=0)
 
48
 
 
49
#Linear & Hybrid
 
50
lin_f1 = np.amax(alu_gups[0:8:4], axis=0)
 
51
lin_f2 = np.amax(alu_gups[1:8:4], axis=0)
 
52
lin_f4 = np.amax(alu_gups[2:8:4], axis=0)
 
53
lin_h4 = np.amax(alu_gups[3:8:4], axis=0)
 
54
 
 
55
#Individual
 
56
alu_fx = np.amax(alu_gups[0:3], axis=0)
 
57
alu_xx = np.amax(alu_gups[0:4], axis=0)
 
58
hyb_fx = np.amax(alu_gups[4:7], axis=0)
 
59
hyb_xx = np.amax(alu_gups[4:8], axis=0)
 
60
 
 
61
#oversampling & NN
 
62
ovs_f1 = alu_gups[8];
 
63
ovs_xx = np.amax(alu_gups[8:12], axis=0)
 
64
nn_f1 = alu_gups[12];
 
65
nn_fx = np.amax(alu_gups[12:15], axis=0)
 
66
#nn_hx = np.amax(alu_gups[15], axis=0)
 
67
nn_hx = alu_gups[15]
 
68
 
 
69
# Compute maximum for precise and approximate modes
 
70
plin = np.amax([lin_f1, lin_f2, lin_f4, plin_tex], axis=0)
 
71
alin = np.amax([plin, lin_h4, ovs_xx, alin_tex], axis=0)
 
72
pnn = np.amax([nn_fx, pnn_tex], axis=0)
 
73
ann = np.amax([pnn, nn_hx, ann_tex], axis=0)
 
74
 
 
75
# Single-slice mode
 
76
plin_slice = np.amax([tex_f1, lin_f1], axis=0)
 
77
alin_slice = np.amax([plin_slice, ovs_f1], axis=0)
 
78
pnn_slice = np.amax([tex_f1, nn_f1], axis=0)
 
79
ann_slice = pnn_slice
 
80
 
 
81
 
 
82
# Compute speed-up
 
83
#def speedup(x): return (x - std) / std
 
84
def speedup(x): return x / std
 
85
 
 
86
#print speedup(plin)
 
87
#print speedup(alin)
 
88
 
 
89
N = len(data[0])
 
90
idx = np.arange(N)
 
91
idx = np.fliplr([idx])[0]
 
92
 
 
93
#print idx
 
94
 
 
95
bar_width = 1.0
 
96
bar_gap = 0.2
 
97
group_gap = 0.6
 
98
 
 
99
mult = (bar_width + bar_gap) + group_gap;
 
100
 
 
101
fig, (p) = plt.subplots(1, 1)
 
102
 
 
103
#p_atex = p.barh(mult * idx + 2 * (bar_width + bar_gap), speedup(atex), bar_width, color=colors[1], edgecolor='black')
 
104
#p_ptex = p.barh(mult * idx + 2 * (bar_width + bar_gap), speedup(ptex), bar_width, color=colors[0], edgecolor='black')
 
105
 
 
106
#p_ann = p.barh(mult * idx, speedup(ann), bar_width, hatch='\\\\', color=colors2[5], edgecolor='black')
 
107
p_pnn = p.barh(mult * (idx + 0.35), speedup(pnn), bar_width, color=colors2[2], edgecolor='black')
 
108
 
 
109
#p_alin = p.barh(mult * idx + bar_width + bar_gap, speedup(alin), bar_width, hatch="", color=colors2[4], edgecolor='black')
 
110
p_plin = p.barh(mult * (idx + 0.35), speedup(plin), bar_width, hatch="", color=colors2[1], edgecolor='black')
 
111
 
 
112
ax = plt.gca()
 
113
ax.xaxis.grid(alpha=0.25)
 
114
plt.xticks(np.arange(1,8.1,0.5))
 
115
plt.yticks(mult * idx + (bar_width + bar_gap)/2, titles)
 
116
 
 
117
plt.xlabel("speedup (times)")
 
118
plt.xlim(1, 8.0)
 
119
plt.ylim(0, 9*mult - group_gap)
 
120
 
 
121
 
 
122
legend = p.legend(
 
123
    (p_plin[0], p_pnn[0]), 
 
124
    ("Linear", "Nearest-Neighbor"), 
 
125
    loc='upper right')
 
126
    #, bbox_to_anchor=(0.5,-0.2), ncol=3)
 
127
 
 
128
#plt.gca().add_artist(legend2)
 
129
 
 
130
 
 
131
plt.savefig('algorithms.png', dpi=300, bbox_inches='tight', bbox_extra_artists=(legend,))
 
132
plt.close()
 
133
sys.exit()
 
134
 
 
135
 
 
136
fig, (p) = plt.subplots(1, 1)
 
137
 
 
138
#p_atex = p.barh(mult * idx + 2 * (bar_width + bar_gap), speedup(atex), bar_width, color=colors[1], edgecolor='black')
 
139
#p_ptex = p.barh(mult * idx + 2 * (bar_width + bar_gap), speedup(ptex), bar_width, color=colors[0], edgecolor='black')
 
140
 
 
141
p_alin = p.barh(mult * idx + bar_width + bar_gap, speedup(alin), bar_width, hatch="", color=colors[1], edgecolor='black')
 
142
p_plin = p.barh(mult * idx + bar_width + bar_gap, speedup(plin), bar_width, hatch="", color=colors[0], edgecolor='black')
 
143
 
 
144
p_ann = p.barh(mult * idx, speedup(ann), bar_width, hatch='\\\\', color=colors[1], edgecolor='black')
 
145
p_pnn = p.barh(mult * idx, speedup(pnn), bar_width, hatch='\\\\', color=colors[0], edgecolor='black')
 
146
 
 
147
ax = plt.gca()
 
148
ax.xaxis.grid(alpha=0.25)
 
149
plt.xticks(np.arange(1,8.1,0.5))
 
150
plt.yticks(mult * idx + 2 * (bar_width + bar_gap)/2, titles)
 
151
 
 
152
plt.xlabel("speedup (times)")
 
153
plt.xlim(1, 8.0)
 
154
plt.ylim(0, 9*mult - group_gap)
 
155
 
 
156
legend = p.legend(
 
157
    (p_plin[0], p_pnn[0], p_alin[0], p_ann[0]), 
 
158
    ("Linear", "Nearest",
 
159
     "Linear & Oversampling / Half-float", "Nearest / Half-float"), 
 
160
    loc='upper center', bbox_to_anchor=(0.5,-0.1), ncol=2)
 
161
 
 
162
plt.savefig('speedup.pdf', dpi=300, bbox_inches='tight', bbox_extra_artists=(legend,))
 
163
plt.close()
 
164
 
 
165
 
 
166
fig, (p) = plt.subplots(1, 1)
 
167
 
 
168
p_alin = p.barh(mult * idx + bar_width + bar_gap, speedup(alin_tex), bar_width, hatch="", color=colors[1], edgecolor='black')
 
169
p_plin = p.barh(mult * idx + bar_width + bar_gap, speedup(plin_tex), bar_width, hatch="", color=colors[0], edgecolor='black')
 
170
 
 
171
p_ann = p.barh(mult * idx, speedup(ann_tex), bar_width, hatch='\\\\', color=colors[1], edgecolor='black')
 
172
p_pnn = p.barh(mult * idx, speedup(pnn_tex), bar_width, hatch='\\\\', color=colors[0], edgecolor='black')
 
173
 
 
174
ax = plt.gca()
 
175
ax.xaxis.grid(alpha=0.25)
 
176
plt.xticks(np.arange(1,8.1,0.5))
 
177
plt.yticks(mult * idx + 2 * (bar_width + bar_gap)/2, titles)
 
178
 
 
179
plt.xlabel("speedup (times)")
 
180
plt.xlim(1, 8.0)
 
181
plt.ylim(0, 9*mult - group_gap)
 
182
 
 
183
legend = p.legend(
 
184
    (p_plin[0], p_pnn[0], p_alin[0], p_ann[0]), 
 
185
    ("Linear", "Nearest",
 
186
     "Linear / Half-float", "Nearest / Half-float"), 
 
187
    loc='upper center', bbox_to_anchor=(0.5,-0.1), ncol=2)
 
188
 
 
189
plt.savefig('speedup_tex.pdf', dpi=300, bbox_inches='tight', bbox_extra_artists=(legend,))
 
190
plt.close()
 
191
 
 
192
 
 
193
fig, (p) = plt.subplots(1, 1)
 
194
 
 
195
p_alin = p.barh(mult * idx + bar_width + bar_gap, speedup(alin_slice), bar_width, hatch="", color=colors[1], edgecolor='black')
 
196
p_plin = p.barh(mult * idx + bar_width + bar_gap, speedup(plin_slice), bar_width, hatch="", color=colors[0], edgecolor='black')
 
197
 
 
198
#p_ann = p.barh(mult * idx, speedup(ann_slice), bar_width, hatch='\\\\', color=colors[1], edgecolor='black')
 
199
p_pnn = p.barh(mult * idx, speedup(pnn_slice), bar_width, hatch='\\\\', color=colors[0], edgecolor='black')
 
200
 
 
201
ax = plt.gca()
 
202
ax.xaxis.grid(alpha=0.25)
 
203
plt.xticks(np.arange(1,8.1,0.5))
 
204
plt.yticks(mult * idx + 2 * (bar_width + bar_gap)/2, titles)
 
205
 
 
206
plt.xlabel("speedup (times)")
 
207
plt.xlim(1, 8.0)
 
208
plt.ylim(0, 9*mult - group_gap)
 
209
 
 
210
legend = p.legend(
 
211
    (p_plin[0], p_pnn[0], p_alin[0], p_ann[0]), 
 
212
    ("Linear", "Nearest",
 
213
     "Oversampling"), 
 
214
    loc='upper center', bbox_to_anchor=(0.5,-0.1), ncol=2)
 
215
 
 
216
plt.savefig('speedup_slice.pdf', dpi=300, bbox_inches='tight', bbox_extra_artists=(legend,))
 
217
plt.close()
 
218