Skip to content

Commit a6cf03a

Browse files
committed
add minimal python automation
1 parent 42656d2 commit a6cf03a

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

automation/run_benchmarks.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import subprocess
2+
import csv
3+
import os
4+
import sys
5+
from pathlib import Path
6+
7+
# Define path to the benchmark executable
8+
SCRIPT_DIR = Path(__file__).parent.parent
9+
BENCHMARK_EXECUTABLE = SCRIPT_DIR / "build" / "benchmark.exe"
10+
SCRIPT_DIR = Path(__file__).parent.parent
11+
SAVE_DIR = SCRIPT_DIR / "automation" / "benchmark_results.csv"
12+
13+
14+
15+
def run_benchmark(device, N):
16+
if not BENCHMARK_EXECUTABLE.exists():
17+
print(f"Benchmark executable not found at {BENCHMARK_EXECUTABLE}")
18+
return None
19+
try:
20+
result = subprocess.run([str(BENCHMARK_EXECUTABLE), str(device), str(N)], text=True, capture_output=True)
21+
22+
if result.returncode != 0:
23+
print(f"Error running benchmark for device {device} with N={N}: {result.stderr}")
24+
return None
25+
if "Correct: yes" not in result.stdout:
26+
print("Validation failed")
27+
return None
28+
for line in result.stdout.splitlines():
29+
if line.startswith("Time:"):
30+
return float(line.split()[1])
31+
32+
except Exception as e:
33+
print(f"Exception occurred while running benchmark for device {device} with N={N}: {e}")
34+
return None
35+
36+
def main():
37+
devices = [0, 1] # List of device IDs to benchmark
38+
N_values = [1 << 22, 1 << 24, 1 << 26] # Different sizes for the benchmark
39+
40+
results = []
41+
for N in N_values:
42+
for device in devices:
43+
print(f"Running benchmark for device {device} with N={N}...")
44+
output = run_benchmark(device, N)
45+
if output:
46+
results.append((device, N, output))
47+
print(f"Result: {output}")
48+
49+
# Save results to CSV
50+
with open(SAVE_DIR, "w", newline='') as csvfile:
51+
csvwriter = csv.writer(csvfile)
52+
csvwriter.writerow(["Device", "N", "Output"])
53+
csvwriter.writerows(results)
54+
55+
print("Benchmarking completed. Results saved to ", SAVE_DIR)
56+
57+
if __name__ == "__main__":
58+
main()

0 commit comments

Comments
 (0)