forked from IntelPython/dpbench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_graphs.py
179 lines (143 loc) · 5.14 KB
/
plot_graphs.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
import os
import sys
import run_utils as util
import options
try:
import pandas as pd
except:
print("Pandas not available\n")
def get_runtime_data(app_name, cmds, platform):
util.chdir(platform)
try:
df = pd.read_csv(
"runtimes.csv",
names=["input_size", "runtime"],
index_col="input_size",
)
return df.loc[cmds["ref_input"], "runtime"]
except:
print("Runtimes not available for " + app_name + "\n")
return 0
def get_runtimes(opts, all_plot_data, impl):
util.chdir(impl)
numba_dir = os.getcwd()
for app, cmds in opts.wls.wl_list.items():
if cmds["execute"] is True:
plot_data_entry = {}
if app in all_plot_data:
plot_data_entry = all_plot_data[app]
util.chdir(app)
app_dir = os.getcwd()
if (
opts.platform == options.platform.cpu
or opts.platform == options.platform.all
):
cpu_perf = get_runtime_data(app, cmds, "CPU")
if cpu_perf is not 0:
plot_data_entry[impl + "_cpu"] = cpu_perf
util.chdir(app_dir)
if (
opts.platform == options.platform.gpu
or opts.platform == options.platform.all
):
gpu_perf = get_runtime_data(app, cmds, "GPU")
if gpu_perf is not 0:
plot_data_entry[impl + "_gpu"] = gpu_perf
util.chdir(numba_dir)
all_plot_data[app] = plot_data_entry
def check_envvars_tools(opts):
if (
opts.analysis is not options.analysis.all
and opts.analysis is not options.analysis.perf
):
print(
"Plotting can be run only with option --analysis(-a) set to all or perf. Exiting"
)
sys.exit()
try:
import pandas
except:
print("Pandas not available. Plotting disabled\n")
sys.exit()
def plot_efficiency_graph(all_plot_data):
df = pd.DataFrame.from_dict(all_plot_data, orient="index")
plot = False
try:
df["CPU"] = (df["numba_cpu"] / df["native_cpu"]) * 100.00
plot = True
df.drop(columns=["native_cpu", "numba_cpu"], inplace=True)
except:
print("CPU Efficiency data not available\n")
try:
df["GPU"] = (df["numba_gpu"] / df["native_gpu"]) * 100.00
plot = True
df.drop(columns=["native_gpu", "numba_gpu"], inplace=True)
except:
print("GPU Efficiency data not available\n")
if plot:
# df.drop(columns=['native_cpu', 'native_gpu', 'numba_cpu', 'numba_gpu'], inplace=True)
bar_chart = df.plot.bar(rot=45, fontsize=10)
# bar_chart.legend(loc='upper right')
bar_chart.set_ylabel("Efficiency in percentage", fontsize=10)
bar_chart.set_xlabel("Benchmark", fontsize=10)
bar_chart.set_title(
"Efficiency of Numba execution relative to OpenMP execution on CPU and GPU",
fontsize=10,
)
fig = bar_chart.get_figure()
fig_filename = "Efficiency_graph.pdf"
fig.savefig(fig_filename, bbox_inches="tight")
else:
print(
"Insufficient data to generate Efficiency graph. Verify execution times in runtimes.csv\n"
)
def plot_speedup_graph(all_plot_data):
df = pd.DataFrame.from_dict(all_plot_data, orient="index")
plot = False
try:
df["OpenMP"] = (df["native_cpu"] / df["native_gpu"]) * 100.00
plot = True
df.drop(columns=["native_cpu", "native_gpu"], inplace=True)
except:
print("CPU Speedup data not available\n")
try:
df["Numba"] = (df["numba_cpu"] / df["numba_gpu"]) * 100.00
plot = True
df.drop(columns=["numba_cpu", "numba_gpu"], inplace=True)
except:
print("GPU Speedup data not available\n")
if plot:
# df.drop(columns=['native_cpu', 'native_gpu', 'numba_cpu', 'numba_gpu'], inplace=True)
bar_chart = df.plot.bar(rot=45, fontsize=10)
# bar_chart.legend(loc='upper right')
bar_chart.set_ylabel("Speedup in percentage", fontsize=10)
bar_chart.set_xlabel("Benchmark", fontsize=10)
bar_chart.set_title(
"Speedup of GPU execution over CPU execution for Numba and OpenMP",
fontsize=10,
)
fig = bar_chart.get_figure()
fig_filename = "Speedup_graph.pdf"
fig.savefig(fig_filename, bbox_inches="tight")
else:
print(
"Insufficient data to generate Speedup graph. Verify execution times in runtimes.csv\n"
)
def run(opts):
check_envvars_tools(opts)
ref_cwd = os.getcwd()
all_plot_data = {}
if (
opts.impl == options.implementation.native
or opts.impl == options.implementation.all
):
get_runtimes(opts, all_plot_data, "native")
util.chdir(ref_cwd)
if (
opts.impl == options.implementation.numba
or opts.impl == options.implementation.all
):
get_runtimes(opts, all_plot_data, "numba")
util.chdir(ref_cwd)
plot_efficiency_graph(all_plot_data)
plot_speedup_graph(all_plot_data)