Repository navigation
Support pickle and copy.deepcopy of dpnp.ndarray - #3142
antonwolfy wants to merge 1 commit into
Conversation
Both failed with "no default __reduce__ due to non-trivial __cinit__" because a SYCL queue can't be pickled. `__reduce__` copies the data to the host and pickles it with the array type and the USM type; unpickling allocates the array on the default device, keeping the USM type, the dtype (raising on a device that doesn't support it), the C/F layout and the subclass. `__deepcopy__` copies on the array's own queue, like `__copy__`, so a deep copy doesn't go through `__reduce__` to the default device. Enable the matching CuPy tests and update `test_pickle` in `test_npz.py` to its current upstream version.
|
View rendered docs @ https://intelpython.github.io/dpnp/pull/3142/index.html |
|
Array API standard conformance tests for dpnp=0.22.0dev0=np2py314h8d9cdd5_7 ran successfully. |
|
@antonwolfy |
|
@ndgrigorian Comparing to CuPy, they seem also supporting only the default device. |
I think this sounds reasonable, if the dpctl PR ends up open soon (which it may be) we can rework this one slightly |
|
IntelPython/dpctl#2406 is now open |
pickle.dumps(a)andcopy.deepcopy(a)failed on anydpnp.ndarraywithTypeError: no default __reduce__ due to non-trivial __cinit__. The default pickling tries to serialize the underlyingusm_ndarraytogether with its SYCL queue, and a SYCL queue can't be pickled.Closes #2602.
How pickling works (
__reduce__):asnumpy(order="A")and pickled together with the array type and the USM type. The SYCL queue isn't pickled.ONEAPI_DEVICE_SELECTOR.ValueErroron a device that doesn't support it, e.g.float64on a device without fp64, instead of silently downcasting tofloat32asdpnp.asarraywould.dpnp.ndarrayare preserved.copy.deepcopy(__deepcopy__) behaves likecopy.copy: it returnsa.copy(order="K")on the array's own queue, with no host round trip. It has to be defined explicitly; otherwisecopy.deepcopywould go through__reduce__and move the array to the default device.Docs:
ndarray.__reduce__is now listed indoc/reference/ndarray.rst.