-
Notifications
You must be signed in to change notification settings - Fork 11
/
process_log.py
348 lines (252 loc) · 12.7 KB
/
process_log.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
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import json
import argparse
import sys
def parse_commandline():
arg_parser = argparse.ArgumentParser( description = 'generate plots from the log output' )
arg_parser.add_argument( '-logfile', nargs = '?', default='make_log.txt', help = 'log file' )
arg_parser.add_argument( '-specfile', nargs = '?', default='plot_spec.json', help = 'plot specification file' )
arg_parser.add_argument( '-plot_charts', action = "store_true", help = 'generates plots per spec' )
arg_parser.add_argument( '-base_dir', default='doc/', help = 'output directory where the PNG files are saved' )
arg_parser.add_argument( '-show_impl', action = "store_true", help = 'shows all the implementation types' )
return arg_parser
def get_unique_values_for_column(df, col):
L = []
for v in df[col].unique():
L.append(v)
return L
def get_implementation_combinations(df):
implementation_types = get_unique_values_for_column( df, 'implementation type' )
loop_unrolling_factors = get_unique_values_for_column( df, 'loop unrolling factor')
num_cpu_threads = get_unique_values_for_column( df, 'num CPU threads' )
L = []
for t in implementation_types:
if t == 'METAL':
metal_implementations = get_unique_values_for_column( df, 'metal implementation type' )
metal_implementations.remove('NOT_APPLICABLE')
for mi in metal_implementations:
df_filtered = df[ (df['implementation type'] == t ) & (df['metal implementation type'] == mi) ]
if df_filtered.shape[0] > 0:
L.append( t + " " + mi + " 0 0" )
else:
for f in loop_unrolling_factors:
for n in num_cpu_threads:
df_filtered = df[ (df['implementation type'] == t ) & (df['loop unrolling factor'] == f) & (df['num CPU threads'] == n) ]
if df_filtered.shape[0] > 0:
L.append( t + " " + str(f) + " " + str(n) )
return L
def get_best_times_for_impl( vector_length, mean_times ):
new_lenghts = []
new_times = []
prev_best = 1.0e+20
prev_length = 0
for i in range( 0, len(vector_length) ):
v = vector_length[i]
t = mean_times [i]
if prev_length == v:
if prev_best > t:
prev_best = t
else:
if prev_length != 0:
new_lenghts.append( prev_length )
new_times.append ( prev_best )
prev_length = v
prev_best = t
new_lenghts.append( prev_length )
new_times.append ( prev_best )
return new_lenghts, new_times
def get_mean_times( df, et, est, comb ):
f = comb.split(' ')
if f[0] == 'METAL':
df_row_filtered = df[ (df['data element type'] == et ) & (df['data element subtype'] == est ) & (df['implementation type'] == f[0] ) & (df['metal implementation type'] == f[1] ) ]
else:
df_row_filtered = df[ (df['data element type'] == et ) & (df['data element subtype'] == est ) & (df['implementation type'] == f[0] ) & (df['loop unrolling factor'] == int(f[1]) ) & (df['num CPU threads'] == int(f[2]) ) ]
if est == 'VECTOR' or est == 'STRUCTURE_OF_ARRAYS' or est == 'ARRAY_OF_STRUCTURES':
vector_lengths = [ int(r['vector length/matrix row']) for i, r in df_row_filtered.iterrows() ]
elif est == 'MATRIX_COL_MAJOR' or est == 'MATRIX_ROW_MAJOR':
vector_rows = [ int(r['vector length/matrix row']) for i, r in df_row_filtered.iterrows() ]
vector_cols = [ int(r['matrix columns']) for i, r in df_row_filtered.iterrows() ]
vector_lengths = []
for i, r in enumerate(vector_rows):
c = vector_cols[i]
vector_lengths.append(r*c)
elif est == 'MATRIX_SPARSE':
vector_lengths = [ int(r['number of non zeros']) for i, r in df_row_filtered.iterrows() ]
elif est == 'RANDOM_DIAGONALLY_DOMINANT_SYMMETRIC' or est == 'RANDOM_DIAGONALLY_DOMINANT_SKEWSYMMETRIC' or est == 'REAL_NONSYMMETRIC_MU02' or est == 'REAL_NONSYMMETRIC_MU08' or est == 'REAL_SYMMETRIC':
vector_rows = [ int(r['vector length/matrix row']) for i, r in df_row_filtered.iterrows() ]
vector_cols = [ int(r['matrix columns']) for i, r in df_row_filtered.iterrows() ]
vector_lengths = []
for i, r in enumerate(vector_rows):
c = vector_cols[i]
vector_lengths.append(r*c)
mean_times = [ float(r['mean time milliseconds']) for i, r in df_row_filtered.iterrows() ]
return get_best_times_for_impl( vector_lengths, mean_times )
def get_x_label(est):
if est == 'VECTOR' or est == 'STRUCTURE_OF_ARRAYS' or est == 'ARRAY_OF_STRUCTURES':
return '|Vec|'
elif est == 'MATRIX_COL_MAJOR' or est == 'MATRIX_ROW_MAJOR':
return '|Mat|'
elif est == 'RANDOM_DIAGONALLY_DOMINANT_SYMMETRIC' or est == 'RANDOM_DIAGONALLY_DOMINANT_SKEWSYMMETRIC' or est == 'REAL_NONSYMMETRIC_MU02' or est == 'REAL_NONSYMMETRIC_MU08' or est == 'REAL_SYMMETRIC':
return '|Mat|'
elif est == 'MATRIX_SPARSE':
return 'NNZ'
def plot_log_log( element_type, element_subtype, width, height, title, lengths, times, labels, base_dir ):
fig = plt.figure( figsize = (width, height) )
ax1 = fig.add_subplot(111)
ax1.set_yscale('log')
ax1.set_xscale('log', base=10)
ax1.set_title(title)
plt.xlabel( get_x_label(element_subtype) )
plt.ylabel("[ms]")
for i, length in enumerate(lengths):
my_time = times[i]
label = labels[i]
ax1.plot( length, my_time, label=label, marker='o' )
ax_handles, ax_labels = ax1.get_legend_handles_labels()
lgd = ax1.legend(ax_handles, ax_labels)
ax1.grid('on')
plt.savefig(base_dir + element_type + '_' + element_subtype + '_' + title.replace(' ','_').replace('+', 'P') + '.png')
plt.clf()
def plot_log_lin_relative( element_type, element_subtype, width, height, title, lengths, times, labels, base_label, upper_limit, base_dir ):
fig = plt.figure( figsize = (width, height) )
ax1 = fig.add_subplot(111)
ax1.set_yscale('linear')
ax1.set_ylim(0, upper_limit)
ax1.set_xscale('log', base=10)
ax1.set_title(title)
plt.xlabel( get_x_label(element_subtype) )
plt.ylabel("ratio")
for i, length in enumerate(lengths):
my_time = times[i]
label = labels[i]
if label == base_label:
label = label + "*"
ax1.plot( length, my_time, label=label, marker='o' )
ax_handles, ax_labels = ax1.get_legend_handles_labels()
lgd = ax1.legend(ax_handles, ax_labels)
ax1.grid('on')
plt.savefig(base_dir + element_type + '_' + element_subtype + '_' + title.replace(' ', '_') + '_relative.png')
plt.clf()
def plot_lin_lin( element_type, element_subtype, width, height, title, lengths, times, labels, base_dir ):
fig = plt.figure( figsize = (width, height) )
ax1 = fig.add_subplot(111)
ax1.set_yscale('linear')
ax1.set_xscale('linear')
ax1.set_title(title)
plt.xlabel( get_x_label(element_subtype) )
plt.ylabel("[ms]")
for i, length in enumerate(lengths):
my_time = times[i]
label = labels[i]
ax1.plot( length, my_time, label=label, marker='o' )
ax_handles, ax_labels = ax1.get_legend_handles_labels()
lgd = ax1.legend(ax_handles, ax_labels)
ax1.grid('on')
plt.savefig(base_dir + element_type + '_' + element_subtype + '_' + title.replace(' ','_').replace('+', 'P') + '.png')
plt.clf()
def show_implementations(df):
data_element_types = get_unique_values_for_column( df, 'data element type' )
data_element_subtypes = get_unique_values_for_column( df, 'data element subtype' )
for et in data_element_types:
for est in data_element_subtypes:
print ('')
print ( 'Element Type: [' + et + '] Subtype: [' + est + ']' )
df_per_data_type = df[ (df['data element type'] == et ) & (df['data element subtype'] == est ) ]
vector_lengths = get_unique_values_for_column( df_per_data_type, 'vector length/matrix row' )
print ('Vector Lengths: ' + str(vector_lengths))
cols = get_unique_values_for_column( df_per_data_type, 'matrix columns' )
print ('Cols: ' + str(cols))
nnz = get_unique_values_for_column( df_per_data_type, 'number of non zeros' )
print ('Number of Nonzeros: ' + str(nnz))
implementation_types = get_unique_values_for_column( df_per_data_type, 'implementation type' )
num_cpu_threads = get_unique_values_for_column( df_per_data_type, 'num CPU threads' )
loop_unrolling_factors = get_unique_values_for_column( df_per_data_type, 'loop unrolling factor' )
implementation_combinations = get_implementation_combinations( df_per_data_type )
out_str = ""
for i, ic in enumerate(implementation_combinations):
if i > 0:
out_str += ", "
out_str += "\""
out_str += ic
out_str += "\""
print ('Implementation Combinarions: ' + out_str )
def plot_charts( df, js, base_dir ):
for plot_data in js:
width = int( plot_data[ 'Width' ] )
height = int( plot_data[ 'Height' ] )
title = plot_data[ 'Title' ]
list_lengths = []
list_times = []
list_labels = []
det = plot_data[ 'DataElementType' ]
des = plot_data[ 'DataElementSubtype' ]
pt = plot_data[ 'PlotType' ]
ul = float(plot_data[ 'UpperLimit' ])
base_mapping = {}
if des != 'ANY':
if pt == 'LOG-LIN-RELATIVE':
pb = plot_data[ 'PlotBase' ]
base_lengths, base_times = get_mean_times( df, det, des, pb )
for i in range(len(base_lengths)):
base_mapping[ base_lengths[i] ] = base_times[i]
pcs = plot_data[ 'PlotCases' ]
for pc in pcs:
lengths, times = get_mean_times( df, det, des, pc )
if pt == 'LOG-LIN-RELATIVE':
if len( base_times ) < len( times ):
print ('Number of elements does not match to the base. ckp1')
exit(1)
relative_times = []
for i, t in enumerate( times ):
L = lengths[i]
b = base_mapping[L]
relative_times.append( t / b )
list_times.append( relative_times )
else:
list_times.append( times )
list_lengths.append( lengths )
list_labels.append( pc )
else:
if pt == 'LOG-LIN-RELATIVE':
des, pb = plot_data[ 'PlotBase' ].split(':')
base_lengths, base_times = get_mean_times( df, det, des, pb )
for i in range(len(base_lengths)):
base_mapping[ base_lengths[i] ] = base_times[i]
pcs_des = plot_data[ 'PlotCases' ]
for pd in pcs_des:
des2, pc = pd.split(':')
lengths, times = get_mean_times( df, det, des2, pc )
if pt == 'LOG-LIN-RELATIVE':
if len( base_times ) < len( times ):
print ('Number of elements does not match to the base. ckp2')
exit(1)
relative_times = []
for i, t in enumerate( times ):
L = lengths[i]
b = base_mapping[L]
relative_times.append( t / b )
list_times.append( relative_times )
else:
list_times.append( times )
list_lengths.append( lengths )
list_labels.append( pd )
if pt == 'LOG-LIN-RELATIVE':
plot_log_lin_relative( det, des, width, height, title, list_lengths, list_times, list_labels, pb, ul, base_dir )
elif pt == 'LOG-LOG':
plot_log_log( det, des, width, height, title, list_lengths, list_times, list_labels, base_dir )
elif pt == 'LIN-LIN':
plot_lin_lin( det, des, width, height, title, list_lengths, list_times, list_labels, base_dir )
def main():
comm_parser = parse_commandline()
comm_args = comm_parser.parse_args()
df = pd.read_csv( comm_args.logfile, sep = "\t" )
if comm_args.show_impl:
show_implementations(df)
if comm_args.plot_charts:
with open(comm_args.specfile, 'r') as jf:
js = json.load(jf)
plot_charts(df, js, comm_args.base_dir + '/' )
if __name__ == "__main__":
main()