From 48ec02f1efcf5915711e095cbc2112a41ccec2ea Mon Sep 17 00:00:00 2001 From: Siming Dai <908660116@qq.com> Date: Mon, 13 Sep 2021 11:07:11 +0800 Subject: [PATCH] Add public api for dlpack. (#35620) --- python/paddle/utils/dlpack.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/python/paddle/utils/dlpack.py b/python/paddle/utils/dlpack.py index d3a7e7918f7..ca2a1ae0e19 100644 --- a/python/paddle/utils/dlpack.py +++ b/python/paddle/utils/dlpack.py @@ -17,6 +17,11 @@ from ..fluid.core import LoDTensor from ..fluid.framework import in_dygraph_mode from ..fluid.data_feeder import check_type, check_dtype, convert_dtype +__all__ = [ + 'to_dlpack', + 'from_dlpack', +] + def to_dlpack(x): """ @@ -63,7 +68,8 @@ def to_dlpack(x): def from_dlpack(dlpack): - """Decodes a DLPack to a tensor. + """ + Decodes a DLPack to a tensor. Args: dlpack (PyCapsule): a PyCapsule object with the dltensor. @@ -82,8 +88,8 @@ def from_dlpack(dlpack): x = paddle.utils.dlpack.from_dlpack(dlpack) print(x) # Tensor(shape=[2, 4], dtype=float32, place=CUDAPlace(0), stop_gradient=True, - [[0.20000000, 0.30000001, 0.50000000, 0.89999998], - [0.10000000, 0.20000000, 0.60000002, 0.69999999]]) + # [[0.20000000, 0.30000001, 0.50000000, 0.89999998], + # [0.10000000, 0.20000000, 0.60000002, 0.69999999]]) """ t = type(dlpack) -- GitLab