-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdnn_analysis.py
More file actions
332 lines (273 loc) · 14.2 KB
/
dnn_analysis.py
File metadata and controls
332 lines (273 loc) · 14.2 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/usr/bin/python2.7
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib.patches as patches
from matplotlib.ticker import FuncFormatter
import numpy as np
import math
# This module is used for visualizing the result.
# This is a function to plot the utilization of buffer
# and systolic array for a single DNN under one particular
# hardware configuration
def plot_util_dnn(res, suffix):
# initialize the array from the result first.
sa_util = []
buf_util = []
# comp_bound = {'x':[], 'y': []}
# mem_bound = {'x':[], 'y': []}
cnt = 1
# the content in the result is listed as:
for item in res:
sa_util.append(item[2])
buf_util.append(item[3])
# if item[-1] == 'C':
# comp_bound['x'].append(cnt)
# comp_bound['y'].append(item[2]*item[3])
# else:
# mem_bound['x'].append(cnt)
# mem_bound['y'].append(item[2]*item[3])
# cnt += 1
x_axis_ls = range(1, len(res)+1)
plt.rc('font', size=10)
ax1 = plt.figure(figsize=(8, 3)).add_subplot(111)
ax1.set_ylabel('PE util', fontsize=14, fontweight='bold')
plt.xticks(rotation=60)
plt.setp(ax1.spines.values(), linewidth=2)
ax2 = ax1.twinx()
ax2.set_ylabel('Buf Util', fontsize=14, fontweight='bold')
p1 = ax1.plot(x_axis_ls, sa_util, color='#71985E', linestyle=':', linewidth=2, \
marker='d',markersize=8, markeredgewidth=1.5, markeredgecolor='k');
p2 = ax2.plot(x_axis_ls, buf_util, color='#FFBF56', linestyle=':', linewidth=2, \
marker='o',markersize=8, markeredgewidth=1.5, markeredgecolor='k');
# p3 = ax1.bar(comp_bound['x'], comp_bound['y'], 0.5, align='center',color='#8154D1',\
# edgecolor=['k']*len(x_axis_ls), linewidth=1.5, hatch="/");
# p4 = ax2.bar(mem_bound['x'], mem_bound['y'], 0.5, align='center', \
# color='#5b87f2', edgecolor=['k']*len(x_axis_ls), linewidth=1.5, hatch="\\");
# plt.subplots_adjust(left=0.1, bottom=0.25, right=0.9, top=0.9,
# wspace=0.2, hspace=0.2)
plt.xticks(x_axis_ls, [ "Layer" + str(n) for n in x_axis_ls])
ax1.set_ylim(0.0, 1.0)
ax2.set_ylim(0.0, 1.0)
ax1.tick_params(axis="y",direction="in")
ax2.tick_params(axis="y",direction="in")
ax1.tick_params(axis="x",direction="in")
plt.grid(color='grey', which='major', axis='y', linestyle='--')
ax1.yaxis.set_major_formatter(FuncFormatter(lambda y, _: '{:.0%}'.format(y)))
ax2.yaxis.set_major_formatter(FuncFormatter(lambda y, _: '{:.0%}'.format(y)))
plt.legend((p1[0], p2[0]), ('SA util', 'Buf util',),\
bbox_to_anchor=(0., 1.01, 1., .101), loc=3,
ncol=2, mode="expand", borderaxespad=0., frameon=False)
ax1.set_axisbelow(True)
plt.savefig(suffix+"_layer_util.pdf");
print(sa_util)
print(buf_util)
def profile_layer_cycle(res, suffix):
# initialize the array from the result first.
total_transfer = []
total_cycle = []
# the content in the result is listed as:
for item in res:
total_transfer.append(item[0])
total_cycle.append(item[1])
x_axis_ls = range(1, len(res)+1)
plt.rc('font', size=10)
ax1 = plt.figure(figsize=(8, 3)).add_subplot(111)
ax1.set_ylabel('Norm. Energy', fontsize=14, fontweight='bold')
plt.xticks(rotation=60)
plt.setp(ax1.spines.values(), linewidth=2)
ax2 = ax1.twinx()
ax2.set_ylabel('Norm. Speedup', fontsize=14, fontweight='bold')
p1 = ax1.plot(x_axis_ls,[float(i)/total_transfer[0] for i in total_transfer], color='#71985E', linestyle=':', linewidth=2, \
marker='d',markersize=8, markeredgewidth=1.5, markeredgecolor='k');
p2 = ax2.plot(x_axis_ls, [float(i)/total_cycle[0] for i in total_cycle], color='#FFBF56', linestyle=':', linewidth=2, \
marker='o',markersize=8, markeredgewidth=1.5, markeredgecolor='k');
plt.subplots_adjust(left=0.1, bottom=0.25, right=0.9, top=0.9,
wspace=0.2, hspace=0.2)
# ax1.set_ylim(pow(10, 6), pow(10, 8))
# ax2.set_ylim(pow(10, 6), pow(10, 8))
ax1.set_yscale('log')
ax2.set_yscale('log')
plt.xticks(x_axis_ls, [ "Layer" + str(n) for n in x_axis_ls])
ax1.tick_params(axis="y",direction="in")
ax2.tick_params(axis="y",direction="in")
ax1.tick_params(axis="x",direction="in")
plt.grid(color='grey', which='major', axis='y', linestyle='--')
plt.legend((p1[0], p2[0]), ('mem. traffic', 'cycle'), \
bbox_to_anchor=(0., 1.01, 1., .101), loc=3,
ncol=2, mode="expand", borderaxespad=0., frameon=False)
ax1.set_axisbelow(True)
plt.savefig(suffix+"_layer_cycle.pdf");
print(total_transfer)
print(total_cycle)
'''
The functions below are to profile the impacts of different bandwidth,
buffer size, and systolic array size on overall system.
'''
def plot_sa_size(res, low, high, step):
plt.rc('font', size=10)
ax1 = plt.figure(figsize=(16, 3)).add_subplot(111)
ax1.set_ylabel('PE Util', fontsize=14, fontweight='bold')
ax1.set_xlabel('Systolic Array Size', fontsize=14, fontweight='bold')
plt.setp(ax1.spines.values(), linewidth=2)
ax2 = ax1.twinx()
ax2.set_ylabel('Buf Util', fontsize=14, fontweight='bold')
p1 = ax1.bar([i - 0.3 for i in range(len(res['sa_avg']))], res['sa_avg'], \
0.3, yerr=res['sa_std'], align='center',color='#8154D1',\
edgecolor=['k']*len(res['sa_avg']), linewidth=1.5, hatch="/");
p2 = ax2.bar(range(len(res['buf_avg'])), res['buf_avg'], 0.3, yerr=res['buf_std'], align='center', \
color='#5b87f2', edgecolor=['k']*len(res['buf_avg']), linewidth=1.5, hatch="\\");
plt.subplots_adjust(left=0.1, bottom=0.20, right=0.9, top=0.9,
wspace=0.2, hspace=0.2)
ax2.set_ylim(0.0, 1.0)
ax1.set_ylim(0.0, 1.0)
plt.xticks(range(len(res['sa_avg'])), range(low, high+step, step))
plt.legend((p1[0], p2[0]), ('SA util', 'Buf util'), \
bbox_to_anchor=(0., 1.01, 1., .101), loc=3, \
ncol=2, mode="expand", borderaxespad=0., frameon=False)
ax1.set_axisbelow(True)
plt.savefig("profile_sa.pdf");
def plot_sa_cycle(res, low, high, step):
plt.rc('font', size=10)
ax1 = plt.figure(figsize=(6, 2.5)).add_subplot(111)
ax1.set_ylabel('Norm. Speedup', fontsize=14, fontweight='bold')
ax1.set_xlabel('Systolic Array Size', fontsize=14, fontweight='bold')
plt.setp(ax1.spines.values(), linewidth=2)
ax2 = ax1.twinx()
ax1.tick_params(axis="both",direction="in",which="both")
ax2.tick_params(axis="both",direction="in",which="both",right=False)
ax2.set_ylabel('Norm. Energy', fontsize=14, fontweight='bold')
p1 = ax1.bar([i - 0.3 for i in range(len(res['cycle_avg']))], \
[res['cycle_avg'][0]/float(i) for i in res['cycle_avg']], \
0.3, align='center',color='#71985E',\
edgecolor=['k']*len(res['cycle_avg']), linewidth=1.5, hatch="/");
p2 = ax2.bar(range(len(res['traffic_avg'])), \
[float(i)/res['traffic_avg'][0] for i in res['traffic_avg']], 0.3, align='center', \
color='#FFBF56', edgecolor=['k']*len(res['traffic_avg']), linewidth=1.5, hatch="\\");
plt.subplots_adjust(left=0.1, bottom=0.20, right=0.9, top=0.9,
wspace=0.2, hspace=0.2)
ax1.set_yscale('log')
# ax2.set_yscale('log')
ax1.set_ylim(0.5,100)
ax2.set_ylim(0, 1)
# ax1.set_ylim(pow(10, math.floor(math.log10(min(res['cycle_avg'])))), \
# pow(10, math.ceil(math.log10(max(res['cycle_avg'])))))
# ax2.set_ylim(pow(10, math.floor(math.log10(min(res['traffic_avg'])))), \
# pow(10, math.ceil(math.log10(max(res['traffic_avg'])))))
# ax2.yaxis.set_major_formatter(FuncFormatter(lambda y, _: '{:.1f}'.format(y)))
# ax2.yaxis.set_minor_formatter(FuncFormatter(lambda y, _: '{:.1f}'.format(y)))
plt.xticks(range(len(res['sa_avg'])), range(low, high+step, step))
ax2.set_yticks([0, 0.2, 0.4, 0.6, 0.8, 1.0])
plt.legend((p1[0], p2[0]), ('speedup', 'Energy'), \
bbox_to_anchor=(0., 1.01, 1., .101), loc=3, \
ncol=2, mode="expand", borderaxespad=0., frameon=False)
ax1.set_axisbelow(True)
plt.savefig("profile_sa_cycle.pdf");
def plot_buf_size(res, low, high, step, base, scale):
plt.rc('font', size=10)
ax1 = plt.figure(figsize=(16, 3)).add_subplot(111)
ax1.set_ylabel('PE Util', fontsize=14, fontweight='bold')
ax1.set_xlabel('Buffer Size (MB)', fontsize=14, fontweight='bold')
plt.setp(ax1.spines.values(), linewidth=2)
ax2 = ax1.twinx()
ax2.set_ylabel('Buf Util', fontsize=14, fontweight='bold')
p1 = ax1.bar([i - 0.3 for i in range(len(res['sa_avg']))], res['sa_avg'],\
0.3, yerr=res['sa_std'], align='center',color='#8154D1',\
edgecolor=['k']*len(res['sa_avg']), linewidth=1.5, hatch="/");
p2 = ax2.bar(range(len(res['buf_avg'])), res['buf_avg'], 0.3, yerr=res['buf_std'], align='center', \
color='#5b87f2', edgecolor=['k']*len(res['buf_avg']), linewidth=1.5, hatch="\\");
plt.subplots_adjust(left=0.1, bottom=0.20, right=0.9, top=0.9,
wspace=0.2, hspace=0.2)
ax2.set_ylim(0.0, 1.0)
ax1.set_ylim(0.0, 1.0)
# ax2.set_yscale('log')
plt.xticks(range(len(res['sa_avg'])), [base*scale*i for i in range(low, high, step)])
plt.legend((p1[0], p2[0]), ('SA util', 'Buf util'), \
bbox_to_anchor=(0.1, 1.01, 0.8, .101), loc=3, \
ncol=2, mode="expand", borderaxespad=0., frameon=False)
ax1.set_axisbelow(True)
plt.savefig("profile_buf.pdf");
def plot_buf_cycle(res, arr, scale):
plt.rc('font', size=10)
ax1 = plt.figure(figsize=(6, 2.5)).add_subplot(111)
ax1.set_ylabel('Norm. Speedup', fontsize=14, fontweight='bold')
ax1.set_xlabel('Buffer Size (MB)', fontsize=14, fontweight='bold')
plt.setp(ax1.spines.values(), linewidth=2)
ax2 = ax1.twinx()
# plt.grid(color='grey', which='major', axis='y', linestyle='--')
ax2.set_ylabel('Norm. Energy', fontsize=14, fontweight='bold')
p1 = ax1.bar([i - 0.3 for i in range(len(res['cycle_avg']))],\
[float(res['cycle_avg'][0])/float(i) for i in res['cycle_avg']],\
0.3, align='center',color='#71985E', edgecolor=['k']*len(res['sa_avg']), \
linewidth=1.5, hatch="/");
p2 = ax2.bar(range(len(res['traffic_avg'])), \
[float(i)/res['traffic_avg'][0] for i in res['traffic_avg']], 0.3, align='center', \
color='#FFBF56', edgecolor=['k']*len(res['buf_avg']), linewidth=1.5, hatch="\\");
plt.subplots_adjust(left=0.1, bottom=0.20, right=0.9, top=0.9,
wspace=0.2, hspace=0.2)
# ax1.set_yscale('log')
# ax2.set_yscale('log')
# ax1.set_ylim(pow(10, math.floor(math.log10(min(res['cycle_avg'])))), \
# pow(10, math.ceil(math.log10(max(res['cycle_avg'])))))
# ax2.set_ylim(pow(10, math.floor(math.log10(min(res['traffic_avg'])))), \
# pow(10, math.ceil(math.log10(max(res['traffic_avg'])))))
ax1.set_ylim(0.5, 1.5)
ax2.set_ylim(0, 1)
ax1.set_yticks([0.5, 0.7, 0.9, 1.1, 1.3, 1.5])
ax2.set_yticks([0.0, 0.2, 0.4, 0.6, 0.8, 1.0])
plt.xticks(range(len(res['cycle_avg'])), arr)
plt.legend((p1[0], p2[0]), ('speedup', 'energy'), \
bbox_to_anchor=(0.1, 1.01, 0.8, .101), loc=3, \
ncol=2, mode="expand", borderaxespad=0., frameon=False)
ax1.set_axisbelow(True)
plt.savefig("profile_buf_cycle.pdf");
def plot_bw_size(res, low, high):
plt.rc('font', size=10)
ax1 = plt.figure(figsize=(16, 3)).add_subplot(111)
ax1.set_ylabel('PE Util', fontsize=14, fontweight='bold')
ax1.set_xlabel('Memory Bandwidth (B/cycle)', fontsize=14, fontweight='bold')
plt.setp(ax1.spines.values(), linewidth=2)
ax2 = ax1.twinx()
ax2.set_ylabel('Buf Util', fontsize=14, fontweight='bold')
p1 = ax1.bar([i - 0.3 for i in range(len(res['sa_avg']))], res['sa_avg'],\
0.3, yerr=res['sa_std'], align='center',color='#8154D1',\
edgecolor=['k']*len(res['sa_avg']), linewidth=1.5, hatch="/");
p2 = ax2.bar(range(len(res['buf_avg'])), res['buf_avg'], 0.3, yerr=res['buf_std'], align='center', \
color='#5b87f2', edgecolor=['k']*len(res['buf_avg']), linewidth=1.5, hatch="\\");
plt.subplots_adjust(left=0.1, bottom=0.20, right=0.9, top=0.9,
wspace=0.2, hspace=0.2)
ax2.set_ylim(0.0, 1.0)
ax1.set_ylim(0.0, 1.0)
plt.xticks(range(len(res['sa_avg'])), [pow(2, i) for i in range(low, high)])
plt.legend((p1[0], p2[0]), ('SA util', 'Buf util'), \
bbox_to_anchor=(0., 1.01, 1., .101), loc=3, \
ncol=4, mode="expand", borderaxespad=0., frameon=False)
ax1.set_axisbelow(True)
plt.savefig("profile_bw.pdf");
def plot_bw_cycle(res, low, high):
plt.rc('font', size=10)
ax1 = plt.figure(figsize=(16, 3)).add_subplot(111)
ax1.set_ylabel('Total Cycle', fontsize=14, fontweight='bold')
ax1.set_xlabel('Memory Bandwidth (B/cycle)', fontsize=14, fontweight='bold')
plt.setp(ax1.spines.values(), linewidth=2)
ax2 = ax1.twinx()
ax2.set_ylabel('Total Traffic', fontsize=14, fontweight='bold')
p1 = ax1.bar([i - 0.3 for i in range(len(res['cycle_avg']))], res['cycle_avg'],\
0.3, align='center',color='#8154D1',\
edgecolor=['k']*len(res['cycle_avg']), linewidth=1.5, hatch="/");
p2 = ax2.bar(range(len(res['traffic_avg'])), res['traffic_avg'], 0.3, align='center', \
color='#5b87f2', edgecolor=['k']*len(res['traffic_avg']), linewidth=1.5, hatch="\\");
plt.subplots_adjust(left=0.1, bottom=0.20, right=0.9, top=0.9,
wspace=0.2, hspace=0.2)
ax1.set_yscale('log')
ax2.set_yscale('log')
ax1.set_ylim(pow(10, math.floor(math.log10(min(res['cycle_avg'])))), \
pow(10, math.ceil(math.log10(max(res['cycle_avg'])))))
ax2.set_ylim(pow(10, math.floor(math.log10(min(res['traffic_avg'])))), \
pow(10, math.ceil(math.log10(max(res['traffic_avg'])))))
plt.xticks(range(len(res['cycle_avg'])), [pow(2, i) for i in range(low, high)])
plt.legend((p1[0], p2[0]), ('cycle', 'traffic'), \
bbox_to_anchor=(0.1, 1.01, 0.9, .101), loc=3, \
ncol=4, mode="expand", borderaxespad=0., frameon=False)
ax1.set_axisbelow(True)
plt.savefig("profile_bw_cycle.pdf");