Skip to content

Commit dbd5eed

Browse files
Adjusted example sycl_queue to handle error creating sub-devices
1 parent 08aa044 commit dbd5eed

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

docs/docfiles/user_guides/manual/dpctl/queues.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ the associated task completes.
4545

4646
.. literalinclude:: ../../../../../examples/python/sycl_queue.py
4747
:language: python
48-
:lines: 17-19, 67-79
48+
:lines: 17-19, 72-89
4949
:caption: Constructing SyclQueue from context and device
5050
:linenos:
5151

examples/python/sycl_queue.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ def create_queue_from_subdevice():
5555
Create a queue from a sub-device.
5656
"""
5757
cpu_d = dpctl.SyclDevice("opencl:cpu:0")
58-
sub_devs = cpu_d.create_sub_devices(partition=2)
58+
try:
59+
sub_devs = cpu_d.create_sub_devices(partition=2)
60+
except dpctl.SubDeviceCreationError:
61+
print("Could not create sub device.")
62+
print(f"{cpu_d} has {cpu_d.max_compute_units} compute units")
63+
return
5964
q = dpctl.SyclQueue(sub_devs[0])
6065
# a single-device context is created automatically
6166
print(
@@ -69,7 +74,12 @@ def create_queue_from_subdevice_multidevice_context():
6974
Create a queue from a sub-device.
7075
"""
7176
cpu_d = dpctl.SyclDevice("opencl:cpu:0")
72-
sub_devs = cpu_d.create_sub_devices(partition=2)
77+
try:
78+
sub_devs = cpu_d.create_sub_devices(partition=2)
79+
except dpctl.SubDeviceCreationError:
80+
print("Could not create sub device.")
81+
print(f"{cpu_d} has {cpu_d.max_compute_units} compute units")
82+
return
7383
ctx = dpctl.SyclContext(sub_devs)
7484
q = dpctl.SyclQueue(ctx, sub_devs[0], partition="enable_profiling")
7585
print(

0 commit comments

Comments
 (0)