dpctl icon indicating copy to clipboard operation
dpctl copied to clipboard

Feature request: make SyclQueue picklable

Open olegkkruglov opened this issue 1 year ago • 2 comments

Currently SyclQueue is not picklable. The error message is the following:

File "<stringsource>", line 2, in dpctl._sycl_queue.SyclQueue.__reduce_cython__
TypeError: no default __reduce__ due to non-trivial __cinit__

The queue is used for dispatching in scikit-learn-intelex and the fact that it is unpickleable prevents classes with SyclQueue type attribute from being pickleable.

olegkkruglov avatar Jun 19 '24 20:06 olegkkruglov

@olegkkruglov Unfortunately this can not be done since sycl::queue C++ class itself can not be serialized (i.e. pickled). It is a stateful object whose state can not be saved and recreated as far as I am aware.

oleksandr-pavlyk avatar Jul 25 '24 13:07 oleksandr-pavlyk

@oleksandr-pavlyk but how then MemoryUSMDevice is picklable if it has SyclQueue as its attribute?

Pickling of USM allocation occurs by copying data from device to host and recording the USM type. The information about the device is lost (at present), and restoring to the default-selected device:

In [1]: import dpctl.tensor as dpt

In [2]: import pickle

In [3]: x = dpt.linspace(0, 1, num=30, device="cpu")

In [4]: m = x.usm_data

In [5]: m_roundtrip = pickle.loads(pickle.dumps(m))

In [6]: m.sycl_device
Out[6]: <dpctl.SyclDevice [backend_type.opencl, device_type.cpu,  11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz] at 0x7f2ded29b5f0>

In [7]: m_roundtrip.sycl_device
Out[7]: <dpctl.SyclDevice [backend_type.level_zero, device_type.gpu,  Intel(R) Graphics [0x9a49]] at 0x7f2de44ab430>

The queue associated with the round-tripped memory object is the cached queue corresponding to the default-selected device.

Pickling of dpctl.tensor.usm_ndarray is not supported at all yet.

olegkkruglov avatar Jul 25 '24 14:07 olegkkruglov