21
21
from reference_black_scholes import ref_python_black_scholes
22
22
23
23
24
- def gen_option_params (n_opts , pl , ph , sl , sh , tl , th , rl , rh , vl , vh , dtype , queue = None ):
24
+ def gen_option_params (
25
+ n_opts , pl , ph , sl , sh , tl , th , rl , rh , vl , vh , dtype , queue = None
26
+ ):
25
27
nbytes = n_opts * 5 * np .dtype (dtype ).itemsize
26
28
usm_mem = dpctl_mem .MemoryUSMShared (nbytes , queue = queue )
27
29
params = np .ndarray (shape = (n_opts , 5 ), buffer = usm_mem , dtype = dtype )
28
30
seed = 1234
29
- bs .populate_params (params , pl , ph , sl , sh , tl , th , rl , rh , vl , vh , seed , queue = queue )
31
+ bs .populate_params (
32
+ params , pl , ph , sl , sh , tl , th , rl , rh , vl , vh , seed , queue = queue
33
+ )
30
34
return params
31
35
32
36
@@ -47,7 +51,9 @@ def gen_option_params(n_opts, pl, ph, sl, sh, tl, th, rl, rh, vl, vh, dtype, que
47
51
# compute prices in CPython
48
52
X_ref = np .array ([ref_python_black_scholes (* opt ) for opt in opts ], dtype = "d" )
49
53
50
- print ("Correctness check: allclose(Xgpu, Xref) == " , np .allclose (Xgpu , X_ref , atol = 1e-5 ))
54
+ print (
55
+ "Correctness check: allclose(Xgpu, Xref) == " , np .allclose (Xgpu , X_ref , atol = 1e-5 )
56
+ )
51
57
52
58
n_opts = 3 * 10 ** 6
53
59
@@ -72,14 +78,14 @@ def gen_option_params(n_opts, pl, ph, sl, sh, tl, th, rl, rh, vl, vh, dtype, que
72
78
X1 = bs .black_scholes_price (opts1 , queue = cpu_q )
73
79
t1 = timeit .default_timer ()
74
80
75
- cpu_times .append (t1 - t0 )
81
+ cpu_times .append (t1 - t0 )
76
82
77
83
# compute on GPU sycl device
78
84
79
85
t0 = timeit .default_timer ()
80
86
X2 = bs .black_scholes_price (opts2 , queue = gpu_q )
81
87
t1 = timeit .default_timer ()
82
- gpu_times .append (t1 - t0 )
88
+ gpu_times .append (t1 - t0 )
83
89
84
90
print ("Using : {}" .format (cpu_q .sycl_device .name ))
85
91
print ("Wall times : {}" .format (cpu_times ))
0 commit comments