-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_gupta_stat.py
71 lines (56 loc) · 2.25 KB
/
gen_gupta_stat.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
import os, sys
benchs = {
"is": "large",
"bfs": "large",
"dither": "large",
"jacobi-1d": "large",
"malloc_1d_array": "micro",
"static_1d_array": "micro",
"global_1d_array": "micro",
"check_elimination": "micro",
"check_modification": "micro",
}
BUILD_CMD = """
cmake -DVERBOSE=TRUE -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_INSTALL_PREFIX=./install -DCMAKE_BUILD_TYPE=Debug -B build -S . -G Ninja
(cd build && ninja install)
"""
def build():
if os.system(BUILD_CMD) == 0:
print("Build successful")
else:
print("Build failed")
sys.exit(1)
BASELINE_SIZE_CSV = "stat_gupta_size.csv"
BASELINE_PERF_CSV = "stat_gupat_perf.csv"
FOLDER = "stat_gupta"
def compile_benchmarks(bench: str):
os.environ["DUMP_DST"] = os.path.join(os.getcwd(), f"{FOLDER}/{bench}.txt")
print("DUMP_DST = " + os.environ["DUMP_DST"])
# run the benchmark
os.system(f"(cd install && ./run_pass.sh {bench})")
BENCH_ORIGINAL_BC = f"install/benchmark/{benchs[bench]}_benchmark/{bench}.bc"
BENCH_TRANSFORMED_BC = f"install/{bench}-transformed.bc"
# compare file size
original_size = os.path.getsize(BENCH_ORIGINAL_BC)
transformed_size = os.path.getsize(BENCH_TRANSFORMED_BC)
print(f"Original size: {original_size} bytes")
print(f"Transformed size: {transformed_size} bytes")
print(f"Size percentage: {transformed_size/original_size*100:.2f}%")
with open(BASELINE_SIZE_CSV, "a") as f:
f.write(f"{bench},{original_size},{transformed_size}\n")
STUB_FILE = "stubs/BoundCheck.o"
def link_stub(bench: str):
os.system(f"clang++ {STUB_FILE} install/{bench}-transformed.bc -o install/{bench}-transformed.out")
os.system(f"clang++ install/benchmark/{benchs[bench]}_benchmark/{bench}.bc -o install/{bench}-original.out")
def run_bench(bench: str):
os.system(f"hyperfine -w 2 ./install/{bench}-original.out --export-csv {FOLDER}/{bench}-original.csv")
os.system(f"hyperfine -w 2 ./install/{bench}-transformed.out --export-csv {FOLDER}/{bench}-transformed.csv")
if not os.path.exists(f"{FOLDER}"):
os.mkdir(f"{FOLDER}")
else:
os.system(f"rm -rf {FOLDER}/*")
build()
for bench in benchs:
compile_benchmarks(bench)
link_stub(bench)
run_bench(bench)