|
23 | 23 | """ |
24 | 24 |
|
25 | 25 | from ._backend cimport ( # noqa: E211 |
| 26 | + DPCTLContext_AreEq, |
26 | 27 | DPCTLContext_Create, |
27 | 28 | DPCTLContext_Delete, |
28 | 29 | DPCTLDefaultSelector_Create, |
@@ -103,6 +104,7 @@ from libc.stdlib cimport free, malloc |
103 | 104 |
|
104 | 105 | import collections.abc |
105 | 106 | import logging |
| 107 | +import pickle |
106 | 108 | import struct |
107 | 109 | import sys |
108 | 110 |
|
@@ -2221,9 +2223,26 @@ cdef class SyclQueue(_SyclQueue): |
2221 | 2223 | """Pickles the queue's context, device, and properties. |
2222 | 2224 |
|
2223 | 2225 | Raises: |
2224 | | - pickle.PicklingError: if the queue's context is not the default |
2225 | | - context of its device, or the device is not a root device. |
| 2226 | + pickle.PicklingError: if the queue's device is not a root device, |
| 2227 | + or its context is not the default context of that device. |
2226 | 2228 | """ |
| 2229 | + cdef DPCTLSyclContextRef CRef = NULL |
| 2230 | + cdef bint is_default_ctx = False |
| 2231 | + if self._device.parent_device is not None: |
| 2232 | + raise pickle.PicklingError( |
| 2233 | + f"Cannot pickle {self!r}: its device is not a root device" |
| 2234 | + ) |
| 2235 | + CRef = DPCTLDeviceMgr_GetCachedContext(self._device.get_device_ref()) |
| 2236 | + if CRef is not NULL: |
| 2237 | + is_default_ctx = DPCTLContext_AreEq( |
| 2238 | + CRef, self._context.get_context_ref() |
| 2239 | + ) |
| 2240 | + DPCTLContext_Delete(CRef) |
| 2241 | + if not is_default_ctx: |
| 2242 | + raise pickle.PicklingError( |
| 2243 | + f"Cannot pickle {self!r}: its context is not the default " |
| 2244 | + "context of its device" |
| 2245 | + ) |
2227 | 2246 | props = [] |
2228 | 2247 | if DPCTLQueue_IsInOrder(self._queue_ref): |
2229 | 2248 | props.append("in_order") |
|
0 commit comments