-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis_gesv.py
137 lines (114 loc) · 4.23 KB
/
analysis_gesv.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
import argparse
import matplotlib.pyplot as plt
import json
import pathlib
import numpy as np
import re
import copy
from distutils.util import strtobool
def str2num(datum):
""" Convert string to integer or float"""
try:
return int(datum)
except:
try:
return float(datum)
except:
try:
return strtobool(datum)
except:
return datum
def get_details(str_in_bench):
matches = re.findall(r'<(.*?)>', str_in_bench)[0].split(',')
precision, layout, param = matches
layout = layout.split('::')[-1]
param = param.replace(" ", "")
#params = param.split('_')[-3:]
#_param = [param_dict[key][param] for key, param in zip(param_keys, params)]
return precision, layout, param_dict[param]
def parse():
parser = argparse.ArgumentParser(add_help=True)
parser.add_argument('-dirname', \
action='store', \
nargs='?', \
const=None, \
default='./', \
type=str, \
choices=None, \
help='directory of inputfile', \
metavar=None
)
parser.add_argument('--filename', \
action='store', \
nargs='?', \
const=None, \
default='gesv_gpu_bench.json', \
type=str, \
choices=None, \
help='input file name', \
metavar=None
)
return parser.parse_args()
if __name__ == '__main__':
args = parse()
# Read json file
filename = pathlib.Path(args.dirname) / args.filename
with open(filename, 'r') as f:
data = json.load(f);
benchmarks = data.get('benchmarks')
# Reconfigure a dict
param_dict = {'param_s': "Static",
'param_d2': "Dynamic",
}
param_keys = ['uplo', 'trans', 'diag']
keys = ['real_time', 'GB/s']
layouts = ['LayoutLeft', 'LayoutRight']
results = {}
for bench in benchmarks:
print(bench)
full_name = bench.get('name')
list_of_names = full_name.split('/')
name, N, batch, _ = list_of_names
def get_number(str_in_bench):
str = str_in_bench.split(':')[-1]
return str2num(str)
N = get_number(N)
batch = get_number(batch)
precision, layout, pivoting = get_details(name)
print(precision, layout, pivoting)
result = {key: bench.get(key) for key in keys}
result['precision'] = precision
result['layout'] = layout
result['pivoting'] = pivoting
result['N'] = N
result['batch'] = batch
result['tag'] = name
print(result)
results[full_name] = result
def to_list(key):
_list = [result_dict[key] for result_dict in results.values()]
_list = set(_list) # remove overlap
_list = sorted(list(_list)) # To ascending order
return _list
tags = to_list('tag')
mat_sizes = to_list('N')
#for tag in tags:
# precision, layout, pivoting = get_details(tag)
# print(tag)
# Plot
for mat_size in mat_sizes:
fig, ax = plt.subplots(figsize=(8, 8))
for key in param_dict.keys():
time = [result_dict['real_time'] for result_dict in results.values()
if ((key in result_dict['tag']) and ("Left" in result_dict['tag'])) and result_dict['N'] == mat_size]
batch = [result_dict['batch'] for result_dict in results.values()
if ((key in result_dict['tag']) and ("Left" in result_dict['tag'])) and result_dict['N'] == mat_size]
ax.plot(batch, np.asarray(time) * 1.0e-6, marker='*', markersize=10, label=param_dict[key])
#ax.set_ylim([0, max_bandwidth])
ax.set_xscale('log')
ax.set_xlabel('Batch size')
ax.set_ylabel('time [s]')
ax.legend()
ax.grid()
fig.savefig(f'N_{mat_size}.png')
plt.close('all')