dpnp icon indicating copy to clipboard operation
dpnp copied to clipboard

Follow ```__sycl_usm_array_interface__``` standard in ```asarray```

Open icfaust opened this issue 5 months ago • 1 comments

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 avatar Aug 06 '25 14:08 icfaust

@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?

antonwolfy avatar Sep 01 '25 10:09 antonwolfy