Skip to content

Commit e7b5949

Browse files
committed
address second round of pickling review feedback
Reject unknown filter strings at pickling time, skip empty affinity partitions in get_sub_device_or_skip, and test root device copies without a partitionable device.
1 parent 0929cf2 commit e7b5949

4 files changed

Lines changed: 24 additions & 11 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
* Added `dpctl::utils::defer_release` to `dpctl4pybind11.hpp`, which calls a release callback once the given events have completed [gh-2359](https://github.com/IntelPython/dpctl/pull/2359)
1414
* Added `dpctl.SyclQueue.get_last_event` and `dpctl.SyclQueue.is_get_last_event_available`, and the `DPCTLQueue_GetLastEvent` and `DPCTLQueue_GetLastEvent_Available` C-API functions, wrapping the DPC++ `sycl_ext_oneapi_in_order_queue_events` extension [gh-2299](https://github.com/IntelPython/dpctl/pull/2299)
1515
* Added `dpctl.SyclPlatform.has_aspect_*` properties and the `DPCTLPlatform_HasAspect` C-API function for querying aspects supported by all devices of a platform [gh-2412](https://github.com/IntelPython/dpctl/pull/2412)
16-
17-
* `dpctl.SyclDevice`, `dpctl.SyclContext`, and `dpctl.SyclQueue` can be pickled. Root devices are restored by filter string, default contexts by one of their devices, and queues by context, device, and properties, with default-property queues restored as the cached queue of their device. `copy.copy` and `copy.deepcopy` return the same object
16+
* `dpctl.SyclDevice`, `dpctl.SyclContext`, and `dpctl.SyclQueue` can be pickled. Root devices are restored by filter string, default contexts by one of their devices, and queues by context, device, and properties, with default-property queues restored as the cached queue of their device. `copy.copy` and `copy.deepcopy` return the same object [gh-2406](https://github.com/IntelPython/dpctl/pull/2406)
1817

1918
### Changed
2019
* Object lifetime during offload is now managed by a list of releases deferred until the events that gate them have completed, rather than by a `host_task`. `dpctl` keeps one thread for looking over the list and running the releases that have come due, started by the first release deferred and again in the child of a `fork`, which takes the GIL to do so and lets a release call into the interpreter and free USM allocations [gh-2359](https://github.com/IntelPython/dpctl/pull/2359)
2120
* `import_dpctl()` now returns 0 on success and -1 with a Python exception set on failure, and `dpctl4pybind11.hpp` raises that exception rather than failing on the first C-API call [gh-2359](https://github.com/IntelPython/dpctl/pull/2359)
2221
* The event returned by `dpctl.SyclQueue.keep_args_alive`, `dpctl::utils::keep_args_alive` and `dpctl.SyclQueue._submit_keep_args_alive` is now for an empty kernel that gates the deferred release rather than for a `host_task` that performs it, so its completion means that the objects are no longer in use rather than that they have been released [gh-2359](https://github.com/IntelPython/dpctl/pull/2359)
2322
* `dpctl.utils.SequentialOrderManager[q].submitted_events` includes the queue's last event for in-order queues when `sycl_ext_oneapi_in_order_queue_events` is available, and `wait()` waits for all work on an in-order queue [gh-2299](https://github.com/IntelPython/dpctl/pull/2299)
24-
25-
* Pickled `dpctl.memory.MemoryUSMShared`, `MemoryUSMDevice`, and `MemoryUSMHost` objects keep their queue instead of being restored on the default device. Pickling memory whose queue can not be pickled raises `pickle.PicklingError`
23+
* Pickled `dpctl.memory.MemoryUSMShared`, `MemoryUSMDevice`, and `MemoryUSMHost` objects keep their queue instead of being restored on the default device. Pickling memory whose queue can not be pickled raises `pickle.PicklingError` [gh-2406](https://github.com/IntelPython/dpctl/pull/2406)
2624

2725
### Deprecated
2826
* Deprecated `dpctl.SyclQueue._submit_keep_args_alive` in favor of `dpctl.SyclQueue.keep_args_alive`, which it now calls and which behaves identically [gh-2359](https://github.com/IntelPython/dpctl/pull/2359)

‎dpctl/_sycl_device.pyx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1682,12 +1682,18 @@ cdef class SyclDevice(_SyclDevice):
16821682
of the same name.
16831683
16841684
Raises:
1685-
pickle.PicklingError: if the device is not a root device.
1685+
pickle.PicklingError: if the device is not a root device, or its
1686+
filter string has an ``unknown`` backend or device type.
16861687
"""
16871688
try:
16881689
filter_string = self.filter_string
16891690
except ValueError as e:
16901691
raise pickle.PicklingError(f"Cannot pickle {self!r}: {e}") from e
1692+
if "unknown" in filter_string.split(":")[:2]:
1693+
raise pickle.PicklingError(
1694+
f"Cannot pickle device '{self.name}': filter string "
1695+
f"'{filter_string}' can not select it"
1696+
)
16911697
return _rebuild_device, (filter_string, self.name)
16921698

16931699
def __copy__(self):

‎dpctl/tests/helper/_helper.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def get_sub_device_or_skip():
5555
for dev in dpctl.get_devices():
5656
for partition in ("next_partitionable", [1, 1]):
5757
try:
58-
return dev.create_sub_devices(partition=partition)[0]
58+
sub_devs = dev.create_sub_devices(partition=partition)
5959
except dpctl.SyclSubDeviceCreationError:
60-
pass
60+
continue
61+
if sub_devs:
62+
return sub_devs[0]
6163
pytest.skip("No device can be partitioned")

‎dpctl/tests/test_sycl_device.py‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,15 @@ def test_device_unpickling_missing_device():
495495

496496

497497
def test_device_copy():
498+
try:
499+
dev = dpctl.SyclDevice()
500+
except SyclDeviceCreationError:
501+
pytest.skip("No default device available")
502+
assert copy.copy(dev) is dev
503+
assert copy.deepcopy(dev) is dev
504+
505+
506+
def test_sub_device_copy():
498507
sub_dev = get_sub_device_or_skip()
499-
root_dev = sub_dev.parent_device
500-
for dev in (root_dev, sub_dev):
501-
assert copy.copy(dev) is dev
502-
assert copy.deepcopy(dev) is dev
508+
assert copy.copy(sub_dev) is sub_dev
509+
assert copy.deepcopy(sub_dev) is sub_dev

0 commit comments

Comments
 (0)