Skip to content

Commit 91391cf

Browse files
committed
Implement __usm_ndarray__ protocol
1 parent ce3ef5e commit 91391cf

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

dpnp/dpnp_array.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,25 @@ def __truediv__(self, other):
612612
"""Return ``self/value``."""
613613
return dpnp.true_divide(self, other)
614614

615+
@property
616+
def __usm_ndarray__(self):
617+
"""
618+
Property to support `__usm_ndarray__` protocol.
619+
620+
It assumes to return :class:`dpctl.tensor.usm_ndarray` instance
621+
corresponding to the content of the object.
622+
623+
This property is intended to speed-up conversion from
624+
:class:`dpnp.ndarray` to :class:`dpctl.tensor.usm_ndarray` passed
625+
into `dpctl.tensor.asarray` function. The input object that implements
626+
`__usm_ndarray__` protocol is recognized as owner of USM allocation
627+
that is managed by a smart pointer, and asynchronous deallocation
628+
will not involve GIL.
629+
630+
"""
631+
632+
return self._array_obj
633+
615634
def __xor__(self, other):
616635
"""Return ``self^value``."""
617636
return dpnp.bitwise_xor(self, other)

0 commit comments

Comments
 (0)