-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfigure10a_plot.py
87 lines (71 loc) · 2.63 KB
/
figure10a_plot.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
import numpy as np
import matplotlib.pyplot as plt
import os
bar_width = 0.20
fig = plt.subplots(figsize = (20, 12))
benchmarks = ["KVS", "HM", "SRAD", "Red", "MQ", "Scan"]
models = ["sbrp_near_L1_125", "sbrp_near_L1_25", "sbrp_near_L1_50", "sbrp_near"]
baseline = "epoch_near"
figure10_a_speedup = []
path = "../figure10_a_results/"
os.chdir(path)
graph_path = "../outputs/figure10_a_graph.pdf"
output_file_path = "../outputs/figure10_a_output.txt"
baseline_latency = {}
# Get baseline latency for all benchmarks
output_file = open(output_file_path, "w")
for benchmark in benchmarks:
file_name = "epoch_near_" + benchmark + ".out"
file_read = open(file_name, "r")
lines = file_read.readlines()
for line in reversed(lines):
if "gpu_tot_sim_cycle" in line:
baseline_latency[benchmark] = line.split(" ")[-1]
break
file_read.close()
# Get speedup for each model and each benchmark
for model in models:
speedup_list = []
speedup_list_str = []
for benchmark in benchmarks:
file_name = model + "_" + benchmark + ".out"
file_read = open(file_name, "r")
lines = file_read.readlines()
for line in reversed(lines):
if "gpu_tot_sim_cycle" in line:
latency = line.split(" ")[-1]
speedup = float(baseline_latency[benchmark])/float(latency)
print(f"model: " + model + " baseline latency: " + baseline_latency[benchmark] + " model_latency: " + latency + " speedup: " + str(speedup))
speedup_list.append(speedup)
break
figure10_a_speedup.append(speedup_list)
file_read.close()
print(speedup_list)
# Write to output file
output_file.write(" , ")
for benchmark in benchmarks:
output_file.write(benchmark + ", ")
output_file.write("\n")
for speedup in figure10_a_speedup:
output_file.write(models[figure10_a_speedup.index(speedup)] + ", ")
for i in speedup:
output_file.write(str(i) + ", ")
output_file.write("\n")
output_file.close()
print(figure10_a_speedup)
# Bar for each model
br = []
br.append(np.arange(len(benchmarks)))
for i in range(1, len(models)):
br.append([x + bar_width for x in br[i-1]])
colors = ['r', 'g', 'b', 'c', 'm']
for i in range(len(models)):
print(br[i])
print(i)
plt.bar(br[i], figure10_a_speedup[i], color = colors[i], width = bar_width, edgecolor = 'black', label = models[i])
plt.ylabel('Normalized run time', fontweight = 'bold', fontsize = 15)
plt.xticks([r + 2 * bar_width for r in range(len(benchmarks))],
['gpKVS', 'HM', 'SRAD', 'Red', 'MQ', 'Scan'])
plt.legend()
plt.savefig(graph_path, format='pdf')
plt.show()