From 5610c1717eb9fb92d05121d957edb9629bd203c0 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Mon, 1 Mar 2021 14:58:24 +0800 Subject: [PATCH] fix dtype unmatched (#31305) --- paddle/fluid/extension/include/ext_tensor.h | 4 ++-- paddle/fluid/extension/src/ext_tensor.cc | 6 +++--- paddle/fluid/framework/custom_tensor_test.cc | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/paddle/fluid/extension/include/ext_tensor.h b/paddle/fluid/extension/include/ext_tensor.h index 77d4ec36e5..be492a6d55 100644 --- a/paddle/fluid/extension/include/ext_tensor.h +++ b/paddle/fluid/extension/include/ext_tensor.h @@ -57,7 +57,7 @@ class PD_DLL_DECL Tensor { /// Reshape must be called before calling /// mutable_data() or copy_to(const PlaceType& place) /// \param shape The shape to set. - void reshape(const std::vector& shape); + void reshape(const std::vector& shape); /// \brief Get the memory pointer in CPU or GPU with /// specific data type. @@ -90,7 +90,7 @@ class PD_DLL_DECL Tensor { Tensor copy_to(const PlaceType& place) const; /// \brief Return the shape of the Tensor. - std::vector shape() const; + std::vector shape() const; /// \brief Return the data type of the tensor. /// It's usually used to get the output tensor data type. diff --git a/paddle/fluid/extension/src/ext_tensor.cc b/paddle/fluid/extension/src/ext_tensor.cc index 88c2050bc8..4434a3bf59 100644 --- a/paddle/fluid/extension/src/ext_tensor.cc +++ b/paddle/fluid/extension/src/ext_tensor.cc @@ -95,7 +95,7 @@ void GpuCopy(T *src, T *dst, PlaceType src_plc, PlaceType dst_plc, } \ auto *tensor = static_cast(tensor_.get()); -void Tensor::reshape(const std::vector &shape) { +void Tensor::reshape(const std::vector &shape) { GET_CASTED_TENSOR tensor->Resize(framework::make_ddim(shape)); } @@ -251,9 +251,9 @@ template PD_DLL_DECL int16_t *Tensor::mutable_data( const PlaceType &place); template PD_DLL_DECL bool *Tensor::mutable_data(const PlaceType &place); -std::vector Tensor::shape() const { +std::vector Tensor::shape() const { GET_CASTED_TENSOR - return framework::vectorize(tensor->dims()); + return framework::vectorize(tensor->dims()); } const PlaceType &Tensor::place() const { diff --git a/paddle/fluid/framework/custom_tensor_test.cc b/paddle/fluid/framework/custom_tensor_test.cc index b891975b96..2e42248f64 100644 --- a/paddle/fluid/framework/custom_tensor_test.cc +++ b/paddle/fluid/framework/custom_tensor_test.cc @@ -20,7 +20,7 @@ template paddle::Tensor InitCPUTensorForTest() { - std::vector tensor_shape{5, 5}; + std::vector tensor_shape{5, 5}; auto t1 = paddle::Tensor(paddle::PlaceType::kCPU); t1.reshape(tensor_shape); auto* p_data_ptr = t1.mutable_data(paddle::PlaceType::kCPU); @@ -54,7 +54,7 @@ void TestCopyTensor() { } void TestAPIPlace() { - std::vector tensor_shape = {5, 5}; + std::vector tensor_shape = {5, 5}; #ifdef PADDLE_WITH_CUDA auto t1 = paddle::Tensor(paddle::PlaceType::kGPU); t1.reshape(tensor_shape); @@ -68,7 +68,7 @@ void TestAPIPlace() { } void TestAPISizeAndShape() { - std::vector tensor_shape = {5, 5}; + std::vector tensor_shape = {5, 5}; auto t1 = paddle::Tensor(paddle::PlaceType::kCPU); t1.reshape(tensor_shape); CHECK_EQ(t1.size(), 25); @@ -77,7 +77,7 @@ void TestAPISizeAndShape() { template paddle::DataType TestDtype() { - std::vector tensor_shape = {5, 5}; + std::vector tensor_shape = {5, 5}; auto t1 = paddle::Tensor(paddle::PlaceType::kCPU); t1.reshape(tensor_shape); t1.template mutable_data(); @@ -86,7 +86,7 @@ paddle::DataType TestDtype() { template void TestCast(paddle::DataType data_type) { - std::vector tensor_shape = {5, 5}; + std::vector tensor_shape = {5, 5}; auto t1 = paddle::Tensor(paddle::PlaceType::kCPU); t1.reshape(tensor_shape); t1.template mutable_data(); -- GitLab