dpnp
dpnp copied to clipboard
Follow ```__sycl_usm_array_interface__``` standard in ```asarray```
As of now, arrays which present the __sycl_usm_array_interface__ analogous to the numpy __array__ interface are copied, which is not the case in dpctl. This is problematic for scikit-learn-intelex, and ideally dpnp should out-of-the-box support implementations of this standard. It would be nice if a check was added in asarray to directly convert objects with that interface to dpt tensors for consumption by dpnp.
https://intelpython.github.io/dpctl/latest/api_reference/dpctl/sycl_usm_array_interface.html
@icfaust, dpnp already support __sycl_usm_array_interface__ interface and no copy should be done:
import dpnp, numpy, dpctl, dpctl.tensor as dpt
mobj = dpctl.memory.MemoryUSMShared(numpy.int64(10))
hasattr(mobj, "__sycl_usm_array_interface__")
# Out: True
a = dpt.asarray(mobj)
a.__sycl_usm_array_interface__
# Out:
# {'data': (102566846842880, True),
# 'shape': (10,),
# 'strides': None,
# 'typestr': '|u1',
# 'version': 1,
# 'syclobj': <dpctl.SyclQueue at 0x781153f80580>,
# 'offset': 0}
mobj.__sycl_usm_array_interface__
# Out:
# {'data': (102566846842880, True),
# 'shape': (10,),
# 'strides': None,
# 'typestr': '|u1',
# 'version': 1,
# 'syclobj': <dpctl.SyclQueue at 0x781153f80580>}
b = dpnp.asarray(mobj)
b.__sycl_usm_array_interface__
# Out[9]:
# {'data': (102566846842880, True),
# 'shape': (10,),
# 'strides': None,
# 'typestr': '|u1',
# 'version': 1,
# 'syclobj': <dpctl.SyclQueue at 0x781153f80580>,
# 'offset': 0}
Could you please share an example which does not work?