forked from SparseRooflineBenchmark/SparseRooflineBenchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.py
170 lines (137 loc) · 4.75 KB
/
graph.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
import json
import os
from collections import defaultdict
import matplotlib.pyplot as plt
RESULT_JULIA_DIRECTORY = "result_julia"
NTHREADS = [i + 1 for i in range(12)]
DEFAULT_METHOD = "serial_default_implementation"
METHODS = [
DEFAULT_METHOD,
"intrinsics_atomic_add",
"atomix_atomic_add",
]
DATA_CLASS = {
"1024-0.1": "uniform",
"8192-0.1": "uniform",
"1048576-3000000": "uniform",
"FEMLAB-poisson3Da": "FEMLAB",
"FEMLAB-poisson3Db": "FEMLAB",
}
COLORS_JULIA = ["gray", "cadetblue", "saddlebrown"]
MEASUREMENTS_JSON = "measurements.json"
RESULT_DIRECTORY = "result"
GRAPH_DIRECTORY = "graph"
RUNTIME_DIRECTORY = "runtime"
SPEEDUP_DIRECTORY = "speedup"
COLORS_CPP = ["navy", "black", "orange"]
def load_json():
combine_results = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: {})))
for n_thread in NTHREADS:
results_json = json.load(
open(f"{RESULT_JULIA_DIRECTORY}/spmv_{n_thread}_threads.json", "r")
)
for result in results_json:
matrix = (
result["matrix"].replace("/", "-")
if result["dataset"] != "uniform"
else f"{result['matrix']['size']}-{result['matrix']['sparsity']}"
)
combine_results[result["dataset"]][matrix][result["method"]][
result["n_threads"]
] = result["time"]
return combine_results
def find_measurements(result_directory):
found_files = []
for root, _, files in os.walk(result_directory):
if MEASUREMENTS_JSON in files:
found_files.append(os.path.join(root, MEASUREMENTS_JSON))
return found_files
def plot_runtime(result, result_julia, dataset):
dataset_index = dataset.replace("/", "-")
plt.figure(figsize=(10, 6))
for (method, method_result), color in zip(result.items(), COLORS_CPP):
plt.plot(
range(1, len(method_result) + 1),
[method_result[str(thread)] for thread in range(1, len(method_result) + 1)],
label=f"CPP: {method}",
color=color,
marker="o",
linestyle="-",
linewidth=1,
)
for method, color in zip(METHODS, COLORS_JULIA):
plt.plot(
NTHREADS,
[
1e9
* result_julia[DATA_CLASS[dataset_index]][dataset_index][method][
n_thread
]
for n_thread in NTHREADS
],
label=f"Julia: {method}",
color=color,
marker="o",
linestyle="-",
linewidth=1,
)
plt.title(f"SpMV - Runtime for {dataset}")
plt.legend()
plt.xlabel("Number of Threads")
plt.ylabel(f"Runtime (in nanoseconds)")
plt.savefig(
os.path.join(GRAPH_DIRECTORY, RUNTIME_DIRECTORY, f"{dataset_index}.png")
)
def plot_speedup(result, result_julia, dataset):
dataset_index = dataset.replace("/", "-")
plt.figure(figsize=(10, 6))
for (method, method_result), color in zip(result.items(), COLORS_CPP):
plt.plot(
range(1, len(method_result) + 1),
[
result[DEFAULT_METHOD][str(thread)] / method_result[str(thread)]
for thread in range(1, len(method_result) + 1)
],
label=f"CPP: {method}",
color=color,
marker="o",
linestyle="-",
linewidth=1,
)
for method, color in zip(METHODS, COLORS_JULIA):
plt.plot(
NTHREADS,
[
result_julia[DATA_CLASS[dataset_index]][dataset_index][DEFAULT_METHOD][
n_thread
]
/ result_julia[DATA_CLASS[dataset_index]][dataset_index][method][
n_thread
]
for n_thread in NTHREADS
],
label=f"Julia: {method}",
color=color,
marker="o",
linestyle="-",
linewidth=1,
)
plt.title(f"SpMV - Speedup for {dataset} (with respect to {DEFAULT_METHOD})")
plt.legend()
plt.xlabel("Number of Threads")
plt.ylabel(f"Speedup")
plt.savefig(
os.path.join(GRAPH_DIRECTORY, SPEEDUP_DIRECTORY, f"{dataset_index}.png")
)
def plot_result(result, result_julia, dataset):
plot_runtime(result, result_julia, dataset)
plot_speedup(result, result_julia, dataset)
if __name__ == "__main__":
measurement_files = find_measurements(RESULT_DIRECTORY)
result_julia = load_json()
for measurement_file in measurement_files:
dataset = os.path.join(
*os.path.normpath(measurement_file).split(os.path.sep)[1:-1]
)
result = json.load(open(measurement_file, "r"))
plot_result(result, result_julia, dataset)