From 1b8689ac7acef71f621dde88d8b3d1da83e2d17a Mon Sep 17 00:00:00 2001 From: DesmonDay <908660116@qq.com> Date: Wed, 1 Feb 2023 12:51:59 +0000 Subject: [PATCH] add code --- paddle/fluid/framework/dlpack_tensor.cc | 3 +-- paddle/fluid/framework/dlpack_tensor.h | 1 - paddle/fluid/pybind/tensor.cc | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/framework/dlpack_tensor.cc b/paddle/fluid/framework/dlpack_tensor.cc index 419eb0e7fe8..e1131e4c6d9 100644 --- a/paddle/fluid/framework/dlpack_tensor.cc +++ b/paddle/fluid/framework/dlpack_tensor.cc @@ -188,6 +188,7 @@ DLPackTensor::DLPackTensor(phi::DenseTensor &tensor, LaneType lanes) { auto tensor = new DLManagedTensor; tensor->dl_tensor = t_; + tensor->manager_ctx = dt_; tensor->deleter = [](DLManagedTensor *arg) { phi::DenseTensor *tensor_ptr = @@ -200,8 +201,6 @@ DLPackTensor::DLPackTensor(phi::DenseTensor &tensor, LaneType lanes) { delete arg; }; - tensor->manager_ctx = dt_; - return tensor; } diff --git a/paddle/fluid/framework/dlpack_tensor.h b/paddle/fluid/framework/dlpack_tensor.h index 2fcd2511afb..10c38a956cf 100644 --- a/paddle/fluid/framework/dlpack_tensor.h +++ b/paddle/fluid/framework/dlpack_tensor.h @@ -42,7 +42,6 @@ class DLPackTensor { // The shape in DLTensor is defined as int64_t* // Add this member to make TVMTensor init without heap allocation ShapeType shape_[DDim::kMaxRank]; - phi::DenseTensor* dt_; }; diff --git a/paddle/fluid/pybind/tensor.cc b/paddle/fluid/pybind/tensor.cc index b58e697e695..8b020792b6e 100644 --- a/paddle/fluid/pybind/tensor.cc +++ b/paddle/fluid/pybind/tensor.cc @@ -473,9 +473,9 @@ void BindTensor(pybind11::module &m) { // NOLINT )DOC") .def("_to_dlpack", [](phi::DenseTensor &self) { - DLPackTensor dlpack_tensor(self, 1); pybind11::handle tensor_handle = pybind11::cast(&self); tensor_handle.inc_ref(); + DLPackTensor dlpack_tensor(self, 1); DLManagedTensor *dmt = dlpack_tensor.ToDLManagedTensor(); auto capsule = pybind11::capsule( static_cast(dmt), "dltensor", [](PyObject *ptr) { -- GitLab