Skip to content

Commit 392c11d

Browse files
committed
Add exception handling in subdevices example
as some devices (especially those in GH runners) cannot be partitioned into sub-devices, we print that the device cannot be partitioned and discard the exception
1 parent 543bb55 commit 392c11d

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

examples/python/subdevices.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ def subdivide_root_cpu_device():
4343
"cpu_d is "
4444
+ ("a root device." if is_root_device(cpu_d) else "not a root device.")
4545
)
46-
sub_devs = cpu_d.create_sub_devices(partition=4)
46+
try:
47+
sub_devs = cpu_d.create_sub_devices(partition=4)
48+
except dpctl.SyclSubDeviceCreationError:
49+
print("Device partitioning was not successful.")
50+
return
4751
print("Sub-device #EU: ", [d.max_compute_units for d in sub_devs])
4852
print("Sub-device is_root: ", [is_root_device(d) for d in sub_devs])
4953
print(
@@ -70,7 +74,7 @@ def subdivide_by_affinity(affinity="numa"):
7074
f"{len(sub_devs)} sub-devices were created with respective #EUs "
7175
f"being {[d.max_compute_units for d in sub_devs]}"
7276
)
73-
except Exception:
77+
except dpctl.SyclSubDeviceCreationError:
7478
print("Device partitioning by affinity was not successful.")
7579

7680

@@ -82,7 +86,11 @@ def create_subdevice_queue():
8286
"""
8387
cpu_d = dpctl.SyclDevice("cpu")
8488
cpu_count = cpu_d.max_compute_units
85-
sub_devs = cpu_d.create_sub_devices(partition=cpu_count // 2)
89+
try:
90+
sub_devs = cpu_d.create_sub_devices(partition=cpu_count // 2)
91+
except dpctl.SyclSubDeviceCreationError:
92+
print("Device partitioning was not successful.")
93+
return
8694
multidevice_ctx = dpctl.SyclContext(sub_devs)
8795
# create a SyclQueue for each sub-device, using common
8896
# multi-device context

0 commit comments

Comments
 (0)