-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_performance_alt.py
143 lines (121 loc) · 4.19 KB
/
plot_performance_alt.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
from os import path
import argparse
from typing import Type
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from math import log2
AMD = r" $\bf{AMD\ Ryzen\ 7\ 4800H\ (Zen\ 2),\ 2.9GHz}$"
INTEL = r" $\bf{Intel\ i5-7300U\ (Kaby\ Lake),\ 2.6GHz}$"
def format_func(value, tick_number):
# find exponent for tick
return r"$2^{{ {:} }}$".format(int(log2(value)))
def read_dataset(path, system="intel"):
data = np.loadtxt(open(path, "rb"), delimiter=",", skiprows=1)
if system == "intel":
return data[:, 0], data[:, 1], data[:, 6], data[:, 2], data[:, 3], data[:, 10]
else:
return data[:, 0], data[:, 1], data[:, 6], data[:, 2], data[:, 3], data[:, 11]
def main(args):
datadir = path.relpath(args.data_path)
if not path.exists(datadir):
raise Exception("directory {} does not exist".format(datadir))
sns.set_theme()
fig = plt.figure()
ax = fig.add_subplot(111)
system_name = INTEL if args.system == "intel" else AMD
title = (
r"$\bf{Performance\ on}$" if args.metric == "fp/c" else r"$\bf{Runtime\ on}$"
)
title += system_name
if args.metric == "fp/c":
title += "\n [flops/cycle]"
elif args.metric == "time":
title += "\n [seconds]"
elif args.metric == "cycles":
title += "\n [" + r"$\times 10^9$" + " cycles]"
ax.set_title(title, loc="left")
mpts_mode = False
freq = 2.6e9 if args.system == "intel" else 2.9e9
for file in args.files[0]:
fpath = path.join(datadir, file)
N, D, flops, cycles, time, mpts = read_dataset(fpath, args.system)
# hack hack hack
mpts_mode = all(elem == N[0] for elem in N) and all(elem == D[0] for elem in D)
dim_mode = not mpts_mode and all(elem == N[0] for elem in N)
# flops *= 1e-9
if args.metric == "fp/c":
y = np.divide(flops, cycles)
elif args.metric == "time":
y = cycles / freq
elif args.metric == "cycles":
y = cycles / 1e9
else:
raise TypeError("unsupported metric to plot")
if not mpts_mode and not dim_mode:
N = N[2:]
y = y[2:]
X_axis = []
if mpts_mode:
X_axis = mpts
elif dim_mode:
X_axis = D
else:
X_axis = N
if args.x_scale == "linear":
(line,) = ax.plot(X_axis, y, linestyle="-", marker="o")
ax.xaxis.set_major_locator(plt.MultipleLocator(2048))
# ax.xaxis.set_major_locator(plt.LogLocator(base=2, subs=[16]))
# ax.xaxis.set_major_formatter(plt.FuncFormatter(format_func))
# ax.set_xlim(right=17000)
elif args.x_scale == "log":
(line,) = ax.semilogx(X_axis, y, linestyle="-", marker="o", base=2)
else:
raise TypeError("unsupported scale for x-axis")
line.set_label(path.splitext(file)[0])
ax.set_xlabel("k" if mpts_mode else ("d" if dim_mode else "n"))
# ax.set_ylabel('flops/cycle')
ax.legend(loc="center left", bbox_to_anchor=(1, 0.5))
if args.save_path is None:
plt.show()
else:
fig.savefig(args.save_path, bbox_inches="tight")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--system", type=str, default="intel", choices=["intel", "amd"])
parser.add_argument(
"--data-path",
type=str,
default="data/timings/",
help="relative path to where timings are stored",
)
parser.add_argument(
"--files",
type=str,
nargs="+",
required=True,
action="append",
help="name of one or more .csv performance measurements",
)
parser.add_argument(
"--save-path",
type=str,
default=None,
help="path or filename to store plot to",
)
parser.add_argument(
"--metric",
type=str,
default="fp/c",
help="which metric to plot on y axis",
choices=["fp/c", "cycles", "time"],
)
parser.add_argument(
"--x-scale",
type=str,
default="log",
help="scaling of x-axis",
choices=["log", "linear"],
)
args = parser.parse_args()
main(args)