Skip to content

Commit f6a1f06

Browse files
Add synchronization points in example
1 parent 61f8c54 commit f6a1f06

File tree

7 files changed

+20
-9
lines changed

7 files changed

+20
-9
lines changed

examples/cython/usm_memory/blackscholes/blackscholes.pyx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,15 @@ def black_scholes_price(c_dpt.usm_ndarray option_params_arr):
106106
call_put_prices = dpt.empty((n_opts, 2), dtype='d', sycl_queue=q)
107107
dp1 = <double *>option_params_arr.get_data()
108108
dp2 = <double *>call_put_prices.get_data()
109+
# ensure content of dp1 and dp2 is no longer worked on
110+
exec_q_ptr[0].wait()
109111
cpp_blackscholes[double](exec_q_ptr[0], n_opts, dp1, dp2)
110112
elif (typenum_ == c_dpt.UAR_FLOAT):
111113
call_put_prices = dpt.empty((n_opts, 2), dtype='f', sycl_queue=q)
112114
fp1 = <float *>option_params_arr.get_data()
113115
fp2 = <float *>call_put_prices.get_data()
116+
# ensure content of fp1 and fp2 is no longer worked on
117+
exec_q_ptr[0].wait()
114118
cpp_blackscholes[float](exec_q_ptr[0], n_opts, fp1, fp2)
115119
else:
116120
raise ValueError("Unsupported data-type")
@@ -196,11 +200,13 @@ def populate_params(
196200

197201
if (typenum_ == c_dpt.UAR_DOUBLE):
198202
dp = <double *>option_params_arr.get_data()
203+
exec_q_ptr[0].wait()
199204
cpp_populate_params[double](
200205
exec_q_ptr[0], n_opts, dp, pl, ph, sl, sh, tl, th, rl, rh, vl, vh, seed
201206
)
202207
elif (typenum_ == c_dpt.UAR_FLOAT):
203208
fp = <float *>option_params_arr.get_data()
209+
exec_q_ptr[0].wait()
204210
cpp_populate_params[float](
205211
exec_q_ptr[0], n_opts, fp, pl, ph, sl, sh, tl, th, rl, rh, vl, vh, seed
206212
)

examples/cython/usm_memory/src/sycl_blackscholes.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ constexpr int CALL = 0;
4747
constexpr int PUT = 1;
4848

4949
template <typename T>
50-
void cpp_blackscholes(sycl::queue q, size_t n_opts, T *params, T *callput)
50+
void cpp_blackscholes(sycl::queue &q, size_t n_opts, T *params, T *callput)
5151
{
5252
using data_t = T;
5353

@@ -57,8 +57,7 @@ void cpp_blackscholes(sycl::queue q, size_t n_opts, T *params, T *callput)
5757
data_t half = one / two;
5858

5959
cgh.parallel_for<class black_scholes_kernel<T>>(
60-
sycl::range<1>(n_opts),
61-
[=](sycl::id<1> idx)
60+
sycl::range<1>(n_opts), [=](sycl::id<1> idx)
6261
{
6362
const size_t i = n_params * idx[0];
6463
const data_t opt_price = params[i + PRICE];
@@ -106,7 +105,7 @@ void cpp_blackscholes(sycl::queue q, size_t n_opts, T *params, T *callput)
106105
const size_t callput_i = n_prices * idx[0];
107106
callput[callput_i + CALL] = call_price;
108107
callput[callput_i + PUT] = put_price;
109-
});
108+
});
110109
});
111110

112111
e.wait_and_throw();

examples/pybind11/external_usm_allocation/external_usm_allocation/_usm_alloc_example.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ py::dict construct_sua_iface(DMatrix &m)
114114
iface["typestr"] = "|f8";
115115
iface["syclobj"] = syclobj;
116116

117+
// ensure that content of array is flushed out
118+
m.get_queue().wait();
119+
117120
return iface;
118121
}
119122

examples/pybind11/onemkl_gemv/solve.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,14 @@ def cg_solve(A, b):
127127
converged is False if solver has not converged, or the iteration number
128128
"""
129129
exec_queue = A.sycl_queue
130+
exec_queue.wait()
131+
130132
x = dpt.zeros_like(b)
131133
Ap = dpt.empty_like(x)
132134

133135
all_host_tasks = []
134-
r = dpt.copy(b) # synchronous copy
135-
p = dpt.copy(b) # synchronous copy
136+
r = dpt.copy(b)
137+
p = dpt.copy(b)
136138

137139
rsold = sycl_gemm.norm_squared_blocking(exec_queue, r)
138140
if rsold < 1e-20:

examples/pybind11/onemkl_gemv/sycl_gemm/_onemkl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace py = pybind11;
4141
using dpctl::utils::keep_args_alive;
4242

4343
std::pair<sycl::event, sycl::event>
44-
py_gemv(sycl::queue q,
44+
py_gemv(sycl::queue &q,
4545
dpctl::tensor::usm_ndarray matrix,
4646
dpctl::tensor::usm_ndarray vector,
4747
dpctl::tensor::usm_ndarray result,

examples/pybind11/use_dpctl_sycl_kernel/tests/test_user_kernel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def test_kernel_submit_through_extension():
6464
x = dpt.arange(0, stop=13, step=1, dtype="i4", sycl_queue=q)
6565
y = dpt.zeros_like(x)
6666

67+
q.wait()
6768
uk.submit_custom_kernel(q, krn, x, y, [])
6869

6970
assert np.array_equal(dpt.asnumpy(y), np.arange(0, 26, step=2, dtype="i4"))

examples/pybind11/use_dpctl_sycl_kernel/use_kernel/_example.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535

3636
namespace py = pybind11;
3737

38-
void submit_custom_kernel(sycl::queue q,
39-
sycl::kernel krn,
38+
void submit_custom_kernel(sycl::queue &q,
39+
sycl::kernel &krn,
4040
dpctl::tensor::usm_ndarray x,
4141
dpctl::tensor::usm_ndarray y,
4242
const std::vector<sycl::event> &depends = {})

0 commit comments

Comments
 (0)