10
10
from .result import Result
11
11
from utils .utils import run , create_build_path
12
12
from .options import options
13
+ from .oneapi import get_oneapi
14
+ import shutil
15
+
13
16
import os
14
17
15
18
class VelocityBench (Suite ):
@@ -35,7 +38,10 @@ def benchmarks(self) -> list[Benchmark]:
35
38
CudaSift (self ),
36
39
Easywave (self ),
37
40
QuickSilver (self ),
38
- SobelFilter (self )
41
+ SobelFilter (self ),
42
+ DLCifar (self ),
43
+ DLMnist (self ),
44
+ SVM (self )
39
45
]
40
46
41
47
class VelocityBase (Benchmark ):
@@ -50,6 +56,12 @@ def __init__(self, name: str, bin_name: str, vb: VelocityBench, unit: str):
50
56
def download_deps (self ):
51
57
return
52
58
59
+ def extra_cmake_args (self ) -> list [str ]:
60
+ return []
61
+
62
+ def ld_libraries (self ) -> list [str ]:
63
+ return []
64
+
53
65
def setup (self ):
54
66
self .download_deps ()
55
67
self .benchmark_bin = os .path .join (self .directory , self .bench_name , self .bin_name )
@@ -62,8 +74,10 @@ def setup(self):
62
74
f"-S { self .code_path } " ,
63
75
f"-DCMAKE_BUILD_TYPE=Release"
64
76
]
77
+ configure_command += self .extra_cmake_args ()
78
+
65
79
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 () )
67
81
68
82
def bin_args (self ) -> list [str ]:
69
83
return []
@@ -82,7 +96,7 @@ def run(self, env_vars) -> list[Result]:
82
96
]
83
97
command += self .bin_args ()
84
98
85
- result = self .run_bench (command , env_vars )
99
+ result = self .run_bench (command , env_vars , ld_library = self . ld_libraries () )
86
100
87
101
return [ Result (label = self .name (), value = self .parse_output (result ), command = command , env = env_vars , stdout = result , unit = self .unit ) ]
88
102
@@ -136,7 +150,6 @@ def __init__(self, vb: VelocityBench):
136
150
137
151
def download_deps (self ):
138
152
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
140
153
141
154
def name (self ):
142
155
return "Velocity-Bench Sobel Filter"
@@ -228,7 +241,6 @@ def get_last_elapsed_time(self, log_file_path) -> float:
228
241
def parse_output (self , stdout : str ) -> float :
229
242
return self .get_last_elapsed_time (os .path .join (options .benchmark_cwd , "easywave.log" ))
230
243
231
-
232
244
class CudaSift (VelocityBase ):
233
245
def __init__ (self , vb : VelocityBench ):
234
246
super ().__init__ ("cudaSift" , "cudaSift" , vb , "ms" )
@@ -248,3 +260,103 @@ def parse_output(self, stdout: str) -> float:
248
260
return float (match .group (1 ))
249
261
else :
250
262
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