/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.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
colors2=['#303030', '#2b83ba', 'limegreen', 'red', 'lightyellow', '#d3ffd5']
 
16
 
 
17
 
 
18
titles = np.genfromtxt('../bench/gpu.txt', dtype = 'S32', delimiter=",", usecols = [0])
 
19
specs = np.genfromtxt('../bench/specs.txt', names = True, usecols = range(1,10))
 
20
# Convert structured numpy array to standard ndarray
 
21
specs = specs.view(np.float).reshape(specs.shape + (-1,))
 
22
 
 
23
data = np.genfromtxt('../bench/tex.txt', names = True, usecols = range(1,10))
 
24
# Convert structured numpy array to standard ndarray
 
25
data = data.view(np.float).reshape(data.shape + (-1,))
 
26
# Convert to GUPS
 
27
tex_gups = np.vectorize(lambda v: ops / v / 1000 / 1000 if v > 0 else 0.)(data)
 
28
 
 
29
data = np.genfromtxt('../bench/alu.txt', names = True, usecols = range(1,10))
 
30
# Convert structured numpy array to standard ndarray
 
31
alu_gups = data.view(np.float).reshape(data.shape + (-1,))
 
32
 
 
33
#Extract
 
34
std = np.round(tex_gups[0])
 
35
tex_f1 = np.amax(tex_gups[0:12:4], axis=0)
 
36
tex_f2 = np.amax(tex_gups[1:12:4], axis=0)
 
37
tex_f4 = np.amax(tex_gups[2:12:4], axis=0)
 
38
tex_h4 = np.amax(tex_gups[3:12:4], axis=0)
 
39
 
 
40
#Standard
 
41
lin_simple = tex_f1
 
42
nn_simple = tex_f1
 
43
 
 
44
# Compute maximum for precise and approximate modes
 
45
plin_tex = np.amax([tex_f1, tex_f2], axis=0)
 
46
alin_tex = plin_tex
 
47
pnn_tex = np.amax([plin_tex, tex_f4], axis=0)
 
48
ann_tex = np.amax([pnn_tex, tex_h4], axis=0)
 
49
 
 
50
#Linear & Hybrid
 
51
lin_f1 = np.amax(alu_gups[0:8:4], axis=0)
 
52
lin_f2 = np.amax(alu_gups[1:8:4], axis=0)
 
53
lin_f4 = np.amax(alu_gups[2:8:4], axis=0)
 
54
lin_h4 = np.amax(alu_gups[3:8:4], axis=0)
 
55
 
 
56
#Individual
 
57
alu_fx = np.amax(alu_gups[0:3], axis=0)
 
58
alu_xx = np.amax(alu_gups[0:4], axis=0)
 
59
hyb_fx = np.amax(alu_gups[4:7], axis=0)
 
60
hyb_xx = np.amax(alu_gups[4:8], axis=0)
 
61
 
 
62
#oversampling & NN
 
63
ovs_f1 = alu_gups[8];
 
64
ovs_xx = np.amax(alu_gups[8:12], axis=0)
 
65
nn_f1 = alu_gups[12];
 
66
nn_fx = np.amax(alu_gups[12:15], axis=0)
 
67
#nn_hx = np.amax(alu_gups[15], axis=0)
 
68
nn_hx = alu_gups[15]
 
69
 
 
70
# Compute maximum for precise and approximate modes
 
71
plin = np.amax([lin_f1, lin_f2, lin_f4, plin_tex], axis=0)
 
72
alin = np.amax([plin, lin_h4, ovs_xx, alin_tex], axis=0)
 
73
pnn = np.amax([nn_fx, pnn_tex], axis=0)
 
74
ann = np.amax([pnn, nn_hx, ann_tex], axis=0)
 
75
 
 
76
# Single-slice mode
 
77
plin_slice = np.amax([tex_f1, lin_f1], axis=0)
 
78
alin_slice = np.amax([plin_slice, ovs_f1], axis=0)
 
79
pnn_slice = np.amax([tex_f1, nn_f1], axis=0)
 
80
ann_slice = pnn_slice
 
81
 
 
82
 
 
83
# Compute speed-up
 
84
#def speedup(x): return (x - std) / std
 
85
def speedup(x): return x / std
 
86
 
 
87
#print speedup(plin)
 
88
#print speedup(alin)
 
89
 
 
90
N = len(data[0])
 
91
idx = np.arange(N)
 
92
idx = np.fliplr([idx])[0]
 
93
 
 
94
#print idx
 
95
 
 
96
bar_width = 1.0
 
97
bar_gap = 0.2
 
98
group_gap = 0.6
 
99
 
 
100
mult = 2 * bar_width + bar_gap + group_gap;
 
