to_dlpack¶
- paddle.utils.dlpack. to_dlpack ( x ) [source]
-
Encodes a tensor to DLPack.
- Parameters
-
x (Tensor) – The input tensor, and the data type can be bool, float16, float32, float64, int8, int16, int32, int64, uint8, complex64, complex128.
- Returns
-
dltensor, and the data type is PyCapsule.
Examples
>>> import paddle >>> # x is a tensor with shape [2, 4] >>> x = paddle.to_tensor([[0.2, 0.3, 0.5, 0.9], ... [0.1, 0.2, 0.6, 0.7]]) >>> dlpack = paddle.utils.dlpack.to_dlpack(x) >>> print(dlpack) >>> <capsule object "dltensor" at 0x7f6103c681b0>