Repository navigation
Improve pickling support #2406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Improve pickling support #2406
Changes from all commits
d934989
19b210a
cde2e00
ed647d8
234b298
c825935
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,6 +155,7 @@ from ._sycl_platform cimport SyclPlatform | |
|
|
||
| import collections | ||
| import functools | ||
| import pickle | ||
| import warnings | ||
|
|
||
| __all__ = [ | ||
|
|
@@ -371,6 +372,26 @@ def _cached_filter_string(d : SyclDevice): | |
| return ":".join((br_str, dt_str, str(relId))) | ||
|
|
||
|
|
||
| def _rebuild_device(str filter_string, str name): | ||
| """Unpickles a :class:`dpctl.SyclDevice`. | ||
|
|
||
| Raises: | ||
| pickle.UnpicklingError: if no device matches ``filter_string``, or | ||
| the device it selects is not named ``name``. | ||
| """ | ||
| try: | ||
| dev = SyclDevice(filter_string) | ||
| except SyclDeviceCreationError as e: | ||
| raise pickle.UnpicklingError( | ||
| f"Device '{filter_string}' ('{name}') is not available" | ||
| ) from e | ||
| if dev.name != name: | ||
| raise pickle.UnpicklingError( | ||
| f"Device '{filter_string}' is '{dev.name}', expected '{name}'" | ||
| ) | ||
| return dev | ||
|
|
||
|
|
||
| cdef class SyclDevice(_SyclDevice): | ||
| """ SyclDevice(arg=None) | ||
| A Python wrapper for the ``sycl::device`` C++ class. | ||
|
|
@@ -1652,6 +1673,29 @@ cdef class SyclDevice(_SyclDevice): | |
| """ | ||
| return DPCTLDevice_Hash(self._device_ref) | ||
|
|
||
| def __reduce__(self): | ||
| """Pickles a root device by its filter string and name. | ||
|
|
||
| The filter string's device id is relative to the devices visible | ||
| under ``ONEAPI_DEVICE_SELECTOR``. If the loading process sees a | ||
| different set of devices, the pickle may load onto another device | ||
| of the same name. | ||
|
|
||
| Raises: | ||
| pickle.PicklingError: if the device is not a root device. | ||
| """ | ||
| try: | ||
| filter_string = self.filter_string | ||
| except ValueError as e: | ||
| raise pickle.PicklingError(f"Cannot pickle {self!r}: {e}") from e | ||
| return _rebuild_device, (filter_string, self.name) | ||
|
Comment on lines
+1687
to
+1691
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a device type that |
||
|
|
||
| def __copy__(self): | ||
| return self | ||
|
|
||
| def __deepcopy__(self, memo): | ||
| return self | ||
|
|
||
| cdef tuple create_sub_devices_equally(self, size_t count): | ||
| """ Returns a tuple of sub-devices partitioned from this SYCL device | ||
| based on the ``count`` parameter. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both new entries (here and line 22) have no
[gh-2406](https://github.com/IntelPython/dpctl/pull/2406)link, which every other[dev]entry has. The blank lines before them (lines 14 and 21) split the lists and are not needed.