1010# Define path to the benchmark executable
1111SCRIPT_DIR = Path (__file__ ).parent .parent
1212BENCHMARK_EXECUTABLE = SCRIPT_DIR / "build" / "benchmark.exe"
13- SCRIPT_DIR = Path (__file__ ).parent .parent
1413SAVE_DIR = SCRIPT_DIR / "automation" / "benchmark_results.csv"
1514
1615
@@ -19,38 +18,31 @@ def get_gpu_devices():
1918 platforms = cl .get_platforms ()
2019 devices = [dev for p in platforms for dev in p .get_devices (device_type = cl .device_type .GPU )]
2120
22- unique_devices = []
23- seen_names = set ()
24-
25- for dev in devices :
26- if dev .name not in seen_names :
27- unique_devices .append (dev )
28- seen_names .add (dev .name )
29-
30- for i , dev in enumerate (unique_devices ):
21+ for i , dev in enumerate (devices ):
3122 print (f"{ i } : { dev .name } " )
32- print (f" Vendor: { dev .vendor } " )
33- print (f" Max Compute Units: { dev .max_compute_units } " )
34- print (f" Max Clock Frequency: { dev .max_clock_frequency } MHz" )
35- print (f" Global Memory Size: { dev .global_mem_size // (1024 ** 2 )} MB" )
36- print (f" Local Memory Size: { dev .local_mem_size // 1024 } KB" )
23+ # print(f" Vendor: {dev.vendor}")
24+ # print(f" Max Compute Units: {dev.max_compute_units}")
25+ # print(f" Max Clock Frequency: {dev.max_clock_frequency} MHz")
26+ # print(f" Global Memory Size: {dev.global_mem_size // (1024**2)} MB")
27+ # print(f" Local Memory Size: {dev.local_mem_size // 1024} KB")
3728
38- return unique_devices
29+ return devices
3930
4031
41- def run_benchmark (device , N ):
32+ def run_benchmark (device , N , mode = 0 ):
4233 if not BENCHMARK_EXECUTABLE .exists ():
4334 print (f"Benchmark executable not found at { BENCHMARK_EXECUTABLE } " )
4435 return None
4536 try :
46- result = subprocess .run ([str (BENCHMARK_EXECUTABLE ), str (device ), str (N )], text = True , capture_output = True )
37+ result = subprocess .run ([str (BENCHMARK_EXECUTABLE ), str (device ), str (N ), str ( mode ) ], text = True , capture_output = True )
4738
4839 if result .returncode != 0 :
4940 print (f"Error running benchmark for device { device } with N={ N } : { result .stderr } " )
5041 return None
51- if "Correct: yes" not in result .stdout :
42+ if "Correct:" in result . stdout and "no" in result .stdout :
5243 print ("Validation failed" )
5344 return None
45+
5446 for line in result .stdout .splitlines ():
5547 if line .startswith ("Time:" ):
5648 return float (line .split ()[1 ])
@@ -60,14 +52,18 @@ def run_benchmark(device, N):
6052 return None
6153
6254def plot_results ():
55+ if not SAVE_DIR .exists ():
56+ print ("No results file. Run benchmarks first." )
57+ return
58+
6359 df = pd .read_csv (SAVE_DIR )
6460
6561 for device_index in df ["Device" ].unique ():
6662 subset = df [df ["Device" ] == device_index ]
6763 plt .plot (subset ["N" ], subset ["Time (ms)" ], label = f"Device { device_index } " )
6864
6965 plt .xlabel ("N (size)" )
70- plt .ylabel ("Time (s )" )
66+ plt .ylabel ("Time (ms )" )
7167 plt .xscale ("log" , base = 2 )
7268 plt .yscale ("log" )
7369 plt .title ("GPU Benchmark Results" )
@@ -76,16 +72,16 @@ def plot_results():
7672 plt .savefig (SCRIPT_DIR / "automation" / "benchmark_results.png" )
7773 plt .show ()
7874
79- def main ():
75+ def main (mode ):
8076 devices = get_gpu_devices () # List of device IDs to benchmark
81- N_values = [1 << 22 , 1 << 24 , 1 << 26 , 1 << 28 ] # Different sizes for the benchmark
77+ N_values = [1 << 10 , 1 << 15 , 1 << 22 , 1 << 24 , 1 << 28 ] # Different sizes for the benchmark
8278
8379 results = []
8480 for N in N_values :
8581 for i , dev in enumerate (devices ):
8682 print (f"Running benchmark for device { i } with N={ N } ..." )
87- output = run_benchmark (i , N )
88- if output :
83+ output = run_benchmark (i , N , mode )
84+ if output is not None :
8985 results .append ((i , N , output ))
9086 print (f"Result: { output } " )
9187
@@ -100,4 +96,5 @@ def main():
10096 plot_results ()
10197
10298if __name__ == "__main__" :
103- main ()
99+ mode = sys .argv [1 ] if len (sys .argv ) > 1 else 0
100+ main (mode )
0 commit comments