@@ -64,59 +64,48 @@ def gen_option_params(
64
64
n_opts = 3 * 10 ** 6
65
65
66
66
# compute on CPU sycl device
67
- cpu_q = dpctl .SyclQueue ("opencl:cpu:0" )
68
- opts1 = gen_option_params (
69
- n_opts ,
70
- 20.0 ,
71
- 30.0 ,
72
- 22.0 ,
73
- 29.0 ,
74
- 18.0 ,
75
- 24.0 ,
76
- 0.01 ,
77
- 0.05 ,
78
- 0.01 ,
79
- 0.05 ,
80
- "d" ,
81
- queue = cpu_q ,
82
- )
83
-
84
- gpu_q = dpctl .SyclQueue ("level_zero:gpu:0" )
85
- opts2 = gen_option_params (
86
- n_opts ,
87
- 20.0 ,
88
- 30.0 ,
89
- 22.0 ,
90
- 29.0 ,
91
- 18.0 ,
92
- 24.0 ,
93
- 0.01 ,
94
- 0.05 ,
95
- 0.01 ,
96
- 0.05 ,
97
- "d" ,
98
- queue = gpu_q ,
99
- )
100
-
101
- cpu_times = []
102
- gpu_times = []
103
- for _ in range (5 ):
104
-
105
- t0 = timeit .default_timer ()
106
- X1 = bs .black_scholes_price (opts1 , queue = cpu_q )
107
- t1 = timeit .default_timer ()
108
67
109
- cpu_times .append (t1 - t0 )
110
-
111
- # compute on GPU sycl device
112
-
113
- t0 = timeit .default_timer ()
114
- X2 = bs .black_scholes_price (opts2 , queue = gpu_q )
115
- t1 = timeit .default_timer ()
116
- gpu_times .append (t1 - t0 )
117
-
118
- print ("Using : {}" .format (cpu_q .sycl_device .name ))
119
- print ("Wall times : {}" .format (cpu_times ))
120
-
121
- print ("Using : {}" .format (gpu_q .sycl_device .name ))
122
- print ("Wall times : {}" .format (gpu_times ))
68
+ queues = []
69
+ for filter_str in ["cpu" , "gpu" ]:
70
+ try :
71
+ q = dpctl .SyclQueue (filter_str )
72
+ queues .append (q )
73
+ except dpctl .SyclQueueCreationError :
74
+ continue
75
+
76
+ if not queues :
77
+ print ("No queues could not created, nothing to do." )
78
+ exit (0 )
79
+
80
+ opt_params_list = []
81
+ for q in queues :
82
+ opt_params = gen_option_params (
83
+ n_opts ,
84
+ 20.0 ,
85
+ 30.0 ,
86
+ 22.0 ,
87
+ 29.0 ,
88
+ 18.0 ,
89
+ 24.0 ,
90
+ 0.01 ,
91
+ 0.05 ,
92
+ 0.01 ,
93
+ 0.05 ,
94
+ "d" ,
95
+ queue = q ,
96
+ )
97
+ opt_params_list .append (opt_params )
98
+
99
+ times_dict = dict ()
100
+ for q , params in zip (queues , opt_params_list ):
101
+ times_list = []
102
+ for _ in range (5 ):
103
+ t0 = timeit .default_timer ()
104
+ X1 = bs .black_scholes_price (params , queue = q )
105
+ t1 = timeit .default_timer ()
106
+ times_list .append (t1 - t0 )
107
+ times_dict [q .name ] = times_list
108
+
109
+ for dev_name , wall_times in times_dict .items ():
110
+ print ("Using : {}" .format (dev_name ))
111
+ print ("Wall times : {}" .format (wall_times ))
0 commit comments