Skip to content

Commit 9842e3c

Browse files
Use try/except to handle failure to create SyclQueue
1 parent 4d92808 commit 9842e3c

File tree

1 file changed

+22
-9
lines changed
  • examples/cython/sycl_buffer

1 file changed

+22
-9
lines changed

examples/cython/sycl_buffer/run.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,31 @@
2323

2424
print("Result computed by NumPy")
2525
print(X.sum(axis=0))
26-
print("Result computed by SYCL extension using default offloading target")
27-
print(sb.columnwise_total(X))
2826

27+
try:
28+
res = sb.columnwise_total(X)
29+
print("Result computed by SYCL extension using default offloading target")
30+
print(res)
31+
except dpctl.SyclQueueCreationError:
32+
print(
33+
"Could not create SyclQueue for default selected device. Nothing to do."
34+
)
35+
exit(0)
2936

3037
print("")
3138

3239
# controlling where to offload
3340

34-
q = dpctl.SyclQueue("opencl:gpu")
35-
print("Running on: ", q.sycl_device.name)
36-
print(sb.columnwise_total(X, queue=q))
37-
38-
q = dpctl.SyclQueue("opencl:cpu")
39-
print("Running on: ", q.sycl_device.name)
40-
print(sb.columnwise_total(X, queue=q))
41+
try:
42+
q = dpctl.SyclQueue("opencl:gpu")
43+
print("Running on: ", q.sycl_device.name)
44+
print(sb.columnwise_total(X, queue=q))
45+
except dpctl.SyclQueueCreationError:
46+
print("Not running onf opencl:gpu, queue could not be created")
47+
48+
try:
49+
q = dpctl.SyclQueue("opencl:cpu")
50+
print("Running on: ", q.sycl_device.name)
51+
print(sb.columnwise_total(X, queue=q))
52+
except dpctl.SyclQueueCreationError:
53+
print("Not running onf opencl:cpu, queue could not be created")

0 commit comments

Comments
 (0)