-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbench.py
More file actions
70 lines (61 loc) · 2.4 KB
/
bench.py
File metadata and controls
70 lines (61 loc) · 2.4 KB
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
import argparse
import numpy as np
import json
from class_project import Project
if __name__ == "__main__":
# Retrieve the name of the project
parser = argparse.ArgumentParser()
parser.add_argument("--project", "-p", required=True)
parser.add_argument("--message", "-m", default="")
parser.add_argument("--arguments", "-a", default="")
parser.add_argument("--test-runs", "-t", type=int, default=1)
parser.add_argument("--skip-bench", "-sb", action="store_true")
args = parser.parse_args()
project = Project(str(args.project))
message = str(args.message)
arguments = str(args.arguments)
test_runs = args.test_runs
skip_bench = bool(args.skip_bench)
# Compile and run test
max_deltas = [] if test_runs > 0 else [-1]
sum_deltas = [] if test_runs > 0 else [-1]
for i in range(test_runs):
# Run the test (after compiling if this is the first time)
if i == 0:
test_output = project.compile_and_run("test.cu", arguments)
else:
test_output = project.run("test.cu", arguments)
test_output = test_output.replace("nan", "\"nan\"")
# Parse the output if t is not 0
try:
parsed = json.loads(test_output)
max_deltas.append(float(parsed["max_delta"]))
sum_deltas.append(float(parsed["total_delta"]))
except:
print(test_output.replace("\\n", "\n"))
raise Exception("Failed to parse the output")
# Compile and run benchmark
if skip_bench:
times = ["End of warmup", 0]
else:
time_string = project.compile_and_run("bench.cu", arguments)
times = time_string[2:-3].split(", ")[3:]
# Retrieve benchmarked times
bench_ts, t = [], times.pop()
while t != "End of warmup":
bench_ts.append(float(t))
t = times.pop()
warmup_ts = list(map(float, times))
# Process them
data = {
"mean": float(np.mean(bench_ts)),
"std": float(np.std(bench_ts)),
"median": float(np.median(bench_ts)),
"message": message,
"max_deltas": f"{max(max_deltas):.4f} <- [" + ", ".join(map(lambda x: f"{x:.4f}", max_deltas)) + "]",
"sum_deltas": f"{max(sum_deltas):.4f} <- [" + ", ".join(map(lambda x: f"{x:.4f}", sum_deltas)) + "]",
}
print(json.dumps(data, indent=4))
# Backup the project
hash_ = project.backup()
project.record(hash_, arguments, data)