1010from .result import Result
1111from utils .utils import run , create_build_path
1212from .options import options
13+ from .oneapi import get_oneapi
14+ import shutil
15+
1316import os
1417
1518class VelocityBench (Suite ):
@@ -35,7 +38,10 @@ def benchmarks(self) -> list[Benchmark]:
3538 CudaSift (self ),
3639 Easywave (self ),
3740 QuickSilver (self ),
38- SobelFilter (self )
41+ SobelFilter (self ),
42+ DLCifar (self ),
43+ DLMnist (self ),
44+ SVM (self )
3945 ]
4046
4147class VelocityBase (Benchmark ):
@@ -50,6 +56,12 @@ def __init__(self, name: str, bin_name: str, vb: VelocityBench, unit: str):
5056 def download_deps (self ):
5157 return
5258
59+ def extra_cmake_args (self ) -> list [str ]:
60+ return []
61+
62+ def ld_libraries (self ) -> list [str ]:
63+ return []
64+
5365 def setup (self ):
5466 self .download_deps ()
5567 self .benchmark_bin = os .path .join (self .directory , self .bench_name , self .bin_name )
@@ -62,8 +74,10 @@ def setup(self):
6274 f"-S { self .code_path } " ,
6375 f"-DCMAKE_BUILD_TYPE=Release"
6476 ]
77+ configure_command += self .extra_cmake_args ()
78+
6579 run (configure_command , {'CC' : 'clang' , 'CXX' :'clang++' }, add_sycl = True )
66- run (f"cmake --build { build_path } -j" , add_sycl = True )
80+ run (f"cmake --build { build_path } -j" , add_sycl = True , ld_library = self . ld_libraries () )
6781
6882 def bin_args (self ) -> list [str ]:
6983 return []
@@ -82,7 +96,7 @@ def run(self, env_vars) -> list[Result]:
8296 ]
8397 command += self .bin_args ()
8498
85- result = self .run_bench (command , env_vars )
99+ result = self .run_bench (command , env_vars , ld_library = self . ld_libraries () )
86100
87101 return [ Result (label = self .name (), value = self .parse_output (result ), command = command , env = env_vars , stdout = result , unit = self .unit ) ]
88102
@@ -136,7 +150,6 @@ def __init__(self, vb: VelocityBench):
136150
137151 def download_deps (self ):
138152 self .download ("sobel_filter" , "https://github.com/oneapi-src/Velocity-Bench/raw/main/sobel_filter/res/sobel_filter_data.tgz?download=" , "sobel_filter_data.tgz" , untar = True )
139- return
140153
141154 def name (self ):
142155 return "Velocity-Bench Sobel Filter"
@@ -228,7 +241,6 @@ def get_last_elapsed_time(self, log_file_path) -> float:
228241 def parse_output (self , stdout : str ) -> float :
229242 return self .get_last_elapsed_time (os .path .join (options .benchmark_cwd , "easywave.log" ))
230243
231-
232244class CudaSift (VelocityBase ):
233245 def __init__ (self , vb : VelocityBench ):
234246 super ().__init__ ("cudaSift" , "cudaSift" , vb , "ms" )
@@ -248,3 +260,103 @@ def parse_output(self, stdout: str) -> float:
248260 return float (match .group (1 ))
249261 else :
250262 raise ValueError ("Failed to parse benchmark output." )
263+
264+ class DLCifar (VelocityBase ):
265+ def __init__ (self , vb : VelocityBench ):
266+ self .oneapi = get_oneapi ()
267+ super ().__init__ ("dl-cifar" , "dl-cifar_sycl" , vb , "s" )
268+
269+ def ld_libraries (self ):
270+ return self .oneapi .ld_libraries ()
271+
272+ def download_deps (self ):
273+ # TODO: dl-cifar hardcodes the path to this dataset as "../../datasets/cifar-10-binary"...
274+ self .download ("datasets" , "https://www.cs.toronto.edu/~kriz/cifar-10-binary.tar.gz" , "cifar-10-binary.tar.gz" , untar = True , skip_data_dir = True )
275+ return
276+
277+ def extra_cmake_args (self ):
278+ return [
279+ f"-DCMAKE_CXX_FLAGS=-O3 -fsycl -ffast-math -I{ self .oneapi .dnn_include ()} -I{ self .oneapi .mkl_include ()} -L{ self .oneapi .dnn_lib ()} -L{ self .oneapi .mkl_lib ()} "
280+ ]
281+
282+ def name (self ):
283+ return "Velocity-Bench dl-cifar"
284+
285+ def parse_output (self , stdout : str ) -> float :
286+ match = re .search (r'dl-cifar - total time for whole calculation: (\d+\.\d+) s' , stdout )
287+ if match :
288+ return float (match .group (1 ))
289+ else :
290+ raise ValueError ("Failed to parse benchmark output." )
291+
292+ class DLMnist (VelocityBase ):
293+ def __init__ (self , vb : VelocityBench ):
294+ self .oneapi = get_oneapi ()
295+ super ().__init__ ("dl-mnist" , "dl-mnist-sycl" , vb , "s" )
296+
297+ def ld_libraries (self ):
298+ return self .oneapi .ld_libraries ()
299+
300+ def download_deps (self ):
301+ # TODO: dl-mnist hardcodes the path to this dataset as "../../datasets/"...
302+ self .download ("datasets" , "https://raw.githubusercontent.com/fgnt/mnist/master/train-images-idx3-ubyte.gz" , "train-images.idx3-ubyte.gz" , unzip = True , skip_data_dir = True )
303+ self .download ("datasets" , "https://raw.githubusercontent.com/fgnt/mnist/master/train-labels-idx1-ubyte.gz" , "train-labels.idx1-ubyte.gz" , unzip = True , skip_data_dir = True )
304+ self .download ("datasets" , "https://raw.githubusercontent.com/fgnt/mnist/master/t10k-images-idx3-ubyte.gz" , "t10k-images.idx3-ubyte.gz" , unzip = True , skip_data_dir = True )
305+ self .download ("datasets" , "https://raw.githubusercontent.com/fgnt/mnist/master/t10k-labels-idx1-ubyte.gz" , "t10k-labels.idx1-ubyte.gz" , unzip = True , skip_data_dir = True )
306+
307+ def extra_cmake_args (self ):
308+ return [
309+ f"-DCMAKE_CXX_FLAGS=-O3 -fsycl -ffast-math -I{ self .oneapi .dnn_include ()} -I{ self .oneapi .mkl_include ()} -L{ self .oneapi .dnn_lib ()} -L{ self .oneapi .mkl_lib ()} "
310+ ]
311+
312+ def name (self ):
313+ return "Velocity-Bench dl-mnist"
314+
315+ def bin_args (self ):
316+ return [
317+ "-conv_algo" , "ONEDNN_AUTO"
318+ ]
319+
320+ # TODO: This shouldn't be required.
321+ # The application crashes with a segfault without it.
322+ def extra_env_vars (self ):
323+ return {
324+ "NEOReadDebugKeys" :"1" ,
325+ "DisableScratchPages" :"0" ,
326+ }
327+
328+ def parse_output (self , stdout : str ) -> float :
329+ match = re .search (r'dl-mnist - total time for whole calculation: (\d+\.\d+) s' , stdout )
330+ if match :
331+ return float (match .group (1 ))
332+ else :
333+ raise ValueError ("Failed to parse benchmark output." )
334+
335+ class SVM (VelocityBase ):
336+ def __init__ (self , vb : VelocityBench ):
337+ self .oneapi = get_oneapi ()
338+ super ().__init__ ("svm" , "svm_sycl" , vb , "s" )
339+
340+ def ld_libraries (self ):
341+ return self .oneapi .ld_libraries ()
342+
343+ def extra_cmake_args (self ):
344+ return [
345+ f"-DCMAKE_CXX_FLAGS=-O3 -fsycl -ffast-math -I{ self .oneapi .dnn_include ()} -I{ self .oneapi .mkl_include ()} -L{ self .oneapi .dnn_lib ()} -L{ self .oneapi .mkl_lib ()} "
346+ ]
347+
348+ def name (self ):
349+ return "Velocity-Bench svm"
350+
351+ def bin_args (self ):
352+ return [
353+ f"{ self .code_path } /a9a" ,
354+ f"{ self .code_path } /a.m" ,
355+ ]
356+
357+ def parse_output (self , stdout : str ) -> float :
358+ match = re .search (r'Total elapsed time : (\d+\.\d+) s' , stdout )
359+ if match :
360+ return float (match .group (1 ))
361+ else :
362+ raise ValueError ("Failed to parse benchmark output." )
0 commit comments