101
 
 
102
fig, (p) = plt.subplots(1, 1)
 
103
 
 
104
#p_atex = p.barh(mult * idx + 2 * (bar_width + bar_gap), speedup(atex), bar_width, color=colors[1], edgecolor='black')
 
105
#p_ptex = p.barh(mult * idx + 2 * (bar_width + bar_gap), speedup(ptex), bar_width, color=colors[0], edgecolor='black')
 
106
 
 
107
idx = idx + 0.3
 
108
p_alin = p.barh(mult * idx + bar_width + bar_gap, speedup(alin), bar_width, hatch="", color=colors2[4], edgecolor='black')
 
109
p_plin = p.barh(mult * idx + bar_width + bar_gap, speedup(plin), bar_width, hatch="", color=colors2[3], edgecolor='black')
 
110
p_plin_alu = p.barh(mult * idx + bar_width + bar_gap, speedup(alu_fx), bar_width, hatch="", color=colors2[2], edgecolor='black')
 
111
p_plin_tex = p.barh(mult * idx + bar_width + bar_gap, speedup(plin_tex), bar_width, hatch="", color=colors2[1], edgecolor='black')
 
112
p_plin_simple = p.barh(mult * idx + bar_width + bar_gap, speedup(lin_simple), bar_width, hatch="", color=colors2[0], edgecolor='black')
 
113
p_plin_white = p.barh(mult * idx + bar_width + bar_gap, speedup(std), bar_width, hatch="", color="white", edgecolor='black')
 
114
p_plin_col5 = p.barh(mult * idx + bar_width + bar_gap, speedup(std), bar_width, hatch="", color=colors2[5], edgecolor='black')
 
115
 
 
116
 
 
117
p_ann = p.barh(mult * idx, speedup(ann), bar_width, hatch='\\\\', color=colors2[5], edgecolor='black')
 
118
p_pnn = p.barh(mult * idx, speedup(pnn), bar_width, hatch='\\\\', color=colors2[3], edgecolor='black')
 
119
p_pnn_alu = p.barh(mult * idx, speedup(nn_fx), bar_width, hatch='\\\\', color=colors2[2], edgecolor='black')
 
120
p_pnn_tex = p.barh(mult * idx, speedup(pnn_tex), bar_width, hatch='\\\\', color=colors2[1], edgecolor='black')
 
121
p_pnn_simple = p.barh(mult * idx, speedup(nn_simple), bar_width, hatch='\\\\', color=colors2[0], edgecolor='black')
 
122
p_pnn_white = p.barh(mult * idx, speedup(std), bar_width, hatch='\\\\', color="white", edgecolor='black')
 
123
 
 
124
ax = plt.gca()
 
125
ax.xaxis.grid(alpha=0.25)
 
126
plt.xticks(np.arange(1,8.1,0.5))
 
127
plt.yticks(mult * (idx - 0.17) + bar_width + bar_gap/2, titles)
 
128
 
 
129
plt.xlabel("speedup (times)")
 
130
plt.xlim(1, 8.0)
 
131
plt.ylim(0, 9*mult)# - group_gap)
 
132
 
 
133
legend2 = p.legend(
 
134
    (p_plin_white[0], p_pnn_white[0]),
 
135
    ("Linear", "Nearest"),
 
136
    loc='right lower', bbox_to_anchor=(1.24,0.5), ncol=1)
 
137
 
 
138
legend = p.legend(
 
139
    (p_plin_simple[0], p_plin_tex[0], p_plin_alu[0], p_plin[0], p_alin[0], p_plin_col5), 
 
140
    ("Re-mapped", "Multi-slice", "ALU-based", "Hybrid", "Oversampling", "Half-Precision"), 
 
141
    loc='right upper', bbox_to_anchor=(1.32,1.02), ncol=1)
 
142
 
 
143
#legend = p.legend(
 
144
#    (p_plin_simple[0], p_pnn_simple[0], p_plin_tex[0], p_pnn_tex[0], p_plin_alu[0], p_pnn_alu[0], p_plin[0], p_pnn[0], p_alin[0], p_ann[0]), 
 
145
#    ("Single", "Single",
 
146
#     "Multi-slice", "Multi-slice",
 
147
#     "ALU-based", "ALU-based", 
 
148
#     "Hybrid", "Hybrid",
 
149
#     "Oversampling", "Half-precision"), 
 
150
#    loc='upper center', bbox_to_anchor=(0.5,-0.3), ncol=3)
 
151
 
 
152
plt.gca().add_artist(legend2)
 
153
 
 
154
 
 
155
 
 
156
plt.savefig('speedup.png', dpi=300, bbox_inches='tight', bbox_extra_artists=(legend,))
 
157
plt.close()
 
158