cupy.fromDlpack#

cupy.fromDlpack(dltensor) ndarray#

Zero-copy conversion from a DLPack tensor to a ndarray.

DLPack is a open in memory tensor structure proposed in this repository: dmlc/dlpack.

This function takes a PyCapsule object which contains a pointer to a DLPack tensor as input, and returns a ndarray. This function does not copy the data in the DLPack tensor but both DLPack tensor and ndarray have pointers which are pointing to the same memory region for the data.

Parameters:

dltensor (PyCapsule) – Input DLPack tensor which is encapsulated in a PyCapsule object.

Returns:

A CuPy ndarray.

Return type:

array (ndarray)

Warning

This function is deprecated in favor of from_dlpack() and will be removed in a future version of CuPy.

Warning

As of the DLPack v0.5 specification, it is implicitly assumed that the user is responsible to ensure the Producer and the Consumer are operating on the same stream.

See also

cupy.ndarray.toDlpack() is a method for zero-copy conversion from a ndarray to a DLPack tensor (which is encapsulated in a PyCapsule object).

Example

>>> import cupy
>>> array1 = cupy.array([0, 1, 2], dtype=cupy.float32)
>>> dltensor = array1.toDlpack()
>>> array2 = cupy.fromDlpack(dltensor)
>>> cupy.testing.assert_array_equal(array1, array2)