From 012d45da8b53aa0e1e64899d5f9fc34f8f40119a Mon Sep 17 00:00:00 2001 From: zyfncg <1370305206@qq.com> Date: Wed, 9 Feb 2022 20:50:55 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E3=80=90Pten=E3=80=91Adjust=20the=20?= =?UTF-8?q?Empyt=20dev=5Fapi=20(#39143)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 9d4d0c3b5b7e2f4699f2d9f2304f4189a9df77d2. --- paddle/pten/kernels/empty_kernel.h | 10 +++++----- paddle/pten/kernels/funcs/elementwise_base.h | 2 +- .../kernels/sparse/cpu/sparse_utils_kernel.cc | 12 ++++++++---- .../kernels/sparse/gpu/sparse_utils_kernel.cu | 17 +++++++++++------ 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/paddle/pten/kernels/empty_kernel.h b/paddle/pten/kernels/empty_kernel.h index 98f7e03d771..8a7da8fbd56 100644 --- a/paddle/pten/kernels/empty_kernel.h +++ b/paddle/pten/kernels/empty_kernel.h @@ -32,7 +32,7 @@ void EmptyLikeKernel(const Context& dev_ctx, DenseTensor* out); // TODO(chenweihang): the tensor creation method need to be replaced later, // all kernel api call Empty here instead of making tensor self -template +template DenseTensor Empty(const Context& dev_ctx, DenseTensorMeta&& meta) { pten::DenseTensor dense_out( pten::make_intrusive( @@ -43,10 +43,10 @@ DenseTensor Empty(const Context& dev_ctx, DenseTensorMeta&& meta) { template DenseTensor Empty(const Context& dev_ctx) { - return Empty(dev_ctx, - {paddle::experimental::CppTypeToDataType::Type(), - {-1}, - DataLayout::NCHW}); + return Empty(dev_ctx, + {paddle::experimental::CppTypeToDataType::Type(), + {-1}, + DataLayout::NCHW}); } template diff --git a/paddle/pten/kernels/funcs/elementwise_base.h b/paddle/pten/kernels/funcs/elementwise_base.h index 0f26f3d8aa6..21abf82c7b2 100644 --- a/paddle/pten/kernels/funcs/elementwise_base.h +++ b/paddle/pten/kernels/funcs/elementwise_base.h @@ -392,7 +392,7 @@ static inline void GetDoubleGradSafeTensor(const DeviceContext &dev_ctx, *ddx_safe = *ddx; } else { auto meta = pten::DenseTensorMeta(x.dtype(), x.dims(), x.layout()); - *ddx_safe = pten::Empty(dev_ctx, std::move(meta)); + *ddx_safe = pten::Empty(dev_ctx, std::move(meta)); ddx_safe->mutable_data(dev_ctx.GetPlace()); paddle::operators::math::SetConstant set_zero; set_zero(dev_ctx, ddx_safe, static_cast(0)); diff --git a/paddle/pten/kernels/sparse/cpu/sparse_utils_kernel.cc b/paddle/pten/kernels/sparse/cpu/sparse_utils_kernel.cc index a86804e25dc..de648f76c1b 100644 --- a/paddle/pten/kernels/sparse/cpu/sparse_utils_kernel.cc +++ b/paddle/pten/kernels/sparse/cpu/sparse_utils_kernel.cc @@ -76,8 +76,10 @@ void DenseToSparseCooKernel(const Context& dev_ctx, {sparse_dim, static_cast(non_zero_num)}, DataLayout::NCHW); DenseTensorMeta values_meta(x.meta().dtype, values_dims, x.meta().layout); - pten::DenseTensor indices = pten::Empty(dev_ctx, std::move(indices_meta)); - pten::DenseTensor values = pten::Empty(dev_ctx, std::move(values_meta)); + pten::DenseTensor indices = + pten::Empty(dev_ctx, std::move(indices_meta)); + pten::DenseTensor values = + pten::Empty(dev_ctx, std::move(values_meta)); int64_t* indices_data = indices.mutable_data(place); T* values_data = values.mutable_data(place); @@ -121,8 +123,10 @@ void SparseCsrToCooKernel(const Context& dev_ctx, DenseTensorMeta indices_meta( DataType::INT64, {sparse_dim, non_zero_num}, DataLayout::NCHW); DenseTensorMeta values_meta(x.dtype(), {non_zero_num}, x.layout()); - pten::DenseTensor indices = pten::Empty(dev_ctx, std::move(indices_meta)); - pten::DenseTensor values = pten::Empty(dev_ctx, std::move(values_meta)); + pten::DenseTensor indices = + pten::Empty(dev_ctx, std::move(indices_meta)); + pten::DenseTensor values = + pten::Empty(dev_ctx, std::move(values_meta)); int64_t* coo_indices = indices.mutable_data(place); int64_t* batch_ptr = x_dims.size() == 2 ? nullptr : coo_indices; int64_t* coo_rows_data = diff --git a/paddle/pten/kernels/sparse/gpu/sparse_utils_kernel.cu b/paddle/pten/kernels/sparse/gpu/sparse_utils_kernel.cu index cd3124bd02f..cb8e3075310 100644 --- a/paddle/pten/kernels/sparse/gpu/sparse_utils_kernel.cu +++ b/paddle/pten/kernels/sparse/gpu/sparse_utils_kernel.cu @@ -111,12 +111,14 @@ void DenseToSparseCooKernel(const Context& dev_ctx, const int cols = dims_2d[1]; auto nums_meta = pten::DenseTensorMeta(DataType::INT32, {1}, pten::DataLayout::NCHW); - DenseTensor nums = pten::Empty(dev_ctx, std::move(nums_meta)); + DenseTensor nums = + pten::Empty(dev_ctx, std::move(nums_meta)); auto x_dims_meta = pten::DenseTensorMeta(DataType::INT64, {static_cast(x_dims.size())}, pten::DataLayout::NCHW); - DenseTensor d_x_dims = pten::Empty(dev_ctx, std::move(x_dims_meta)); + DenseTensor d_x_dims = + pten::Empty(dev_ctx, std::move(x_dims_meta)); const auto place = dev_ctx.GetPlace(); @@ -134,7 +136,8 @@ void DenseToSparseCooKernel(const Context& dev_ctx, auto temp_indexs_meta = pten::DenseTensorMeta(DataType::INT32, {rows}, pten::DataLayout::NCHW); - DenseTensor temp_indexs = pten::Empty(dev_ctx, std::move(temp_indexs_meta)); + DenseTensor temp_indexs = + pten::Empty(dev_ctx, std::move(temp_indexs_meta)); int* temp_indexs_ptr = temp_indexs.mutable_data(place); GetNonZeroNums<<>>( x_data, rows, cols, nums_ptr, temp_indexs_ptr); @@ -266,9 +269,11 @@ void SparseCsrToCooKernel(const Context& dev_ctx, DataType::INT64, {sparse_dim, non_zero_num}, DataLayout::NCHW); DenseTensorMeta values_meta(x.dtype(), {non_zero_num}, x.layout()); DenseTensorMeta offsets_meta(DataType::INT32, {batchs}, DataLayout::NCHW); - DenseTensor indices = pten::Empty(dev_ctx, std::move(indices_meta)); - DenseTensor values = pten::Empty(dev_ctx, std::move(values_meta)); - DenseTensor offsets = pten::Empty(dev_ctx, std::move(offsets_meta)); + DenseTensor indices = + pten::Empty(dev_ctx, std::move(indices_meta)); + DenseTensor values = pten::Empty(dev_ctx, std::move(values_meta)); + DenseTensor offsets = + pten::Empty(dev_ctx, std::move(offsets_meta)); int64_t* coo_indices = indices.mutable_data(place); int64_t* batch_ptr = x_dims.size() == 2 ? nullptr : coo_indices; int64_t* coo_rows_data = -- GitLab