From dd9909819dd1683d78cb13dc8249f6f671d95aff Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Sat, 29 Jan 2022 14:55:58 +0800 Subject: [PATCH] [PTen] Tidy pten core headers (#39188) * open header for custom kernel * add core utils * tidy core code * tify header * tidy include * tidy namespace * resolve conflit * fix unittest and coverage * remove platform using * resolve conflict * resolve conflict * fix digamma namespace error * fix xpu full kernel error * fix xpu full kernel error * polish details * add place for lib storage --- paddle/fluid/eager/eager_tensor.h | 2 +- paddle/fluid/framework/custom_kernel.cc | 2 +- paddle/fluid/framework/custom_operator.cc | 2 +- paddle/fluid/framework/dim.h | 2 +- paddle/fluid/framework/infershape_utils.cc | 21 ++-- paddle/fluid/framework/pten_utils.cc | 2 +- paddle/fluid/framework/tensor.cc | 1 - paddle/fluid/framework/type_defs.h | 2 +- paddle/fluid/imperative/type_defs.h | 2 +- .../elementwise/elementwise_functor.h | 2 +- paddle/fluid/operators/roll_op.cu | 2 +- paddle/fluid/pybind/eager.cc | 2 +- paddle/fluid/pybind/eager_functions.cc | 2 +- paddle/fluid/pybind/eager_method.cc | 2 +- paddle/fluid/pybind/eager_properties.cc | 2 +- paddle/fluid/pybind/eager_utils.cc | 2 +- paddle/pten/api/lib/api_utils.h | 2 +- paddle/pten/api/lib/kernel_dispatch.cc | 2 +- paddle/pten/api/lib/tensor.cc | 12 +- paddle/pten/api/lib/utils/storage.h | 18 ++- paddle/pten/api/lib/utils/tensor_utils.cc | 4 +- paddle/pten/api/lib/utils/tensor_utils.h | 2 +- paddle/pten/core/CMakeLists.txt | 21 +--- paddle/pten/core/allocator.h | 6 +- paddle/pten/core/compat/CMakeLists.txt | 7 ++ paddle/pten/core/compat/arg_map_context.cc | 2 +- .../pten/core/{ => compat}/convert_utils.cc | 27 +--- paddle/pten/core/{ => compat}/convert_utils.h | 13 +- .../core/{ => compat}/kernel_alias_name.h | 0 paddle/pten/core/compat/op_utils.h | 13 +- paddle/pten/core/compat/type_defs.h | 96 ++++++++++++++ paddle/pten/core/ddim.cc | 66 +++++----- paddle/pten/core/ddim.h | 14 +-- paddle/pten/core/dense_tensor.cc | 6 +- paddle/pten/core/dense_tensor.h | 27 ++-- paddle/pten/core/dense_tensor_impl.cc | 3 +- paddle/pten/core/enforce.h | 2 +- paddle/pten/core/infermeta_utils.h | 2 +- paddle/pten/core/kernel_context.h | 12 +- paddle/pten/core/kernel_def.h | 38 ------ paddle/pten/core/kernel_factory.h | 6 +- paddle/pten/core/kernel_registry.h | 2 +- paddle/pten/core/kernel_utils.h | 6 +- paddle/pten/core/lod_utils.cc | 4 +- paddle/pten/core/meta_tensor.cc | 21 ++-- paddle/pten/core/meta_tensor.h | 4 +- paddle/pten/core/storage.h | 31 ++--- paddle/pten/core/tensor_base.h | 6 +- paddle/pten/core/tensor_meta.h | 2 - .../core/{compat_utils.h => tensor_utils.h} | 18 +-- paddle/pten/core/type_defs.h | 118 +++++------------- paddle/pten/core/{ => utils}/array.h | 15 ++- paddle/pten/core/{ => utils}/dim.h | 2 +- paddle/pten/core/utils/rw_lock.h | 26 ++-- .../pten/core/{ => utils}/unroll_array_ops.h | 0 paddle/pten/infermeta/unary.cc | 2 + paddle/pten/kernels/cpu/copy_kernel.cc | 2 +- paddle/pten/kernels/gpu/copy_kernel.cu | 2 +- paddle/pten/kernels/gpu/math_kernel.cu | 2 +- paddle/pten/kernels/gpu/reduce.h | 7 +- .../kernels/impl/digamma_grad_kernel_impl.h | 2 +- .../pten/kernels/impl/digamma_kernel_impl.h | 2 +- paddle/pten/kernels/math_kernel.h | 1 - paddle/pten/kernels/xpu/cast_kernel.cc | 14 ++- paddle/pten/kernels/xpu/copy_kernel.cc | 2 +- paddle/pten/kernels/xpu/full_kernel.cc | 18 ++- paddle/pten/kernels/xpu/scale_kernel.cc | 2 +- paddle/pten/tests/api/test_cast_api.cc | 2 +- paddle/pten/tests/api/test_concat_api.cc | 7 +- paddle/pten/tests/api/test_conj_api.cc | 2 +- paddle/pten/tests/api/test_dot_api.cc | 4 +- paddle/pten/tests/api/test_elementwise_api.cc | 16 +-- paddle/pten/tests/api/test_empty_api.cc | 6 +- paddle/pten/tests/api/test_fill_api.cc | 12 +- paddle/pten/tests/api/test_flatten_api.cc | 2 +- paddle/pten/tests/api/test_matmul_api.cc | 12 +- paddle/pten/tests/api/test_mean_api.cc | 2 +- paddle/pten/tests/api/test_reshape_api.cc | 2 +- paddle/pten/tests/api/test_sum_api.cc | 2 +- paddle/pten/tests/api/test_to_api.cc | 2 +- paddle/pten/tests/core/CMakeLists.txt | 2 + paddle/pten/tests/core/test_convert_utils.cc | 2 +- paddle/pten/tests/core/test_device_context.cc | 10 +- paddle/pten/tests/core/test_dim.cu | 4 +- .../{ => tests}/core/unroll_array_ops_test.cc | 4 +- .../pten/tests/kernels/test_cast_dev_api.cc | 9 +- .../pten/tests/kernels/test_concat_dev_api.cc | 18 +-- .../pten/tests/kernels/test_conj_dev_api.cc | 9 +- .../pten/tests/kernels/test_copy_dev_api.cc | 4 +- .../tests/kernels/test_creation_dev_api.cc | 18 +-- paddle/pten/tests/kernels/test_dot_dev_api.cc | 18 +-- .../tests/kernels/test_elementwise_dev_api.cc | 72 ++++++----- .../tests/kernels/test_flatten_dev_api.cc | 2 +- .../pten/tests/kernels/test_matmul_dev_api.cc | 4 +- .../pten/tests/kernels/test_mean_dev_api.cc | 9 +- .../tests/kernels/test_reshape_dev_api.cc | 2 +- .../pten/tests/kernels/test_scale_dev_api.cc | 20 +-- paddle/pten/tests/kernels/test_sum_dev_api.cc | 9 +- python/setup.py.in | 8 +- 99 files changed, 505 insertions(+), 552 deletions(-) rename paddle/pten/core/{ => compat}/convert_utils.cc (93%) rename paddle/pten/core/{ => compat}/convert_utils.h (75%) rename paddle/pten/core/{ => compat}/kernel_alias_name.h (100%) create mode 100644 paddle/pten/core/compat/type_defs.h delete mode 100644 paddle/pten/core/kernel_def.h rename paddle/pten/core/{compat_utils.h => tensor_utils.h} (81%) rename paddle/pten/core/{ => utils}/array.h (88%) rename paddle/pten/core/{ => utils}/dim.h (98%) rename paddle/pten/core/{ => utils}/unroll_array_ops.h (100%) rename paddle/pten/{ => tests}/core/unroll_array_ops_test.cc (96%) diff --git a/paddle/fluid/eager/eager_tensor.h b/paddle/fluid/eager/eager_tensor.h index 4383cf0fcf..fafdf9b65b 100644 --- a/paddle/fluid/eager/eager_tensor.h +++ b/paddle/fluid/eager/eager_tensor.h @@ -21,7 +21,7 @@ #include "paddle/pten/api/all.h" #include "paddle/pten/api/lib/api_declare.h" #include "paddle/pten/api/lib/utils/tensor_utils.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" /** * This class is used by Eager mode for now. It's painful to do this in Eager * Mode, the better diff --git a/paddle/fluid/framework/custom_kernel.cc b/paddle/fluid/framework/custom_kernel.cc index a549862394..1ba7c4481e 100644 --- a/paddle/fluid/framework/custom_kernel.cc +++ b/paddle/fluid/framework/custom_kernel.cc @@ -25,7 +25,7 @@ limitations under the License. */ #include "paddle/fluid/framework/operator.h" #include "paddle/fluid/platform/enforce.h" #include "paddle/pten/api/ext/op_kernel_info.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/kernel_context.h" #include "paddle/pten/core/kernel_registry.h" diff --git a/paddle/fluid/framework/custom_operator.cc b/paddle/fluid/framework/custom_operator.cc index 0fa1d1f8cb..35b6b91893 100644 --- a/paddle/fluid/framework/custom_operator.cc +++ b/paddle/fluid/framework/custom_operator.cc @@ -37,7 +37,7 @@ limitations under the License. */ #include "paddle/pten/api/lib/api_declare.h" #include "paddle/pten/api/lib/ext_compat_utils.h" #include "paddle/pten/api/lib/utils/tensor_utils.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/utils/any.h" namespace paddle { diff --git a/paddle/fluid/framework/dim.h b/paddle/fluid/framework/dim.h index 6abae4e731..21975485ad 100644 --- a/paddle/fluid/framework/dim.h +++ b/paddle/fluid/framework/dim.h @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. #pragma once -#include "paddle/pten/core/dim.h" +#include "paddle/pten/core/utils/dim.h" namespace paddle { namespace framework { diff --git a/paddle/fluid/framework/infershape_utils.cc b/paddle/fluid/framework/infershape_utils.cc index 52c0aa003e..80787c3b87 100644 --- a/paddle/fluid/framework/infershape_utils.cc +++ b/paddle/fluid/framework/infershape_utils.cc @@ -18,12 +18,12 @@ limitations under the License. */ #include "paddle/fluid/framework/pten_utils.h" #include "paddle/fluid/platform/enforce.h" #include "paddle/pten/core/compat/arg_map_context.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/compat/op_utils.h" -#include "paddle/pten/core/compat_utils.h" -#include "paddle/pten/core/convert_utils.h" #include "paddle/pten/core/dense_tensor.h" #include "paddle/pten/core/infermeta_utils.h" #include "paddle/pten/core/meta_tensor.h" +#include "paddle/pten/core/tensor_utils.h" namespace paddle { namespace framework { @@ -126,8 +126,9 @@ class CompatMetaTensor : public pten::MetaTensor { auto* var = BOOST_GET_CONST(Variable*, var_); return var->Get().layout(); } else { - PADDLE_THROW(platform::errors::Unimplemented( - "Unsupported get layout for VarDesc now.")); + // NOTE(chenweihang): do nothing + // Unsupported get layout for VarDesc now + return DataLayout::UNDEFINED; } } @@ -135,7 +136,7 @@ class CompatMetaTensor : public pten::MetaTensor { if (is_runtime_) { auto* var = BOOST_GET(Variable*, var_); LoDTensor* tensor = var->GetMutable(); - pten::CompatibleDenseTensorUtils::GetMutableMeta( + pten::DenseTensorUtils::GetMutableMeta( static_cast(tensor)) ->dims = dims; } else { @@ -148,7 +149,7 @@ class CompatMetaTensor : public pten::MetaTensor { if (is_runtime_) { auto* var = BOOST_GET(Variable*, var_); LoDTensor* tensor = var->GetMutable(); - pten::CompatibleDenseTensorUtils::GetMutableMeta( + pten::DenseTensorUtils::GetMutableMeta( static_cast(tensor)) ->dtype = dtype; } else { @@ -161,12 +162,12 @@ class CompatMetaTensor : public pten::MetaTensor { if (is_runtime_) { auto* var = BOOST_GET(Variable*, var_); LoDTensor* tensor = var->GetMutable(); - pten::CompatibleDenseTensorUtils::GetMutableMeta( + pten::DenseTensorUtils::GetMutableMeta( static_cast(tensor)) ->layout = layout; } else { - PADDLE_THROW(platform::errors::Unimplemented( - "Unsupported set layout for VarDesc now.")); + // NOTE(chenweihang): do nothing + // Unsupported set layout for VarDesc now } } @@ -174,7 +175,7 @@ class CompatMetaTensor : public pten::MetaTensor { if (is_runtime_) { auto* var = BOOST_GET(Variable*, var_); LoDTensor* tensor = var->GetMutable(); - pten::CompatibleDenseTensorUtils::GetMutableMeta( + pten::DenseTensorUtils::GetMutableMeta( static_cast(tensor)) ->lod = static_cast(meta_tensor).GetRuntimeLoD(); diff --git a/paddle/fluid/framework/pten_utils.cc b/paddle/fluid/framework/pten_utils.cc index 336f8423d6..afcee19c6f 100644 --- a/paddle/fluid/framework/pten_utils.cc +++ b/paddle/fluid/framework/pten_utils.cc @@ -15,8 +15,8 @@ limitations under the License. */ #include #include "paddle/fluid/framework/pten_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/compat/op_utils.h" -#include "paddle/pten/core/convert_utils.h" #include "paddle/pten/core/kernel_factory.h" #include "paddle/fluid/framework/lod_tensor.h" diff --git a/paddle/fluid/framework/tensor.cc b/paddle/fluid/framework/tensor.cc index bb8d7df745..2f0c7c5b2c 100644 --- a/paddle/fluid/framework/tensor.cc +++ b/paddle/fluid/framework/tensor.cc @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and limitations under the License. */ #include "paddle/fluid/framework/tensor.h" -#include "paddle/pten/api/lib/utils/storage.h" DECLARE_bool(use_stream_safe_cuda_allocator); diff --git a/paddle/fluid/framework/type_defs.h b/paddle/fluid/framework/type_defs.h index fe376a5669..5a13df783a 100644 --- a/paddle/fluid/framework/type_defs.h +++ b/paddle/fluid/framework/type_defs.h @@ -22,7 +22,7 @@ limitations under the License. */ #include #include #include "paddle/fluid/platform/variant.h" -#include "paddle/pten/core/type_defs.h" +#include "paddle/pten/core/compat/type_defs.h" #include "paddle/utils/small_vector.h" namespace paddle { diff --git a/paddle/fluid/imperative/type_defs.h b/paddle/fluid/imperative/type_defs.h index a0258c7a88..a248f29ee9 100644 --- a/paddle/fluid/imperative/type_defs.h +++ b/paddle/fluid/imperative/type_defs.h @@ -13,4 +13,4 @@ See the License for the specific language governing permissions and limitations under the License. */ #pragma once -#include "paddle/pten/core/type_defs.h" +#include "paddle/pten/core/compat/type_defs.h" diff --git a/paddle/fluid/operators/elementwise/elementwise_functor.h b/paddle/fluid/operators/elementwise/elementwise_functor.h index daca105ce4..19d3a6c385 100644 --- a/paddle/fluid/operators/elementwise/elementwise_functor.h +++ b/paddle/fluid/operators/elementwise/elementwise_functor.h @@ -15,7 +15,7 @@ limitations under the License. */ #pragma once #include "paddle/fluid/platform/complex.h" -#include "paddle/pten/core/array.h" +#include "paddle/pten/core/utils/array.h" #include "paddle/pten/kernels/funcs/elementwise_functor.h" namespace paddle { diff --git a/paddle/fluid/operators/roll_op.cu b/paddle/fluid/operators/roll_op.cu index 7e8e37bd2e..0f861179b2 100644 --- a/paddle/fluid/operators/roll_op.cu +++ b/paddle/fluid/operators/roll_op.cu @@ -17,7 +17,7 @@ #include "paddle/fluid/operators/roll_op.h" #include "paddle/fluid/platform/complex.h" #include "paddle/fluid/platform/device/gpu/gpu_primitives.h" -#include "paddle/pten/core/array.h" +#include "paddle/pten/core/utils/array.h" namespace paddle { namespace operators { diff --git a/paddle/fluid/pybind/eager.cc b/paddle/fluid/pybind/eager.cc index 0aacbe5e32..6ace815942 100644 --- a/paddle/fluid/pybind/eager.cc +++ b/paddle/fluid/pybind/eager.cc @@ -24,7 +24,7 @@ limitations under the License. */ #include "paddle/fluid/pybind/eager.h" #include "paddle/fluid/pybind/eager_utils.h" #include "paddle/pten/common/data_type.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/dense_tensor.h" #include "pybind11/detail/internals.h" #include "pybind11/numpy.h" diff --git a/paddle/fluid/pybind/eager_functions.cc b/paddle/fluid/pybind/eager_functions.cc index 44fc959383..a5167e9eba 100644 --- a/paddle/fluid/pybind/eager_functions.cc +++ b/paddle/fluid/pybind/eager_functions.cc @@ -32,7 +32,7 @@ limitations under the License. */ #include "paddle/pten/api/lib/utils/storage.h" #include "paddle/pten/api/lib/utils/tensor_utils.h" #include "paddle/pten/common/data_type.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/dense_tensor.h" namespace paddle { diff --git a/paddle/fluid/pybind/eager_method.cc b/paddle/fluid/pybind/eager_method.cc index 4835d8873a..414c60adf0 100644 --- a/paddle/fluid/pybind/eager_method.cc +++ b/paddle/fluid/pybind/eager_method.cc @@ -29,7 +29,7 @@ limitations under the License. */ #include "paddle/fluid/pybind/exception.h" #include "paddle/pten/api/include/api.h" #include "paddle/pten/common/data_type.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/dense_tensor.h" namespace paddle { namespace pybind { diff --git a/paddle/fluid/pybind/eager_properties.cc b/paddle/fluid/pybind/eager_properties.cc index 5f1d809168..d8dac3c628 100644 --- a/paddle/fluid/pybind/eager_properties.cc +++ b/paddle/fluid/pybind/eager_properties.cc @@ -26,7 +26,7 @@ limitations under the License. */ #include "paddle/fluid/pybind/eager_utils.h" #include "paddle/fluid/pybind/exception.h" #include "paddle/pten/common/data_type.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/dense_tensor.h" #pragma GCC diagnostic ignored "-Wwrite-strings" diff --git a/paddle/fluid/pybind/eager_utils.cc b/paddle/fluid/pybind/eager_utils.cc index 1e0697246e..0f21bd4ae3 100644 --- a/paddle/fluid/pybind/eager_utils.cc +++ b/paddle/fluid/pybind/eager_utils.cc @@ -24,7 +24,7 @@ limitations under the License. */ #include "paddle/fluid/pybind/op_function_common.h" #include "paddle/fluid/pybind/tensor_py.h" #include "paddle/pten/common/data_type.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/dense_tensor.h" namespace paddle { diff --git a/paddle/pten/api/lib/api_utils.h b/paddle/pten/api/lib/api_utils.h index f3e7d74db1..6332132fac 100644 --- a/paddle/pten/api/lib/api_utils.h +++ b/paddle/pten/api/lib/api_utils.h @@ -16,7 +16,7 @@ limitations under the License. */ #include "paddle/pten/api/include/tensor.h" #include "paddle/pten/api/lib/utils/storage.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/dense_tensor.h" namespace paddle { diff --git a/paddle/pten/api/lib/kernel_dispatch.cc b/paddle/pten/api/lib/kernel_dispatch.cc index 7930869632..831d01b7cf 100644 --- a/paddle/pten/api/lib/kernel_dispatch.cc +++ b/paddle/pten/api/lib/kernel_dispatch.cc @@ -14,7 +14,7 @@ limitations under the License. */ #include "paddle/pten/api/lib/kernel_dispatch.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" namespace paddle { namespace experimental { diff --git a/paddle/pten/api/lib/tensor.cc b/paddle/pten/api/lib/tensor.cc index 02fd918d79..5ab6e5e763 100644 --- a/paddle/pten/api/lib/tensor.cc +++ b/paddle/pten/api/lib/tensor.cc @@ -23,11 +23,11 @@ limitations under the License. */ #include "paddle/pten/api/lib/ext_compat_utils.h" #include "paddle/pten/api/lib/utils/allocator.h" #include "paddle/pten/api/lib/utils/storage.h" -#include "paddle/pten/core/compat_utils.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/dense_tensor.h" #include "paddle/pten/core/tensor_base.h" #include "paddle/pten/core/tensor_meta.h" +#include "paddle/pten/core/tensor_utils.h" /** * [ Why still include the fluid headers? ] @@ -77,7 +77,7 @@ Tensor::Tensor(const PlaceType &place) std::move(pten::make_intrusive( ConvertExtPlaceToInnerPlace(place))), std::move(pten::DenseTensorMeta(pten::DataType::UNDEFINED, - framework::make_ddim({}), + pten::framework::make_ddim({}), pten::DataLayout::NCHW))))), place_{place} {} @@ -86,7 +86,7 @@ Tensor::Tensor(const PlaceType &place, const std::vector &shape) std::move(pten::make_intrusive( ConvertExtPlaceToInnerPlace(place))), std::move(pten::DenseTensorMeta(pten::DataType::UNDEFINED, - framework::make_ddim(shape), + pten::framework::make_ddim(shape), pten::DataLayout::NCHW))))), place_{place} {} @@ -113,7 +113,7 @@ void Tensor::reshape(const std::vector &shape) { "the tensor to remain constant."; if (is_dense_tensor()) { std::dynamic_pointer_cast(impl_)->set_meta( - pten::DenseTensorMeta(dtype(), framework::make_ddim(shape))); + pten::DenseTensorMeta(dtype(), pten::framework::make_ddim(shape))); } else { PADDLE_THROW(pten::errors::Unimplemented( "Only support reshape operation on DenseTensor now.")); @@ -270,7 +270,7 @@ Tensor::data(); Tensor Tensor::slice(int64_t begin_idx, int64_t end_idx) const { if (is_dense_tensor()) { return Tensor(std::make_shared( - std::move(pten::CompatibleDenseTensorUtils::Slice( + std::move(pten::DenseTensorUtils::Slice( *(std::dynamic_pointer_cast(impl_).get()), begin_idx, end_idx)))); diff --git a/paddle/pten/api/lib/utils/storage.h b/paddle/pten/api/lib/utils/storage.h index a02e5d46a6..4e311135ee 100644 --- a/paddle/pten/api/lib/utils/storage.h +++ b/paddle/pten/api/lib/utils/storage.h @@ -22,7 +22,7 @@ namespace experimental { class ExternalStorage : public pten::Storage { public: - ExternalStorage(void* ptr, size_t size, const paddle::platform::Place& place); + ExternalStorage(void* ptr, size_t size, const pten::Place& place); ExternalStorage(const pten::intrusive_ptr& root, size_t delta, size_t size); @@ -52,7 +52,7 @@ class ExternalStorage : public pten::Storage { } size_t size() const noexcept override { return size_; } - const paddle::platform::Place& place() const override { + const pten::Place& place() const override { PADDLE_ENFORCE_NOT_NULL( data_, paddle::platform::errors::Unavailable( @@ -78,9 +78,7 @@ class SharedStorage : public pten::Storage { // In order to be compatible with the original Tensor design and execution // system, we need to allow the uninitialized SharedStorage to exist, // and it can be removed after the compatibility phase is over in the future - explicit SharedStorage(const paddle::platform::Place& place) { - place_ = place; - } + explicit SharedStorage(const pten::Place& place) { place_ = place; } void Realloc(size_t n) override { this->Clear(); @@ -106,14 +104,14 @@ class SharedStorage : public pten::Storage { std::shared_ptr&& move_data_shared() override { size_ = 0; - place_ = Place(); + place_ = pten::Place(); return std::move(data_); } size_t size() const noexcept override { return data_ ? data_->size() : size_; } - const paddle::platform::Place& place() const override { + const pten::Place& place() const override { return data_ ? data_->place() : place_; } bool OwnsMemory() const noexcept override { return false; } @@ -130,15 +128,13 @@ class SharedStorage : public pten::Storage { } // Temporary method: For compatible with fluid Tensor and improve performance - void ResetAllocationPlace(const paddle::platform::Place& place) { - place_ = place; - } + void ResetAllocationPlace(const pten::Place& place) { place_ = place; } // Temporary method: For compatible with fluid Tensor and improve performance void Reset() { this->Clear(); } private: - Place place_; + pten::Place place_; int64_t size_{0}; }; diff --git a/paddle/pten/api/lib/utils/tensor_utils.cc b/paddle/pten/api/lib/utils/tensor_utils.cc index 1289353a6c..8fdfc29540 100644 --- a/paddle/pten/api/lib/utils/tensor_utils.cc +++ b/paddle/pten/api/lib/utils/tensor_utils.cc @@ -17,7 +17,7 @@ limitations under the License. */ #include #include -#include "paddle/pten/core/compat_utils.h" +#include "paddle/pten/core/tensor_utils.h" namespace paddle { namespace experimental { @@ -201,7 +201,7 @@ pten::ScalarArray MakePtenScalarArrayFromVarList( void ResetTensorByArgDef(pten::DenseTensor* dst, const pten::TensorArgDef& arg_def) { VLOG(5) << "ResetTensor by TensorArgDef."; - auto* meta = pten::CompatibleDenseTensorUtils::GetMutableMeta(dst); + auto* meta = pten::DenseTensorUtils::GetMutableMeta(dst); meta->dtype = arg_def.dtype; meta->layout = arg_def.layout; } diff --git a/paddle/pten/api/lib/utils/tensor_utils.h b/paddle/pten/api/lib/utils/tensor_utils.h index bf8d9b8317..1ffcc7d4d5 100644 --- a/paddle/pten/api/lib/utils/tensor_utils.h +++ b/paddle/pten/api/lib/utils/tensor_utils.h @@ -23,7 +23,7 @@ limitations under the License. */ #include "paddle/pten/api/lib/utils/storage.h" #include "paddle/pten/common/scalar.h" #include "paddle/pten/common/scalar_array.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/dense_tensor.h" #include "paddle/pten/core/kernel_factory.h" diff --git a/paddle/pten/core/CMakeLists.txt b/paddle/pten/core/CMakeLists.txt index ab6a993197..46cd2a9641 100644 --- a/paddle/pten/core/CMakeLists.txt +++ b/paddle/pten/core/CMakeLists.txt @@ -1,14 +1,6 @@ -# utils used for compatible for fluid op system +# compatible utils used for fluid op system add_subdirectory(compat) -if(WITH_GPU) - cc_library(convert_utils SRCS convert_utils.cc DEPS data_type place gpu_info) -elseif(WITH_ROCM) - cc_library(convert_utils SRCS convert_utils.cc DEPS data_type place gpu_info) -else() - cc_library(convert_utils SRCS convert_utils.cc DEPS data_type place) -endif() - cc_library(errors SRCS errors.cc) set(pten_enforce_deps errors flags) if(WITH_GPU) @@ -19,21 +11,20 @@ cc_library(pten_enforce INTERFACE SRCS enforce.cc DEPS ${pten_enforce_deps}) cc_library(kernel_factory SRCS kernel_factory.cc DEPS pten_enforce convert_utils) cc_library(kernel_context SRCS kernel_context.cc DEPS pten_enforce pten_context) -cc_library(tensor_base SRCS tensor_base.cc allocator.cc storage.cc DEPS pten_enforce) +cc_library(ddim SRCS ddim.cc DEPS pten_enforce) +cc_library(tensor_base SRCS tensor_base.cc allocator.cc DEPS pten_enforce) cc_library(tensor_meta SRCS tensor_meta.cc DEPS pten_enforce mixed_vector) cc_library(lod_utils SRCS lod_utils.cc DEPS pten_enforce mixed_vector) + +cc_library(pten_device_context SRCS device_context.cc DEPS tensor_base) +cc_library(dense_tensor SRCS dense_tensor.cc dense_tensor_impl.cc DEPS convert_utils tensor_meta tensor_base) cc_library(sparse_coo_tensor SRCS sparse_coo_tensor.cc DEPS tensor_meta tensor_base) cc_library(sparse_csr_tensor SRCS sparse_csr_tensor.cc DEPS dense_tensor tensor_base) -cc_library(dense_tensor SRCS dense_tensor.cc dense_tensor_impl.cc DEPS convert_utils tensor_meta tensor_base) -cc_library(pten_device_context SRCS device_context.cc DEPS tensor_base ) cc_library(meta_tensor SRCS meta_tensor.cc DEPS tensor_base tensor_meta dense_tensor) cc_library(infermeta_utils SRCS infermeta_utils.cc DEPS meta_tensor) cc_library(selected_rows SRCS selected_rows.cc DEPS dense_tensor mixed_vector pten_enforce ddim) -cc_test(unroll_array_ops_test SRCS unroll_array_ops_test.cc) -cc_library(ddim SRCS ddim.cc DEPS eigen3 boost enforce) - # Will remove once we implemented MKLDNN_Tensor if(WITH_MKLDNN) add_dependencies(dense_tensor mkldnn) diff --git a/paddle/pten/core/allocator.h b/paddle/pten/core/allocator.h index 75d42c4fd1..098e5698de 100644 --- a/paddle/pten/core/allocator.h +++ b/paddle/pten/core/allocator.h @@ -16,7 +16,9 @@ limitations under the License. */ #include #include -#include "paddle/fluid/platform/place.h" +#include + +#include "paddle/pten/common/place.h" namespace pten { @@ -26,7 +28,7 @@ namespace pten { /// support being inherited. class Allocation { public: - using Place = paddle::platform::Place; + using Place = pten::Place; using DeleterFnPtr = void (*)(Allocation*); Allocation() = default; diff --git a/paddle/pten/core/compat/CMakeLists.txt b/paddle/pten/core/compat/CMakeLists.txt index 0c081edb81..f97d5cb9f6 100644 --- a/paddle/pten/core/compat/CMakeLists.txt +++ b/paddle/pten/core/compat/CMakeLists.txt @@ -1,2 +1,9 @@ cc_library(arg_map_context SRCS arg_map_context.cc DEPS pten_enforce) +if(WITH_GPU) + cc_library(convert_utils SRCS convert_utils.cc DEPS data_type place gpu_info) +elseif(WITH_ROCM) + cc_library(convert_utils SRCS convert_utils.cc DEPS data_type place gpu_info) +else() + cc_library(convert_utils SRCS convert_utils.cc DEPS data_type place) +endif() cc_library(op_utils SRCS op_utils.cc DEPS arg_map_context enforce convert_utils) diff --git a/paddle/pten/core/compat/arg_map_context.cc b/paddle/pten/core/compat/arg_map_context.cc index 73fa0b300c..b6b2bf6627 100644 --- a/paddle/pten/core/compat/arg_map_context.cc +++ b/paddle/pten/core/compat/arg_map_context.cc @@ -14,8 +14,8 @@ limitations under the License. */ #include "paddle/pten/core/compat/arg_map_context.h" -#include "paddle/fluid/string/string_helper.h" #include "paddle/pten/core/enforce.h" +#include "paddle/utils/string/string_helper.h" namespace pten { std::ostream& operator<<(std::ostream& os, KernelSignature signature) { diff --git a/paddle/pten/core/convert_utils.cc b/paddle/pten/core/compat/convert_utils.cc similarity index 93% rename from paddle/pten/core/convert_utils.cc rename to paddle/pten/core/compat/convert_utils.cc index 70184e31f7..a8170b6a93 100644 --- a/paddle/pten/core/convert_utils.cc +++ b/paddle/pten/core/compat/convert_utils.cc @@ -11,8 +11,11 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include "paddle/pten/core/convert_utils.h" -#include "paddle/pten/core/kernel_alias_name.h" + +#include "paddle/pten/core/compat/convert_utils.h" + +#include "paddle/pten/core/compat/kernel_alias_name.h" + // See Note [ Why still include the fluid headers? ] #include "paddle/fluid/platform/device/gpu/gpu_info.h" @@ -126,26 +129,6 @@ paddle::framework::proto::VarType::Type TransToProtoVarType( } } -paddle::framework::LoD TransToFluidLoD(const pten::LoD& lod) { - paddle::framework::LoD out; - out.reserve(lod.size()); - - for (auto& elem : lod) { - out.emplace_back(elem); - } - return out; -} - -pten::LoD TransToPtenLoD(const paddle::framework::LoD& lod) { - pten::LoD out; - out.reserve(lod.size()); - - for (auto& elem : lod) { - out.emplace_back(elem); - } - return out; -} - size_t DataTypeSize(DataType dtype) { switch (dtype) { case DataType::UNDEFINED: diff --git a/paddle/pten/core/convert_utils.h b/paddle/pten/core/compat/convert_utils.h similarity index 75% rename from paddle/pten/core/convert_utils.h rename to paddle/pten/core/compat/convert_utils.h index 9e33d37c4a..c67d051cad 100644 --- a/paddle/pten/core/convert_utils.h +++ b/paddle/pten/core/compat/convert_utils.h @@ -17,33 +17,26 @@ limitations under the License. */ #include "paddle/pten/common/backend.h" #include "paddle/pten/common/data_type.h" #include "paddle/pten/common/layout.h" +#include "paddle/pten/common/place.h" #include "paddle/pten/core/tensor_meta.h" // See Note [ Why still include the fluid headers? ] #include "paddle/fluid/framework/data_type.h" -#include "paddle/fluid/framework/lod_tensor.h" -#include "paddle/fluid/platform/place.h" // TODO(chenweihang): this file may need to be removed namespace pten { -using DataType = paddle::experimental::DataType; -using DataLayout = paddle::experimental::DataLayout; - const std::string& TransToPtenKernelName(const std::string& fluid_op_name); -Backend TransToPtenBackend(const paddle::platform::Place& place); +Backend TransToPtenBackend(const pten::Place& place); DataType TransToPtenDataType( const paddle::framework::proto::VarType::Type& dtype); -paddle::platform::Place TransToFluidPlace(const Backend& backend); +pten::Place TransToFluidPlace(const Backend& backend); paddle::framework::proto::VarType::Type TransToProtoVarType( const DataType& dtype); -paddle::framework::LoD TransToFluidLoD(const pten::LoD& lod); -pten::LoD TransToPtenLoD(const paddle::framework::LoD& lod); - size_t DataTypeSize(DataType dtype); DataType String2DataType(const std::string& str); std::string DataType2String(DataType dtype); diff --git a/paddle/pten/core/kernel_alias_name.h b/paddle/pten/core/compat/kernel_alias_name.h similarity index 100% rename from paddle/pten/core/kernel_alias_name.h rename to paddle/pten/core/compat/kernel_alias_name.h diff --git a/paddle/pten/core/compat/op_utils.h b/paddle/pten/core/compat/op_utils.h index 505ef13891..d35eeffd7e 100644 --- a/paddle/pten/core/compat/op_utils.h +++ b/paddle/pten/core/compat/op_utils.h @@ -17,13 +17,12 @@ limitations under the License. */ #include #include "paddle/pten/core/compat/arg_map_context.h" +#include "paddle/pten/core/enforce.h" #include "paddle/pten/core/infermeta_utils.h" -#include "paddle/pten/core/kernel_def.h" #include "paddle/pten/core/macros.h" +#include "paddle/pten/core/type_defs.h" #include "paddle/utils/flat_hash_map.h" -#include "paddle/fluid/platform/enforce.h" - namespace pten { class DefaultKernelSignatureMap { @@ -37,7 +36,7 @@ class DefaultKernelSignatureMap { PADDLE_ENFORCE_NE( it, map_.end(), - paddle::platform::errors::NotFound( + pten::errors::NotFound( "Operator `%s`'s kernel signature is not registered.", op_type)); return it->second; } @@ -46,7 +45,7 @@ class DefaultKernelSignatureMap { PADDLE_ENFORCE_NE( Has(op_type), true, - paddle::platform::errors::AlreadyExists( + pten::errors::AlreadyExists( "Operator (%s)'s Kernel Siginature has been registered.", op_type)); map_.insert({std::move(op_type), std::move(signature)}); } @@ -71,7 +70,7 @@ class OpUtilsMap { PADDLE_ENFORCE_EQ( name_map_.count(op_type), 0UL, - paddle::platform::errors::AlreadyExists( + pten::errors::AlreadyExists( "Operator (%s)'s api name has been registered.", op_type)); name_map_.insert({std::move(op_type), std::move(api_name)}); } @@ -80,7 +79,7 @@ class OpUtilsMap { PADDLE_ENFORCE_EQ( arg_mapping_fn_map_.count(op_type), 0UL, - paddle::platform::errors::AlreadyExists( + pten::errors::AlreadyExists( "Operator (%s)'s argu,emt mapping function has been registered.", op_type)); arg_mapping_fn_map_.insert({std::move(op_type), std::move(fn)}); diff --git a/paddle/pten/core/compat/type_defs.h b/paddle/pten/core/compat/type_defs.h new file mode 100644 index 0000000000..eb5459b1b6 --- /dev/null +++ b/paddle/pten/core/compat/type_defs.h @@ -0,0 +1,96 @@ +/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include + +namespace egr { +class EagerTensor; +} +namespace paddle { +namespace framework { +// The order should be as same as framework.proto +// NOTE(xiongkun): we extract from framework/typedef.h to ensure we can transfer +// enforce.h +class BlockDesc; +using Attribute = boost::variant, + std::vector, + std::vector, + bool, + std::vector, + BlockDesc*, + int64_t, + std::vector, + std::vector, + std::vector>; +using AttributeMap = std::unordered_map; +} // namespace framework + +namespace imperative { + +class VariableWrapper; +class SavedVariableWrapperList; +class VarBase; +class OpBase; +class GradOpNode; +class Tracer; + +using WeakNameVarBaseMap = + std::map>>; + +namespace details { +template +struct NameVarMapTrait {}; + +template <> +struct NameVarMapTrait { + using Type = std::map>>; +}; + +template <> +struct NameVarMapTrait { + using Type = std::map; +}; + +template <> +struct NameVarMapTrait { + using Type = + std::map>>; +}; + +} // namespace details + +template +using NameVarMap = typename details::NameVarMapTrait::Type; + +using NameVarBaseMap = NameVarMap; +using NameVariableWrapperMap = NameVarMap; +using NameTensorMap = NameVarMap; + +using VariableWrapperList = std::vector>; + +} // namespace imperative +} // namespace paddle diff --git a/paddle/pten/core/ddim.cc b/paddle/pten/core/ddim.cc index 663f92a5bf..1846b7cf7f 100644 --- a/paddle/pten/core/ddim.cc +++ b/paddle/pten/core/ddim.cc @@ -13,10 +13,10 @@ // limitations under the License. #include "paddle/pten/core/ddim.h" + #include namespace pten { -namespace platform = paddle::platform; namespace framework { DDim make_ddim(std::initializer_list dims) { @@ -84,7 +84,7 @@ DDim slice_ddim(const DDim& dim, int begin, int end) { PADDLE_ENFORCE_EQ( (begin >= 0 && end <= dim.size()), true, - platform::errors::InvalidArgument( + pten::errors::InvalidArgument( "[begin(%d), end(%d)) must be inside [0, %d) in ddim slice.", begin, end, @@ -111,30 +111,30 @@ std::ostream& operator<<(std::ostream& os, const DDim& ddim) { } DDim flatten_to_3d(const DDim& src, int num_row_dims, int num_col_dims) { - PADDLE_ENFORCE_GE(src.size(), - 3, - platform::errors::InvalidArgument( - "The rank of src dim should be at least 3 " - "in flatten_to_3d, but received %d.", - src.size())); - PADDLE_ENFORCE_EQ((num_row_dims >= 1 && num_row_dims < src.size()), - true, - platform::errors::InvalidArgument( - "The num_row_dims should be inside [1, %d] " - "in flatten_to_3d, but received %d.", - src.size() - 1, - num_row_dims)); - PADDLE_ENFORCE_EQ((num_col_dims >= 2 && num_col_dims <= src.size()), - true, - platform::errors::InvalidArgument( - "The num_col_dims should be inside [2, %d] " - "in flatten_to_3d, but received %d.", - src.size(), - num_col_dims)); + PADDLE_ENFORCE_GE( + src.size(), + 3, + pten::errors::InvalidArgument("The rank of src dim should be at least 3 " + "in flatten_to_3d, but received %d.", + src.size())); + PADDLE_ENFORCE_EQ( + (num_row_dims >= 1 && num_row_dims < src.size()), + true, + pten::errors::InvalidArgument("The num_row_dims should be inside [1, %d] " + "in flatten_to_3d, but received %d.", + src.size() - 1, + num_row_dims)); + PADDLE_ENFORCE_EQ( + (num_col_dims >= 2 && num_col_dims <= src.size()), + true, + pten::errors::InvalidArgument("The num_col_dims should be inside [2, %d] " + "in flatten_to_3d, but received %d.", + src.size(), + num_col_dims)); PADDLE_ENFORCE_GE( num_col_dims, num_row_dims, - platform::errors::InvalidArgument( + pten::errors::InvalidArgument( "The num_row_dims should be less than num_col_dims in flatten_to_3d," "but received num_row_dims = %d, num_col_dims = %d.", num_row_dims, @@ -181,7 +181,7 @@ DDim DDim::reshape(const std::vector& shape) const { if (shape[i] == copy_dim_val) { PADDLE_ENFORCE_LT(static_cast(i), in_dims.size(), - platform::errors::InvalidArgument( + pten::errors::InvalidArgument( "Index %d of shape under which the value of 0 " "is stored, must be lower than the number of " "old dimensions. But received shape[%d] = 0, " @@ -205,22 +205,22 @@ DDim DDim::transpose(const std::vector& axis) const { auto axis_set = std::set(axis.begin(), axis.end()); PADDLE_ENFORCE_EQ(axis_set.size(), axis_size, - platform::errors::InvalidArgument( + pten::errors::InvalidArgument( "In an axis array, elements must be unique.")); PADDLE_ENFORCE_EQ( in_rank, axis_size, - platform::errors::InvalidArgument("The input dimension's size " - "should be equal to the axis's size. " - "But received dimension is %d, " - "axis's size is %d", - in_rank, - axis_size)); + pten::errors::InvalidArgument("The input dimension's size " + "should be equal to the axis's size. " + "But received dimension is %d, " + "axis's size is %d", + in_rank, + axis_size)); PADDLE_ENFORCE_LT(*std::max_element(axis.begin(), axis.end()), axis_size, - platform::errors::InvalidArgument( + pten::errors::InvalidArgument( "Axis values must be ranging from 0 to (dims - 1).")); DDim out_dims(in_dims); @@ -231,4 +231,4 @@ DDim DDim::transpose(const std::vector& axis) const { } } // namespace framework -} // namespace pten \ No newline at end of file +} // namespace pten diff --git a/paddle/pten/core/ddim.h b/paddle/pten/core/ddim.h index 148c32481c..71ee732be2 100644 --- a/paddle/pten/core/ddim.h +++ b/paddle/pten/core/ddim.h @@ -17,10 +17,10 @@ #include #include -#include "paddle/pten/core/dim.h" +#include "paddle/pten/core/enforce.h" +#include "paddle/pten/core/utils/dim.h" namespace pten { -namespace platform = paddle::platform; namespace framework { #define PADDLE_VISIT_DDIM_BASE(rank, callback) \ @@ -42,7 +42,7 @@ namespace framework { PADDLE_VISIT_DDIM_BASE(8, callback); \ PADDLE_VISIT_DDIM_BASE(9, callback); \ default: \ - PADDLE_THROW(platform::errors::Unimplemented( \ + PADDLE_THROW(pten::errors::Unimplemented( \ "Invalid dimension to be accessed. Now only supports access to " \ "dimension 0 to 9, but received dimension is %d.", \ rank)); \ @@ -98,14 +98,14 @@ class DDim { int64_t& at(int idx) { PADDLE_ENFORCE_GE(idx, 0, - platform::errors::InvalidArgument( + pten::errors::InvalidArgument( "Invalid DDim index to be accessed. The valid index " "is between 0 and %d, but received index is %d.", rank_, idx)); PADDLE_ENFORCE_LT(idx, rank_, - platform::errors::InvalidArgument( + pten::errors::InvalidArgument( "Invalid DDim index to be accessed. The valid index " "is between 0 and %d, but received index is %d.", rank_, @@ -116,14 +116,14 @@ class DDim { int64_t at(int idx) const { PADDLE_ENFORCE_GE(idx, 0, - platform::errors::InvalidArgument( + pten::errors::InvalidArgument( "Invalid DDim index to be accessed. The valid index " "is between 0 and %d, but received index is %d.", rank_, idx)); PADDLE_ENFORCE_LT(idx, rank_, - platform::errors::InvalidArgument( + pten::errors::InvalidArgument( "Invalid DDim index to be accessed. The valid index " "is between 0 and %d, but received index is %d.", rank_, diff --git a/paddle/pten/core/dense_tensor.cc b/paddle/pten/core/dense_tensor.cc index 7373ba79c0..36d56212e2 100644 --- a/paddle/pten/core/dense_tensor.cc +++ b/paddle/pten/core/dense_tensor.cc @@ -14,13 +14,13 @@ limitations under the License. */ #include "paddle/pten/core/dense_tensor.h" -// See Note [ Why still include the fluid headers? ] #include "paddle/pten/common/bfloat16.h" #include "paddle/pten/common/complex.h" #include "paddle/pten/common/float16.h" +#include "paddle/pten/core/compat/convert_utils.h" -#include "paddle/pten/api/lib/utils/storage.h" -#include "paddle/pten/core/convert_utils.h" +// See Note [ Why still include the fluid headers? ] +#include "paddle/fluid/memory/malloc.h" namespace pten { diff --git a/paddle/pten/core/dense_tensor.h b/paddle/pten/core/dense_tensor.h index fbecbcf0a1..8d10753b58 100644 --- a/paddle/pten/core/dense_tensor.h +++ b/paddle/pten/core/dense_tensor.h @@ -14,15 +14,15 @@ limitations under the License. */ #pragma once -#include "paddle/fluid/framework/data_layout.h" -#include "paddle/fluid/framework/data_type.h" -#include "paddle/fluid/platform/stream/stream.h" - #include "paddle/pten/core/allocator.h" #include "paddle/pten/core/storage.h" #include "paddle/pten/core/tensor_base.h" #include "paddle/pten/core/tensor_meta.h" +// See Note [ Why still include the fluid headers? ] +#include "paddle/fluid/framework/data_type.h" +#include "paddle/fluid/platform/stream/stream.h" + /* @jim19930609: Move to MKLDNN_Tensor in the future */ #ifdef PADDLE_WITH_MKLDNN @@ -31,7 +31,7 @@ limitations under the License. */ namespace pten { -class CompatibleDenseTensorUtils; +class DenseTensorUtils; /// \brief The Dense tensor store values in a contiguous sequential block /// of memory where all values are represented. Tensors or multi-dimensional @@ -120,8 +120,8 @@ class DenseTensor : public TensorBase, /// \return Whether the metadata is valid. bool valid() const noexcept override { return meta_.valid(); } - /// \brief Test whether the storage is allocated. - /// return Whether the storage is allocated. + /// \brief Test whether the allocation is allocated. + /// return Whether the allocation is allocated. bool initialized() const override { return holder_ && holder_->ptr(); } /// \brief Allocate memory with requested size from allocator. @@ -130,12 +130,12 @@ class DenseTensor : public TensorBase, DataType dtype, size_t requested_size = 0) override; - /// \brief Check if storage is shared with other objects. - /// \return Whether the storage is shared with other objects. + /// \brief Check if allocation is shared with other objects. + /// \return Whether the allocation is shared with other objects. bool IsSharedWith(const DenseTensor& b) const; /// \brief Change the shape information in the metadata. If the new size is - /// larger than the original value, the storage area will be reallocated. + /// larger than the original value, the allocation area will be reallocated. /// \param dims The new dims of the dense tensor. /// \param lod The new lod of the dense tensor. // void Resize(const DDim& dims); @@ -147,9 +147,10 @@ class DenseTensor : public TensorBase, /// \param lod The new lod of the dense tensor. void ResetLoD(const LoD& lod); - /// \brief Returns the actual storage size occupied by tensor, may be larger + /// \brief Returns the actual allocation size occupied by tensor, may be + /// larger /// than its shape dims. - /// \return The actual storage size occupied by tensor. + /// \return The actual allocation size occupied by tensor. size_t capacity() const { return holder_->size(); } /// \brief Get the const data pointer value of type T. @@ -162,7 +163,7 @@ class DenseTensor : public TensorBase, const void* data() const; private: - friend class CompatibleDenseTensorUtils; + friend class DenseTensorUtils; protected: DenseTensorMeta meta_; diff --git a/paddle/pten/core/dense_tensor_impl.cc b/paddle/pten/core/dense_tensor_impl.cc index f825d3619b..8571437347 100644 --- a/paddle/pten/core/dense_tensor_impl.cc +++ b/paddle/pten/core/dense_tensor_impl.cc @@ -14,13 +14,12 @@ limitations under the License. */ #include "paddle/pten/core/dense_tensor.h" -// See Note [ Why still include the fluid headers? ] #include "paddle/pten/common/bfloat16.h" #include "paddle/pten/common/complex.h" #include "paddle/pten/common/float16.h" #include "paddle/pten/api/lib/utils/storage.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" namespace pten { /* --------------------------- */ diff --git a/paddle/pten/core/enforce.h b/paddle/pten/core/enforce.h index 97433f1a6d..2c52d044d2 100644 --- a/paddle/pten/core/enforce.h +++ b/paddle/pten/core/enforce.h @@ -49,7 +49,7 @@ limitations under the License. */ #include "paddle/utils/string/to_string.h" // Note: these headers for simplify demangle type string -#include "paddle/pten/core/type_defs.h" +#include "paddle/pten/core/compat/type_defs.h" namespace pten { class ErrorSummary; diff --git a/paddle/pten/core/infermeta_utils.h b/paddle/pten/core/infermeta_utils.h index 47f55f85ac..0f45185c83 100644 --- a/paddle/pten/core/infermeta_utils.h +++ b/paddle/pten/core/infermeta_utils.h @@ -18,9 +18,9 @@ limitations under the License. */ #include #include "paddle/pten/core/enforce.h" -#include "paddle/pten/core/kernel_def.h" #include "paddle/pten/core/macros.h" #include "paddle/pten/core/meta_tensor.h" +#include "paddle/pten/core/type_defs.h" #include "paddle/utils/flat_hash_map.h" #include "paddle/utils/small_vector.h" diff --git a/paddle/pten/core/kernel_context.h b/paddle/pten/core/kernel_context.h index def1019e20..876c98e3bc 100644 --- a/paddle/pten/core/kernel_context.h +++ b/paddle/pten/core/kernel_context.h @@ -17,20 +17,16 @@ #include #include -#include "paddle/pten/core/compat_utils.h" +#include "paddle/pten/core/device_context.h" +#include "paddle/pten/core/enforce.h" #include "paddle/pten/core/tensor_base.h" +#include "paddle/pten/core/tensor_utils.h" #include "paddle/utils/any.h" #include "paddle/utils/small_vector.h" -// See Note [ Why still include the fluid headers? ] -#include "paddle/fluid/platform/device_context.h" -#include "paddle/pten/core/enforce.h" - namespace pten { -using DeviceContext = paddle::platform::DeviceContext; -using DataType = paddle::experimental::DataType; -using DataLayout = paddle::experimental::DataLayout; +using DeviceContext = pten::DeviceContext; /** * Note: KernelContext doesn't manage the life if DeviceContext and Tensor diff --git a/paddle/pten/core/kernel_def.h b/paddle/pten/core/kernel_def.h deleted file mode 100644 index 9b91720d86..0000000000 --- a/paddle/pten/core/kernel_def.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include - -namespace pten { - -class Kernel; -class KernelKey; -class KernelArgsDef; -class KernelContext; -class KernelSignature; -class ArgumentMappingContext; -class InferMetaContext; - -using KernelFn = std::function; -using KernelArgsDefFn = void (*)(Kernel* kernel); -using KernelArgsParseFn = void (*)(const KernelKey& default_key, - KernelArgsDef* args_def); - -using ArgumentMappingFn = - std::function; -using InferMetaFn = void (*)(InferMetaContext* ctx); - -} // namespace pten diff --git a/paddle/pten/core/kernel_factory.h b/paddle/pten/core/kernel_factory.h index b21c71f3fa..249b83257c 100644 --- a/paddle/pten/core/kernel_factory.h +++ b/paddle/pten/core/kernel_factory.h @@ -23,11 +23,9 @@ #include "paddle/pten/common/backend.h" #include "paddle/pten/common/data_type.h" #include "paddle/pten/common/layout.h" -#include "paddle/pten/core/convert_utils.h" -#include "paddle/pten/core/kernel_def.h" - -// See Note [ Why still include the fluid headers? ] +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/enforce.h" +#include "paddle/pten/core/type_defs.h" #include "paddle/utils/flat_hash_map.h" #include "paddle/utils/small_vector.h" diff --git a/paddle/pten/core/kernel_registry.h b/paddle/pten/core/kernel_registry.h index 210309cad6..7d6c079f46 100644 --- a/paddle/pten/core/kernel_registry.h +++ b/paddle/pten/core/kernel_registry.h @@ -21,10 +21,10 @@ #include #include -#include "paddle/pten/core/kernel_def.h" #include "paddle/pten/core/kernel_factory.h" #include "paddle/pten/core/kernel_utils.h" #include "paddle/pten/core/macros.h" +#include "paddle/pten/core/type_defs.h" #include "paddle/pten/core/enforce.h" diff --git a/paddle/pten/core/kernel_utils.h b/paddle/pten/core/kernel_utils.h index 5d6f5376c7..2ecb3eca6c 100644 --- a/paddle/pten/core/kernel_utils.h +++ b/paddle/pten/core/kernel_utils.h @@ -18,14 +18,12 @@ #include "paddle/pten/common/scalar.h" #include "paddle/pten/common/scalar_array.h" #include "paddle/pten/core/dense_tensor.h" +#include "paddle/pten/core/enforce.h" #include "paddle/pten/core/kernel_context.h" -#include "paddle/pten/core/kernel_def.h" #include "paddle/pten/core/selected_rows.h" #include "paddle/pten/core/sparse_coo_tensor.h" #include "paddle/pten/core/sparse_csr_tensor.h" - -// See Note [ Why still include the fluid headers? ] -#include "paddle/pten/core/enforce.h" +#include "paddle/pten/core/type_defs.h" namespace pten { diff --git a/paddle/pten/core/lod_utils.cc b/paddle/pten/core/lod_utils.cc index ad5ea6d39d..83b90c4305 100644 --- a/paddle/pten/core/lod_utils.cc +++ b/paddle/pten/core/lod_utils.cc @@ -14,14 +14,14 @@ #include "paddle/pten/core/lod_utils.h" -#include "paddle/fluid/platform/enforce.h" +#include "paddle/pten/core/enforce.h" namespace pten { void AppendLoD(LoD *lod, const LoD &lod_length) { PADDLE_ENFORCE( lod->empty() || lod->size() == lod_length.size(), - paddle::platform::errors::InvalidArgument( + pten::errors::InvalidArgument( "The input LoD length should be equal to the appended LoD size, but " "received input LoD length is %d, actual LoD size is %d.", lod_length.size(), diff --git a/paddle/pten/core/meta_tensor.cc b/paddle/pten/core/meta_tensor.cc index a8229b568a..fd558d20a0 100644 --- a/paddle/pten/core/meta_tensor.cc +++ b/paddle/pten/core/meta_tensor.cc @@ -14,10 +14,9 @@ limitations under the License. */ #include "paddle/pten/core/meta_tensor.h" -#include "paddle/pten/core/compat_utils.h" #include "paddle/pten/core/dense_tensor.h" - -#include "paddle/fluid/platform/enforce.h" +#include "paddle/pten/core/enforce.h" +#include "paddle/pten/core/tensor_utils.h" namespace pten { @@ -31,9 +30,8 @@ DataLayout MetaTensor::layout() const { return tensor_->layout(); } void MetaTensor::set_dims(const DDim& dims) { if (pten::DenseTensor::classof(tensor_)) { - CompatibleDenseTensorUtils::GetMutableMeta( - static_cast(tensor_)) - ->dims = dims; + DenseTensorUtils::GetMutableMeta(static_cast(tensor_))->dims = + dims; } else { PADDLE_THROW(paddle::platform::errors::Unimplemented( "Unsupported setting dims for `%s`.", tensor_->type_info().name())); @@ -42,8 +40,7 @@ void MetaTensor::set_dims(const DDim& dims) { void MetaTensor::set_dtype(DataType dtype) { if (pten::DenseTensor::classof(tensor_)) { - CompatibleDenseTensorUtils::GetMutableMeta( - static_cast(tensor_)) + DenseTensorUtils::GetMutableMeta(static_cast(tensor_)) ->dtype = dtype; } else { PADDLE_THROW(paddle::platform::errors::Unimplemented( @@ -53,8 +50,7 @@ void MetaTensor::set_dtype(DataType dtype) { void MetaTensor::set_layout(DataLayout layout) { if (pten::DenseTensor::classof(tensor_)) { - CompatibleDenseTensorUtils::GetMutableMeta( - static_cast(tensor_)) + DenseTensorUtils::GetMutableMeta(static_cast(tensor_)) ->layout = layout; } else { PADDLE_THROW(paddle::platform::errors::Unimplemented( @@ -64,9 +60,8 @@ void MetaTensor::set_layout(DataLayout layout) { void MetaTensor::share_lod(const MetaTensor& meta_tensor) { if (pten::DenseTensor::classof(tensor_)) { - CompatibleDenseTensorUtils::GetMutableMeta( - static_cast(tensor_)) - ->lod = meta_tensor.lod(); + DenseTensorUtils::GetMutableMeta(static_cast(tensor_))->lod = + meta_tensor.lod(); } else { PADDLE_THROW(paddle::platform::errors::Unimplemented( "Unsupported share lod inplace for `%s`.", diff --git a/paddle/pten/core/meta_tensor.h b/paddle/pten/core/meta_tensor.h index 1435e1c391..ae2ec60626 100644 --- a/paddle/pten/core/meta_tensor.h +++ b/paddle/pten/core/meta_tensor.h @@ -16,13 +16,11 @@ limitations under the License. */ #include "paddle/pten/common/data_type.h" #include "paddle/pten/common/layout.h" +#include "paddle/pten/core/ddim.h" #include "paddle/pten/core/macros.h" #include "paddle/pten/core/tensor_base.h" #include "paddle/pten/core/tensor_meta.h" -// See Note [ Why still include the fluid headers? ] -#include "paddle/fluid/framework/ddim.h" - namespace pten { class MetaTensor { diff --git a/paddle/pten/core/storage.h b/paddle/pten/core/storage.h index fc8b5dfaab..6e7c47c205 100644 --- a/paddle/pten/core/storage.h +++ b/paddle/pten/core/storage.h @@ -17,14 +17,12 @@ limitations under the License. */ #include #include "boost/intrusive_ptr.hpp" +#include "paddle/pten/common/place.h" +#include "paddle/pten/core/allocator.h" #include "paddle/pten/core/utils/intrusive_ptr.h" #include "paddle/pten/core/utils/intrusive_ref_counter.h" #include "paddle/pten/core/utils/type_info.h" -#include "paddle/fluid/memory/memory.h" -#include "paddle/fluid/platform/place.h" -#include "paddle/pten/core/allocator.h" - namespace pten { /// \brief The interface of contiguous storage used for the dense tensor. @@ -32,7 +30,6 @@ namespace pten { /// all default copy operations to ensure the integrity of the package. class Storage : public intrusive_ref_counter { public: - using Place = paddle::platform::Place; Storage() = default; Storage(const Storage&) = delete; @@ -43,11 +40,11 @@ class Storage : public intrusive_ref_counter { /* --------- shared_ptr -------- */ // Initialize a Storage with unique Allocation - explicit Storage(std::shared_ptr&& data) + explicit Storage(std::shared_ptr&& data) : data_(std::move(data)) {} // Initialize a Storage shareing Allocation with another storage - explicit Storage(const std::shared_ptr& data) + explicit Storage(const std::shared_ptr& data) : data_(data) {} void* data() const { @@ -56,17 +53,15 @@ class Storage : public intrusive_ref_counter { : nullptr; } - const std::shared_ptr& data_shared() const { - return data_; - } + const std::shared_ptr& data_shared() const { return data_; } virtual void set_data_shared( - const std::shared_ptr& holder) = 0; + const std::shared_ptr& holder) = 0; - virtual std::shared_ptr&& move_data_shared() = 0; + virtual std::shared_ptr&& move_data_shared() = 0; virtual void ReallocShared(size_t n) { - PADDLE_THROW(paddle::platform::errors::Unimplemented( + PADDLE_THROW(pten::errors::Unimplemented( "ReallocShared has not been overrided by the current Storage")); } /* --------- shared_ptr -------- */ @@ -81,13 +76,11 @@ class Storage : public intrusive_ref_counter { virtual void Realloc(size_t n) = 0; protected: - std::shared_ptr data_; + std::shared_ptr data_; }; class TensorStorage : public Storage { public: - using Place = paddle::platform::Place; - explicit TensorStorage(Allocator* a) : alloc_(a) {} TensorStorage(Allocator* a, size_t size) @@ -110,7 +103,7 @@ class TensorStorage : public Storage { const Place& place() const override { if (!data_) { - PADDLE_THROW(paddle::platform::errors::Unimplemented( + PADDLE_THROW(pten::errors::Unimplemented( "Unable to visit place: either data_ or alloc_ has to be initialized " "first.")); } @@ -120,13 +113,13 @@ class TensorStorage : public Storage { bool OwnsMemory() const noexcept override { return true; } void set_data_shared( - const std::shared_ptr& holder) override { + const std::shared_ptr& holder) override { CHECK(holder); data_ = holder; size_ = holder->size(); } - std::shared_ptr&& move_data_shared() override { + std::shared_ptr&& move_data_shared() override { size_ = 0; return std::move(data_); } diff --git a/paddle/pten/core/tensor_base.h b/paddle/pten/core/tensor_base.h index 7a5e42da49..5c0f74df49 100644 --- a/paddle/pten/core/tensor_base.h +++ b/paddle/pten/core/tensor_base.h @@ -14,23 +14,19 @@ limitations under the License. */ #pragma once -#include "paddle/fluid/platform/place.h" #include "paddle/pten/common/backend.h" #include "paddle/pten/common/data_type.h" #include "paddle/pten/common/layout.h" +#include "paddle/pten/common/place.h" #include "paddle/pten/core/allocator.h" #include "paddle/pten/core/ddim.h" -#include "paddle/pten/core/storage.h" #include "paddle/pten/core/utils/type_registry.h" namespace pten { class TensorBase { public: - using DataType = paddle::experimental::DataType; - using DataLayout = paddle::experimental::DataLayout; using DDim = pten::framework::DDim; - using Place = paddle::platform::Place; virtual ~TensorBase() = default; diff --git a/paddle/pten/core/tensor_meta.h b/paddle/pten/core/tensor_meta.h index ac3f17267c..60b2be3c17 100644 --- a/paddle/pten/core/tensor_meta.h +++ b/paddle/pten/core/tensor_meta.h @@ -19,8 +19,6 @@ limitations under the License. */ #include "paddle/pten/common/backend.h" #include "paddle/pten/common/data_type.h" #include "paddle/pten/common/layout.h" - -// See Note [ Why still include the fluid headers? ] #include "paddle/pten/core/ddim.h" // Note: mixed_vector include many header now, LoD will be diff --git a/paddle/pten/core/compat_utils.h b/paddle/pten/core/tensor_utils.h similarity index 81% rename from paddle/pten/core/compat_utils.h rename to paddle/pten/core/tensor_utils.h index 46e53e3997..00dcdc65b8 100644 --- a/paddle/pten/core/compat_utils.h +++ b/paddle/pten/core/tensor_utils.h @@ -14,33 +14,17 @@ limitations under the License. */ #pragma once -#include "paddle/pten/api/lib/utils/storage.h" #include "paddle/pten/core/dense_tensor.h" -#include "paddle/pten/core/storage.h" #include "paddle/pten/core/tensor_meta.h" namespace pten { -/** - * In order to meet some adaptation requirements of the compatible state, - * these class is added to provide some tool functions. - * - * These utility functions may be deleted in the future, It is not recommended - * to be widely used in the framework - */ - -class CompatibleDenseTensorUtils { +class DenseTensorUtils { public: static DenseTensorMeta* GetMutableMeta(DenseTensor* tensor) { return &(tensor->meta_); } - // only can deal with SharedStorage now - static void ClearStorage(DenseTensor* tensor) { - // use static_cast to improve performance, replace by dynamic_cast later - tensor->MoveMemoryHolder(); - } - static DenseTensor Slice(const DenseTensor& tensor, int64_t begin_idx, int64_t end_idx) { diff --git a/paddle/pten/core/type_defs.h b/paddle/pten/core/type_defs.h index eb5459b1b6..9b91720d86 100644 --- a/paddle/pten/core/type_defs.h +++ b/paddle/pten/core/type_defs.h @@ -1,96 +1,38 @@ -/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. */ +// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. #pragma once -#include -#include -#include -#include -#include -#include - -#include - -namespace egr { -class EagerTensor; -} -namespace paddle { -namespace framework { -// The order should be as same as framework.proto -// NOTE(xiongkun): we extract from framework/typedef.h to ensure we can transfer -// enforce.h -class BlockDesc; -using Attribute = boost::variant, - std::vector, - std::vector, - bool, - std::vector, - BlockDesc*, - int64_t, - std::vector, - std::vector, - std::vector>; -using AttributeMap = std::unordered_map; -} // namespace framework - -namespace imperative { - -class VariableWrapper; -class SavedVariableWrapperList; -class VarBase; -class OpBase; -class GradOpNode; -class Tracer; - -using WeakNameVarBaseMap = - std::map>>; - -namespace details { -template -struct NameVarMapTrait {}; - -template <> -struct NameVarMapTrait { - using Type = std::map>>; -}; - -template <> -struct NameVarMapTrait { - using Type = std::map; -}; - -template <> -struct NameVarMapTrait { - using Type = - std::map>>; -}; +#include -} // namespace details +namespace pten { -template -using NameVarMap = typename details::NameVarMapTrait::Type; +class Kernel; +class KernelKey; +class KernelArgsDef; +class KernelContext; +class KernelSignature; +class ArgumentMappingContext; +class InferMetaContext; -using NameVarBaseMap = NameVarMap; -using NameVariableWrapperMap = NameVarMap; -using NameTensorMap = NameVarMap; +using KernelFn = std::function; +using KernelArgsDefFn = void (*)(Kernel* kernel); +using KernelArgsParseFn = void (*)(const KernelKey& default_key, + KernelArgsDef* args_def); -using VariableWrapperList = std::vector>; +using ArgumentMappingFn = + std::function; +using InferMetaFn = void (*)(InferMetaContext* ctx); -} // namespace imperative -} // namespace paddle +} // namespace pten diff --git a/paddle/pten/core/array.h b/paddle/pten/core/utils/array.h similarity index 88% rename from paddle/pten/core/array.h rename to paddle/pten/core/utils/array.h index 86d222d2d5..cd43dc7b42 100644 --- a/paddle/pten/core/array.h +++ b/paddle/pten/core/utils/array.h @@ -15,12 +15,11 @@ #pragma once #include -#include "paddle/pten/core/unroll_array_ops.h" -// TODO(paddle-dev): Need to modify into pten/core/enforce.h -#include "paddle/fluid/platform/enforce.h" + +#include "paddle/pten/core/enforce.h" +#include "paddle/pten/core/utils/unroll_array_ops.h" namespace pten { -namespace platform = paddle::platform; namespace framework { template @@ -58,7 +57,7 @@ class Array { HOSTDEVICE inline T &at(size_t i) { #if !defined(__CUDA_ARCH__) && !defined(__HIPCC__) PADDLE_ENFORCE_LT( - i, N, platform::errors::OutOfRange("Array index out of bounds.")); + i, N, pten::errors::OutOfRange("Array index out of bounds.")); #endif return (*this)[i]; } @@ -66,7 +65,7 @@ class Array { HOSTDEVICE inline const T &at(size_t i) const { #if !defined(__CUDA_ARCH__) && !defined(__HIPCC__) PADDLE_ENFORCE_LT( - i, N, platform::errors::OutOfRange("Array index out of bounds.")); + i, N, pten::errors::OutOfRange("Array index out of bounds.")); #endif return (*this)[i]; } @@ -114,7 +113,7 @@ class Array { static T obj(); return obj; #else - PADDLE_THROW(platform::errors::Unavailable("Array has no element.")); + PADDLE_THROW(pten::errors::Unavailable("Array has no element.")); #endif } @@ -128,7 +127,7 @@ class Array { static const T obj(); return obj; #else - PADDLE_THROW(platform::errors::Unavailable("Array has no element.")); + PADDLE_THROW(pten::errors::Unavailable("Array has no element.")); #endif } diff --git a/paddle/pten/core/dim.h b/paddle/pten/core/utils/dim.h similarity index 98% rename from paddle/pten/core/dim.h rename to paddle/pten/core/utils/dim.h index 8dd984891a..a24d6e40df 100644 --- a/paddle/pten/core/dim.h +++ b/paddle/pten/core/utils/dim.h @@ -20,8 +20,8 @@ #include #include -#include "paddle/pten/core/array.h" #include "paddle/pten/core/hostdevice.h" +#include "paddle/pten/core/utils/array.h" namespace pten { namespace framework { diff --git a/paddle/pten/core/utils/rw_lock.h b/paddle/pten/core/utils/rw_lock.h index 7bd190c901..6a2429ef30 100644 --- a/paddle/pten/core/utils/rw_lock.h +++ b/paddle/pten/core/utils/rw_lock.h @@ -20,8 +20,7 @@ limitations under the License. */ #include // NOLINT #endif // !_WIN32 -// See Note [ Why still include the fluid headers? ] -#include "paddle/fluid/platform/enforce.h" +#include "paddle/pten/core/enforce.h" namespace pten { @@ -32,24 +31,23 @@ struct RWLock { ~RWLock() { pthread_rwlock_destroy(&lock_); } inline void RDLock() { - PADDLE_ENFORCE_EQ(pthread_rwlock_rdlock(&lock_), - 0, - paddle::platform::errors::External( - "The pthread failed to acquire read lock.")); + PADDLE_ENFORCE_EQ( + pthread_rwlock_rdlock(&lock_), + 0, + pten::errors::External("The pthread failed to acquire read lock.")); } inline void WRLock() { - PADDLE_ENFORCE_EQ(pthread_rwlock_wrlock(&lock_), - 0, - paddle::platform::errors::External( - "The pthread failed to acquire write lock.")); + PADDLE_ENFORCE_EQ( + pthread_rwlock_wrlock(&lock_), + 0, + pten::errors::External("The pthread failed to acquire write lock.")); } inline void UNLock() { - PADDLE_ENFORCE_EQ( - pthread_rwlock_unlock(&lock_), - 0, - paddle::platform::errors::External("The pthread failed to unlock.")); + PADDLE_ENFORCE_EQ(pthread_rwlock_unlock(&lock_), + 0, + pten::errors::External("The pthread failed to unlock.")); } private: diff --git a/paddle/pten/core/unroll_array_ops.h b/paddle/pten/core/utils/unroll_array_ops.h similarity index 100% rename from paddle/pten/core/unroll_array_ops.h rename to paddle/pten/core/utils/unroll_array_ops.h diff --git a/paddle/pten/infermeta/unary.cc b/paddle/pten/infermeta/unary.cc index 3f6b559f56..e1a30d10e1 100644 --- a/paddle/pten/infermeta/unary.cc +++ b/paddle/pten/infermeta/unary.cc @@ -24,6 +24,8 @@ void UnchangedInferMetaNew(MetaConfig config, const MetaTensor& x, MetaTensor* out) { out->set_dims(x.dims()); + out->set_dtype(x.dtype()); + out->set_layout(x.layout()); out->share_lod(x); } diff --git a/paddle/pten/kernels/cpu/copy_kernel.cc b/paddle/pten/kernels/cpu/copy_kernel.cc index 0892e3974f..6a5d33b91a 100644 --- a/paddle/pten/kernels/cpu/copy_kernel.cc +++ b/paddle/pten/kernels/cpu/copy_kernel.cc @@ -16,7 +16,7 @@ limitations under the License. */ #include "paddle/pten/backends/cpu/cpu_context.h" #include "paddle/pten/common/data_type.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/kernel_registry.h" // See Note [ Why still include the fluid headers? ] diff --git a/paddle/pten/kernels/gpu/copy_kernel.cu b/paddle/pten/kernels/gpu/copy_kernel.cu index d257872315..6c0e7b1fe6 100644 --- a/paddle/pten/kernels/gpu/copy_kernel.cu +++ b/paddle/pten/kernels/gpu/copy_kernel.cu @@ -16,7 +16,7 @@ limitations under the License. */ #include "paddle/pten/backends/gpu/gpu_context.h" #include "paddle/pten/common/data_type.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/kernel_registry.h" // See Note [ Why still include the fluid headers? ] diff --git a/paddle/pten/kernels/gpu/math_kernel.cu b/paddle/pten/kernels/gpu/math_kernel.cu index 37104c46a4..1a549087e4 100644 --- a/paddle/pten/kernels/gpu/math_kernel.cu +++ b/paddle/pten/kernels/gpu/math_kernel.cu @@ -29,7 +29,7 @@ namespace cub = hipcub; #include "paddle/pten/common/complex.h" #include "paddle/pten/common/float16.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/enforce.h" #include "paddle/pten/core/kernel_registry.h" diff --git a/paddle/pten/kernels/gpu/reduce.h b/paddle/pten/kernels/gpu/reduce.h index d864c76ea1..ca850d2c8c 100644 --- a/paddle/pten/kernels/gpu/reduce.h +++ b/paddle/pten/kernels/gpu/reduce.h @@ -38,14 +38,13 @@ namespace cub = hipcub; #include "paddle/fluid/platform/device/gpu/gpu_info.h" #include "paddle/fluid/platform/fast_divmod.h" #include "paddle/fluid/string/string_helper.h" -#include "paddle/pten/core/array.h" -#include "paddle/pten/core/enforce.h" -#include "paddle/pten/kernels/primitive/kernel_primitives.h" - #include "paddle/pten/api/ext/dispatch.h" #include "paddle/pten/backends/gpu/gpu_context.h" #include "paddle/pten/core/dense_tensor.h" +#include "paddle/pten/core/enforce.h" +#include "paddle/pten/core/utils/array.h" #include "paddle/pten/kernels/funcs/elementwise_base.h" +#include "paddle/pten/kernels/primitive/kernel_primitives.h" // Reduce split or not, Whether to use ReduceHigherDim #define REDUCE_SPLIT_BOUNDARY 512 diff --git a/paddle/pten/kernels/impl/digamma_grad_kernel_impl.h b/paddle/pten/kernels/impl/digamma_grad_kernel_impl.h index 44f94608b9..f919fe234c 100644 --- a/paddle/pten/kernels/impl/digamma_grad_kernel_impl.h +++ b/paddle/pten/kernels/impl/digamma_grad_kernel_impl.h @@ -47,7 +47,7 @@ void DigammaGradKernel(const Context& ctx, auto* x_data = x.data(); auto* dx_data = x_grad->data(); auto numel = out_grad.numel(); - platform::ForRange for_range(ctx, numel); + paddle::platform::ForRange for_range(ctx, numel); DigammaGradFunctor functor(dout_data, x_data, dx_data, numel); for_range(functor); } diff --git a/paddle/pten/kernels/impl/digamma_kernel_impl.h b/paddle/pten/kernels/impl/digamma_kernel_impl.h index a47750ff15..209b3e9537 100644 --- a/paddle/pten/kernels/impl/digamma_kernel_impl.h +++ b/paddle/pten/kernels/impl/digamma_kernel_impl.h @@ -41,7 +41,7 @@ void DigammaKernel(const Context& ctx, const DenseTensor& x, DenseTensor* out) { auto* x_data = x.data(); auto* out_data = out->data(); auto numel = x.numel(); - platform::ForRange for_range(ctx, numel); + paddle::platform::ForRange for_range(ctx, numel); DigammaFunctor functor(x_data, out_data, numel); for_range(functor); } diff --git a/paddle/pten/kernels/math_kernel.h b/paddle/pten/kernels/math_kernel.h index afef586693..6dcb9dd77a 100644 --- a/paddle/pten/kernels/math_kernel.h +++ b/paddle/pten/kernels/math_kernel.h @@ -14,7 +14,6 @@ limitations under the License. */ #pragma once -#include "paddle/pten/api/lib/utils/storage.h" #include "paddle/pten/core/dense_tensor.h" #include "paddle/pten/infermeta/binary.h" #include "paddle/pten/infermeta/unary.h" diff --git a/paddle/pten/kernels/xpu/cast_kernel.cc b/paddle/pten/kernels/xpu/cast_kernel.cc index fc1ba021e2..027aa4f5b4 100644 --- a/paddle/pten/kernels/xpu/cast_kernel.cc +++ b/paddle/pten/kernels/xpu/cast_kernel.cc @@ -14,11 +14,13 @@ #include "paddle/pten/kernels/cast_kernel.h" -#include "paddle/fluid/platform/device/xpu/xpu_header.h" #include "paddle/pten/backends/xpu/xpu_context.h" +#include "paddle/pten/common/float16.h" +#include "paddle/pten/core/enforce.h" #include "paddle/pten/core/kernel_registry.h" -#include "paddle/pten/core/enforce.h" +// See Note [ Why still include the fluid headers? ] +#include "paddle/fluid/platform/device/xpu/xpu_header.h" namespace pten { @@ -28,7 +30,7 @@ void CastKernel(const Context& dev_ctx, DataType out_dtype, DenseTensor* out) { using XPUInTDType = typename XPUTypeTrait::Type; - using float16 = typename XPUTypeTrait::Type; + using float16 = typename XPUTypeTrait::Type; auto* in_data = x.data(); auto numel = x.numel(); @@ -47,7 +49,7 @@ void CastKernel(const Context& dev_ctx, dev_ctx.x_context(), reinterpret_cast(in_data), reinterpret_cast( - out->mutable_data(dev_ctx.GetPlace())), + out->mutable_data(dev_ctx.GetPlace())), numel); break; case pten::DataType::INT64: @@ -72,7 +74,7 @@ void CastKernel(const Context& dev_ctx, numel); break; default: - PADDLE_THROW(platform::errors::Unavailable( + PADDLE_THROW(pten::errors::Unavailable( "Not supported cast %d -> %d", x.dtype(), out_dtype)); } @@ -90,7 +92,7 @@ PT_REGISTER_KERNEL(cast, pten::CastKernel, int32_t, float, - pten::platform::float16, + pten::dtype::float16, int64_t, bool) { kernel->OutputAt(0).SetDataType(paddle::experimental::DataType::UNDEFINED); diff --git a/paddle/pten/kernels/xpu/copy_kernel.cc b/paddle/pten/kernels/xpu/copy_kernel.cc index 56ad19f0cc..f27705ca11 100644 --- a/paddle/pten/kernels/xpu/copy_kernel.cc +++ b/paddle/pten/kernels/xpu/copy_kernel.cc @@ -16,7 +16,7 @@ limitations under the License. */ #include "paddle/pten/backends/xpu/xpu_context.h" #include "paddle/pten/common/data_type.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/kernel_registry.h" // See Note [ Why still include the fluid headers? ] diff --git a/paddle/pten/kernels/xpu/full_kernel.cc b/paddle/pten/kernels/xpu/full_kernel.cc index 71d2b8e3ad..cf6befac02 100644 --- a/paddle/pten/kernels/xpu/full_kernel.cc +++ b/paddle/pten/kernels/xpu/full_kernel.cc @@ -16,9 +16,15 @@ #include "paddle/pten/api/ext/dispatch.h" #include "paddle/pten/backends/xpu/xpu_context.h" +#include "paddle/pten/common/bfloat16.h" +#include "paddle/pten/common/complex.h" +#include "paddle/pten/common/float16.h" #include "paddle/pten/common/scalar.h" #include "paddle/pten/core/kernel_registry.h" +// See Note [ Why still include the fluid headers? ] +#include "paddle/fluid/memory/memcpy.h" + namespace pten { template @@ -64,7 +70,7 @@ void FullLikeKernel(const Context& dev_ctx, using XPUInTDType = typename XPUTypeTrait::Type; using CommonType = typename std::common_type< float, - typename std::conditional::value, + typename std::conditional::value, float, T>::type>::type; @@ -118,10 +124,10 @@ PT_REGISTER_KERNEL(full, int, int64_t, bool, - pten::platform::float16, - pten::platform::bfloat16, - pten::platform::complex, - pten::platform::complex) {} + pten::dtype::float16, + pten::dtype::bfloat16, + pten::dtype::complex, + pten::dtype::complex) {} PT_REGISTER_KERNEL(full_like, XPU, @@ -130,4 +136,4 @@ PT_REGISTER_KERNEL(full_like, float, int, int64_t, - pten::platform::float16) {} + pten::dtype::float16) {} diff --git a/paddle/pten/kernels/xpu/scale_kernel.cc b/paddle/pten/kernels/xpu/scale_kernel.cc index 116cd63f87..25fb086044 100644 --- a/paddle/pten/kernels/xpu/scale_kernel.cc +++ b/paddle/pten/kernels/xpu/scale_kernel.cc @@ -18,7 +18,7 @@ #include "paddle/pten/backends/xpu/xpu_context.h" #include "paddle/pten/common/data_type.h" #include "paddle/pten/common/float16.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" #include "paddle/pten/core/kernel_registry.h" namespace pten { diff --git a/paddle/pten/tests/api/test_cast_api.cc b/paddle/pten/tests/api/test_cast_api.cc index b87bebacab..ad41759e15 100644 --- a/paddle/pten/tests/api/test_cast_api.cc +++ b/paddle/pten/tests/api/test_cast_api.cc @@ -35,7 +35,7 @@ TEST(API, cast) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 4}), + pten::framework::make_ddim({3, 4}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/api/test_concat_api.cc b/paddle/pten/tests/api/test_concat_api.cc index c003e89f6c..ec56861e80 100644 --- a/paddle/pten/tests/api/test_concat_api.cc +++ b/paddle/pten/tests/api/test_concat_api.cc @@ -24,8 +24,7 @@ limitations under the License. */ namespace paddle { namespace tests { -namespace framework = paddle::framework; -using DDim = paddle::framework::DDim; +using DDim = pten::framework::DDim; // TODO(chentianyu03): Remove this test after the API is used in the dygraph TEST(API, concat) { @@ -35,7 +34,7 @@ TEST(API, concat) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), + pten::framework::make_ddim({3, 10}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); @@ -43,7 +42,7 @@ TEST(API, concat) { auto dense_y = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), + pten::framework::make_ddim({3, 10}), pten::DataLayout::NCHW)); auto* dense_y_data = dense_y->mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/api/test_conj_api.cc b/paddle/pten/tests/api/test_conj_api.cc index 0273737347..773ada1afc 100644 --- a/paddle/pten/tests/api/test_conj_api.cc +++ b/paddle/pten/tests/api/test_conj_api.cc @@ -35,7 +35,7 @@ TEST(API, conj) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::COMPLEX64, - framework::make_ddim({3, 10}), + pten::framework::make_ddim({3, 10}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/api/test_dot_api.cc b/paddle/pten/tests/api/test_dot_api.cc index 6de8943a46..9c35e25119 100644 --- a/paddle/pten/tests/api/test_dot_api.cc +++ b/paddle/pten/tests/api/test_dot_api.cc @@ -35,7 +35,7 @@ TEST(API, dot) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), + pten::framework::make_ddim({3, 10}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); @@ -43,7 +43,7 @@ TEST(API, dot) { auto dense_y = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), + pten::framework::make_ddim({3, 10}), pten::DataLayout::NCHW)); auto* dense_y_data = dense_y->mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/api/test_elementwise_api.cc b/paddle/pten/tests/api/test_elementwise_api.cc index df1c6278d9..2a6cf461ee 100644 --- a/paddle/pten/tests/api/test_elementwise_api.cc +++ b/paddle/pten/tests/api/test_elementwise_api.cc @@ -35,7 +35,7 @@ TEST(API, add) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), + pten::framework::make_ddim({3, 10}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); @@ -43,7 +43,7 @@ TEST(API, add) { auto dense_y = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({10}), + pten::framework::make_ddim({10}), pten::DataLayout::NCHW)); auto* dense_y_data = dense_y->mutable_data(paddle::platform::CPUPlace()); @@ -91,7 +91,7 @@ TEST(API, subtract) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), + pten::framework::make_ddim({3, 10}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); @@ -99,7 +99,7 @@ TEST(API, subtract) { auto dense_y = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({10}), + pten::framework::make_ddim({10}), pten::DataLayout::NCHW)); auto* dense_y_data = dense_y->mutable_data(paddle::platform::CPUPlace()); @@ -147,7 +147,7 @@ TEST(API, divide) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), + pten::framework::make_ddim({3, 10}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); @@ -155,7 +155,7 @@ TEST(API, divide) { auto dense_y = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({10}), + pten::framework::make_ddim({10}), pten::DataLayout::NCHW)); auto* dense_y_data = dense_y->mutable_data(paddle::platform::CPUPlace()); @@ -203,7 +203,7 @@ TEST(API, multiply) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), + pten::framework::make_ddim({3, 10}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); @@ -211,7 +211,7 @@ TEST(API, multiply) { auto dense_y = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({10}), + pten::framework::make_ddim({10}), pten::DataLayout::NCHW)); auto* dense_y_data = dense_y->mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/api/test_empty_api.cc b/paddle/pten/tests/api/test_empty_api.cc index 72f9100f7b..4ce97d6c3a 100644 --- a/paddle/pten/tests/api/test_empty_api.cc +++ b/paddle/pten/tests/api/test_empty_api.cc @@ -35,7 +35,7 @@ TEST(API, empty_like) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 2}), + pten::framework::make_ddim({3, 2}), pten::DataLayout::NCHW)); paddle::experimental::Tensor x(dense_x); @@ -59,7 +59,7 @@ TEST(API, empty1) { auto dense_shape = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::INT64, - framework::make_ddim({2}), + pten::framework::make_ddim({2}), pten::DataLayout::NCHW)); auto* shape_data = dense_shape->mutable_data(paddle::platform::CPUPlace()); @@ -86,7 +86,7 @@ TEST(API, empty2) { auto dense_scalar = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::INT32, - framework::make_ddim({1}), + pten::framework::make_ddim({1}), pten::DataLayout::NCHW)); dense_scalar->mutable_data(paddle::platform::CPUPlace())[0] = 2; diff --git a/paddle/pten/tests/api/test_fill_api.cc b/paddle/pten/tests/api/test_fill_api.cc index 4b78d142ae..dd80b93534 100644 --- a/paddle/pten/tests/api/test_fill_api.cc +++ b/paddle/pten/tests/api/test_fill_api.cc @@ -35,7 +35,7 @@ TEST(API, full_like) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 2}), + pten::framework::make_ddim({3, 2}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); @@ -71,7 +71,7 @@ TEST(API, zeros_like) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 2}), + pten::framework::make_ddim({3, 2}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); @@ -105,7 +105,7 @@ TEST(API, ones_like) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::INT32, - framework::make_ddim({3, 2}), + pten::framework::make_ddim({3, 2}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); @@ -140,7 +140,7 @@ TEST(API, full1) { auto dense_shape = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::INT64, - framework::make_ddim({2}), + pten::framework::make_ddim({2}), pten::DataLayout::NCHW)); auto* shape_data = dense_shape->mutable_data(paddle::platform::CPUPlace()); @@ -150,7 +150,7 @@ TEST(API, full1) { auto dense_scalar = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({1}), + pten::framework::make_ddim({1}), pten::DataLayout::NCHW)); dense_scalar->mutable_data(paddle::platform::CPUPlace())[0] = 1.0; @@ -187,7 +187,7 @@ TEST(API, full2) { auto dense_scalar = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::INT32, - framework::make_ddim({1}), + pten::framework::make_ddim({1}), pten::DataLayout::NCHW)); dense_scalar->mutable_data(paddle::platform::CPUPlace())[0] = 2; diff --git a/paddle/pten/tests/api/test_flatten_api.cc b/paddle/pten/tests/api/test_flatten_api.cc index f3b80f7db5..7f04e6f3fc 100644 --- a/paddle/pten/tests/api/test_flatten_api.cc +++ b/paddle/pten/tests/api/test_flatten_api.cc @@ -35,7 +35,7 @@ TEST(API, flatten) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 2, 2, 3}), + pten::framework::make_ddim({3, 2, 2, 3}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/api/test_matmul_api.cc b/paddle/pten/tests/api/test_matmul_api.cc index 7342916c51..48d2374b68 100644 --- a/paddle/pten/tests/api/test_matmul_api.cc +++ b/paddle/pten/tests/api/test_matmul_api.cc @@ -35,7 +35,7 @@ TEST(API, matmul_cpu) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 3}), + pten::framework::make_ddim({3, 3}), pten::DataLayout::NCHW)); auto* dense_x_data = @@ -44,7 +44,7 @@ TEST(API, matmul_cpu) { auto dense_y = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 3}), + pten::framework::make_ddim({3, 3}), pten::DataLayout::NCHW)); auto* dense_y_data = dense_y->mutable_data(paddle::platform::CPUPlace()); @@ -86,7 +86,7 @@ TEST(API, matmul_cuda) { auto ref_x = std::make_shared( alloc_cpu.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 3}), + pten::framework::make_ddim({3, 3}), pten::DataLayout::NCHW)); auto* ref_x_data = ref_x->mutable_data(paddle::platform::CPUPlace()); @@ -94,7 +94,7 @@ TEST(API, matmul_cuda) { auto ref_y = std::make_shared( alloc_cpu.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 3}), + pten::framework::make_ddim({3, 3}), pten::DataLayout::NCHW)); auto* ref_y_data = ref_y->mutable_data(paddle::platform::CPUPlace()); @@ -111,13 +111,13 @@ TEST(API, matmul_cuda) { auto dense_x = std::make_shared( alloc_cuda.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 3}), + pten::framework::make_ddim({3, 3}), pten::DataLayout::NCHW)); auto dense_y = std::make_shared( alloc_cuda.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 3}), + pten::framework::make_ddim({3, 3}), pten::DataLayout::NCHW)); auto& pool = paddle::platform::DeviceContextPool::Instance(); diff --git a/paddle/pten/tests/api/test_mean_api.cc b/paddle/pten/tests/api/test_mean_api.cc index 046db05ca2..68b4933c54 100644 --- a/paddle/pten/tests/api/test_mean_api.cc +++ b/paddle/pten/tests/api/test_mean_api.cc @@ -35,7 +35,7 @@ TEST(API, mean) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 4}), + pten::framework::make_ddim({3, 4}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/api/test_reshape_api.cc b/paddle/pten/tests/api/test_reshape_api.cc index 1f0d734a7e..27e47a9183 100644 --- a/paddle/pten/tests/api/test_reshape_api.cc +++ b/paddle/pten/tests/api/test_reshape_api.cc @@ -35,7 +35,7 @@ TEST(API, reshape) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 2, 2, 3}), + pten::framework::make_ddim({3, 2, 2, 3}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/api/test_sum_api.cc b/paddle/pten/tests/api/test_sum_api.cc index 385d18aa78..33be9e54ee 100644 --- a/paddle/pten/tests/api/test_sum_api.cc +++ b/paddle/pten/tests/api/test_sum_api.cc @@ -35,7 +35,7 @@ TEST(API, sum) { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 4}), + pten::framework::make_ddim({3, 4}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/api/test_to_api.cc b/paddle/pten/tests/api/test_to_api.cc index 11636e1c01..3a1692603b 100644 --- a/paddle/pten/tests/api/test_to_api.cc +++ b/paddle/pten/tests/api/test_to_api.cc @@ -33,7 +33,7 @@ paddle::experimental::Tensor CreateInputTensor() { auto dense_x = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::INT64, - framework::make_ddim({3, 4}), + pten::framework::make_ddim({3, 4}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x->mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/core/CMakeLists.txt b/paddle/pten/tests/core/CMakeLists.txt index 1404b9921f..d9c8c86a24 100644 --- a/paddle/pten/tests/core/CMakeLists.txt +++ b/paddle/pten/tests/core/CMakeLists.txt @@ -23,3 +23,5 @@ endif() if (NOT WIN32) cc_test(test_rw_lock SRCS test_rw_lock.cc) endif (NOT WIN32) + +cc_test(unroll_array_ops_test SRCS unroll_array_ops_test.cc) diff --git a/paddle/pten/tests/core/test_convert_utils.cc b/paddle/pten/tests/core/test_convert_utils.cc index 51fba7cbe0..cc7ac6e7e5 100644 --- a/paddle/pten/tests/core/test_convert_utils.cc +++ b/paddle/pten/tests/core/test_convert_utils.cc @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. */ #include "gtest/gtest.h" -#include "paddle/pten/core/convert_utils.h" +#include "paddle/pten/core/compat/convert_utils.h" namespace pten { namespace tests { diff --git a/paddle/pten/tests/core/test_device_context.cc b/paddle/pten/tests/core/test_device_context.cc index a44d0d3215..c84c4a41a0 100644 --- a/paddle/pten/tests/core/test_device_context.cc +++ b/paddle/pten/tests/core/test_device_context.cc @@ -29,7 +29,7 @@ TEST(DeviceContext, cpu_context) { std::cout << "test training scenarios" << std::endl; { pten::CPUContext ctx; - CHECK(ctx.eigen_device() != nullptr); + EXPECT_TRUE(ctx.eigen_device() != nullptr); } std::cout << "test inference scenarios" << std::endl; @@ -37,13 +37,13 @@ TEST(DeviceContext, cpu_context) { { pten::CPUContextResource ctx_res{device}; pten::CPUContext ctx(ctx_res); - CHECK(ctx.eigen_device() != nullptr); + EXPECT_TRUE(ctx.eigen_device() != nullptr); } { pten::CPUContextResource ctx_res{nullptr}; pten::CPUContext ctx(ctx_res); ctx.SetEigenDevice(device); - CHECK(ctx.eigen_device() != nullptr); + EXPECT_TRUE(ctx.eigen_device() != nullptr); } delete device; @@ -51,7 +51,7 @@ TEST(DeviceContext, cpu_context) { { pten::CPUContext ctx1; pten::CPUContext ctx2(ctx1); - CHECK_EQ(ctx1.eigen_device(), ctx2.eigen_device()); + EXPECT_EQ(ctx1.eigen_device(), ctx2.eigen_device()); } std::cout << "test move constructor" << std::endl; @@ -60,7 +60,7 @@ TEST(DeviceContext, cpu_context) { auto* eigen_device1 = ctx1.eigen_device(); pten::CPUContext ctx2(std::move(ctx1)); auto* eigen_device2 = ctx2.eigen_device(); - CHECK_EQ(eigen_device1, eigen_device2); + EXPECT_EQ(eigen_device1, eigen_device2); } } diff --git a/paddle/pten/tests/core/test_dim.cu b/paddle/pten/tests/core/test_dim.cu index 1c4a9c163f..fec1029814 100644 --- a/paddle/pten/tests/core/test_dim.cu +++ b/paddle/pten/tests/core/test_dim.cu @@ -16,7 +16,7 @@ #include #include "gtest/gtest.h" -#include "paddle/pten/core/dim.h" +#include "paddle/pten/core/utils/dim.h" namespace pten { namespace tests { @@ -100,4 +100,4 @@ TEST(Dim, Print) { } } // namespace tests -} // namespace pten \ No newline at end of file +} // namespace pten diff --git a/paddle/pten/core/unroll_array_ops_test.cc b/paddle/pten/tests/core/unroll_array_ops_test.cc similarity index 96% rename from paddle/pten/core/unroll_array_ops_test.cc rename to paddle/pten/tests/core/unroll_array_ops_test.cc index f32d94be75..aee6cc6f40 100644 --- a/paddle/pten/core/unroll_array_ops_test.cc +++ b/paddle/pten/tests/core/unroll_array_ops_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/pten/core/unroll_array_ops.h" +#include "paddle/pten/core/utils/unroll_array_ops.h" #include #include @@ -79,4 +79,4 @@ TEST(unroll_ops, product) { } } // namespace framework -} // namespace pten \ No newline at end of file +} // namespace pten diff --git a/paddle/pten/tests/kernels/test_cast_dev_api.cc b/paddle/pten/tests/kernels/test_cast_dev_api.cc index 33d27ca5b1..2f9dab0fbe 100644 --- a/paddle/pten/tests/kernels/test_cast_dev_api.cc +++ b/paddle/pten/tests/kernels/test_cast_dev_api.cc @@ -35,10 +35,11 @@ TEST(DEV_API, cast) { // 1. create tensor const auto alloc = std::make_unique( paddle::platform::CPUPlace()); - pten::DenseTensor dense_x(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 4}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_x( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({3, 4}), + pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/kernels/test_concat_dev_api.cc b/paddle/pten/tests/kernels/test_concat_dev_api.cc index eb546e992e..ad2cf8c220 100644 --- a/paddle/pten/tests/kernels/test_concat_dev_api.cc +++ b/paddle/pten/tests/kernels/test_concat_dev_api.cc @@ -32,17 +32,19 @@ TEST(DEV_API, concat) { // 1. create tensor const auto alloc = std::make_unique( paddle::platform::CPUPlace()); - pten::DenseTensor dense_x(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_x( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({3, 10}), + pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); - pten::DenseTensor dense_y(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_y( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({3, 10}), + pten::DataLayout::NCHW)); auto* dense_y_data = dense_y.mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/kernels/test_conj_dev_api.cc b/paddle/pten/tests/kernels/test_conj_dev_api.cc index e43769dfb2..27332d99be 100644 --- a/paddle/pten/tests/kernels/test_conj_dev_api.cc +++ b/paddle/pten/tests/kernels/test_conj_dev_api.cc @@ -33,10 +33,11 @@ TEST(DEV_API, conj) { // 1. create tensor const auto alloc = std::make_unique( paddle::platform::CPUPlace()); - pten::DenseTensor dense_x(alloc.get(), - pten::DenseTensorMeta(pten::DataType::COMPLEX64, - framework::make_ddim({3, 4}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_x( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::COMPLEX64, + pten::framework::make_ddim({3, 4}), + pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/kernels/test_copy_dev_api.cc b/paddle/pten/tests/kernels/test_copy_dev_api.cc index 29f68513fa..76891028c4 100644 --- a/paddle/pten/tests/kernels/test_copy_dev_api.cc +++ b/paddle/pten/tests/kernels/test_copy_dev_api.cc @@ -38,7 +38,7 @@ TEST(DEV_API, copy) { auto dense_src = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({2, 3}), + pten::framework::make_ddim({2, 3}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_src->mutable_data(paddle::platform::CPUPlace()); @@ -46,7 +46,7 @@ TEST(DEV_API, copy) { auto dense_dst = std::make_shared( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({2, 3}), + pten::framework::make_ddim({2, 3}), pten::DataLayout::NCHW)); for (size_t i = 0; i < 2; ++i) { diff --git a/paddle/pten/tests/kernels/test_creation_dev_api.cc b/paddle/pten/tests/kernels/test_creation_dev_api.cc index 8b37c41d0b..14f323399c 100644 --- a/paddle/pten/tests/kernels/test_creation_dev_api.cc +++ b/paddle/pten/tests/kernels/test_creation_dev_api.cc @@ -53,10 +53,11 @@ TEST(DEV_API, empty_like) { // 1. create tensor const auto alloc = std::make_unique( paddle::platform::CPUPlace()); - pten::DenseTensor dense_x(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 2}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_x( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({3, 2}), + pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); dense_x_data[0] = 0; @@ -106,10 +107,11 @@ TEST(DEV_API, full_like) { // 1. create tensor const auto alloc = std::make_unique( paddle::platform::CPUPlace()); - pten::DenseTensor dense_x(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 2}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_x( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({3, 2}), + pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); dense_x_data[0] = 0; diff --git a/paddle/pten/tests/kernels/test_dot_dev_api.cc b/paddle/pten/tests/kernels/test_dot_dev_api.cc index c1f7d6aaba..3343ab1d42 100644 --- a/paddle/pten/tests/kernels/test_dot_dev_api.cc +++ b/paddle/pten/tests/kernels/test_dot_dev_api.cc @@ -33,17 +33,19 @@ TEST(DEV_API, dot) { // 1. create tensor const auto alloc = std::make_unique( paddle::platform::CPUPlace()); - pten::DenseTensor dense_x(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_x( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({3, 10}), + pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); - pten::DenseTensor dense_y(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_y( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({3, 10}), + pten::DataLayout::NCHW)); auto* dense_y_data = dense_y.mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/kernels/test_elementwise_dev_api.cc b/paddle/pten/tests/kernels/test_elementwise_dev_api.cc index 9d4c86f026..5a44fb6dae 100644 --- a/paddle/pten/tests/kernels/test_elementwise_dev_api.cc +++ b/paddle/pten/tests/kernels/test_elementwise_dev_api.cc @@ -33,17 +33,19 @@ TEST(DEV_API, add) { // 1. create tensor const auto alloc = std::make_unique( paddle::platform::CPUPlace()); - pten::DenseTensor dense_x(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_x( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({3, 10}), + pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); - pten::DenseTensor dense_y(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({10}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_y( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({10}), + pten::DataLayout::NCHW)); auto* dense_y_data = dense_y.mutable_data(paddle::platform::CPUPlace()); @@ -85,17 +87,19 @@ TEST(DEV_API, subtract) { // 1. create tensor const auto alloc = std::make_unique( paddle::platform::CPUPlace()); - pten::DenseTensor dense_x(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_x( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({3, 10}), + pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); - pten::DenseTensor dense_y(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({10}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_y( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({10}), + pten::DataLayout::NCHW)); auto* dense_y_data = dense_y.mutable_data(paddle::platform::CPUPlace()); @@ -137,17 +141,19 @@ TEST(DEV_API, divide) { // 1. create tensor const auto alloc = std::make_unique( paddle::platform::CPUPlace()); - pten::DenseTensor dense_x(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_x( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({3, 10}), + pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); - pten::DenseTensor dense_y(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({10}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_y( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({10}), + pten::DataLayout::NCHW)); auto* dense_y_data = dense_y.mutable_data(paddle::platform::CPUPlace()); @@ -189,17 +195,19 @@ TEST(DEV_API, multiply) { // 1. create tensor const auto alloc = std::make_unique( paddle::platform::CPUPlace()); - pten::DenseTensor dense_x(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 10}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_x( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({3, 10}), + pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); - pten::DenseTensor dense_y(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({10}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_y( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({10}), + pten::DataLayout::NCHW)); auto* dense_y_data = dense_y.mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/kernels/test_flatten_dev_api.cc b/paddle/pten/tests/kernels/test_flatten_dev_api.cc index 2ebf10916b..749004f3d7 100644 --- a/paddle/pten/tests/kernels/test_flatten_dev_api.cc +++ b/paddle/pten/tests/kernels/test_flatten_dev_api.cc @@ -46,7 +46,7 @@ TEST(DEV_API, flatten) { pten::DenseTensor dense_x( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 2, 2, 3}), + pten::framework::make_ddim({3, 2, 2, 3}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/kernels/test_matmul_dev_api.cc b/paddle/pten/tests/kernels/test_matmul_dev_api.cc index 87c91b1008..0dfbb54a49 100644 --- a/paddle/pten/tests/kernels/test_matmul_dev_api.cc +++ b/paddle/pten/tests/kernels/test_matmul_dev_api.cc @@ -34,7 +34,7 @@ TEST(DEV_API, dot) { paddle::platform::CPUPlace()); DenseTensor dense_x(alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 3}), + pten::framework::make_ddim({3, 3}), pten::DataLayout::NCHW)); auto* dense_x_data = @@ -42,7 +42,7 @@ TEST(DEV_API, dot) { DenseTensor dense_y(alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 3}), + pten::framework::make_ddim({3, 3}), pten::DataLayout::NCHW)); auto* dense_y_data = dense_y.mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/kernels/test_mean_dev_api.cc b/paddle/pten/tests/kernels/test_mean_dev_api.cc index 3abf54d26a..5360c711d0 100644 --- a/paddle/pten/tests/kernels/test_mean_dev_api.cc +++ b/paddle/pten/tests/kernels/test_mean_dev_api.cc @@ -32,10 +32,11 @@ TEST(DEV_API, mean) { // 1. create tensor const auto alloc = std::make_unique( paddle::platform::CPUPlace()); - pten::DenseTensor dense_x(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 4}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_x( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({3, 4}), + pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/kernels/test_reshape_dev_api.cc b/paddle/pten/tests/kernels/test_reshape_dev_api.cc index fe9b09c255..95eda3ef2d 100644 --- a/paddle/pten/tests/kernels/test_reshape_dev_api.cc +++ b/paddle/pten/tests/kernels/test_reshape_dev_api.cc @@ -36,7 +36,7 @@ TEST(DEV_API, reshape) { pten::DenseTensor dense_x( alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 2, 2, 3}), + pten::framework::make_ddim({3, 2, 2, 3}), pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); diff --git a/paddle/pten/tests/kernels/test_scale_dev_api.cc b/paddle/pten/tests/kernels/test_scale_dev_api.cc index 80f1295009..f27e1037d0 100644 --- a/paddle/pten/tests/kernels/test_scale_dev_api.cc +++ b/paddle/pten/tests/kernels/test_scale_dev_api.cc @@ -32,10 +32,11 @@ TEST(DEV_API, scale) { // 1. create tensor const auto alloc = std::make_unique( paddle::platform::CPUPlace()); - pten::DenseTensor dense_x(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 4}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_x( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({3, 4}), + pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); @@ -70,10 +71,11 @@ TEST(DEV_API, scale_host) { // 1. create tensor const auto alloc = std::make_unique( paddle::platform::CPUPlace()); - pten::DenseTensor dense_x(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 4}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_x( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({3, 4}), + pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); for (size_t i = 0; i < 12; ++i) { @@ -82,7 +84,7 @@ TEST(DEV_API, scale_host) { pten::DenseTensor scale(alloc.get(), pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({1}), + pten::framework::make_ddim({1}), pten::DataLayout::NCHW)); scale.data()[0] = 2; float bias = 1; diff --git a/paddle/pten/tests/kernels/test_sum_dev_api.cc b/paddle/pten/tests/kernels/test_sum_dev_api.cc index 9b48d8908f..023d62c7ed 100644 --- a/paddle/pten/tests/kernels/test_sum_dev_api.cc +++ b/paddle/pten/tests/kernels/test_sum_dev_api.cc @@ -31,10 +31,11 @@ TEST(DEV_API, sum) { // 1. create tensor const auto alloc = std::make_unique( paddle::platform::CPUPlace()); - pten::DenseTensor dense_x(alloc.get(), - pten::DenseTensorMeta(pten::DataType::FLOAT32, - framework::make_ddim({3, 4}), - pten::DataLayout::NCHW)); + pten::DenseTensor dense_x( + alloc.get(), + pten::DenseTensorMeta(pten::DataType::FLOAT32, + pten::framework::make_ddim({3, 4}), + pten::DataLayout::NCHW)); auto* dense_x_data = dense_x.mutable_data(paddle::platform::CPUPlace()); diff --git a/python/setup.py.in b/python/setup.py.in index 4fe4704ae1..d5b237d2a3 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -567,13 +567,15 @@ def find_files(pattern, root, recursive=False): break headers = ( + # paddle level api headers list(find_files('*.h', '@PADDLE_SOURCE_DIR@/paddle')) + list(find_files('*.h', '@PADDLE_SOURCE_DIR@/paddle/pten/api')) + # pten unify api header list(find_files('*.h', '@PADDLE_SOURCE_DIR@/paddle/pten/api/ext')) + # custom op api list(find_files('*.h', '@PADDLE_SOURCE_DIR@/paddle/pten/api/include')) + # pten api list(find_files('*.h', '@PADDLE_SOURCE_DIR@/paddle/pten/common')) + # pten common headers - # For paddle uew custom op, only copy data type headers from `paddle/fluid/platform` - # to `paddle/pten/api/ext`, + # pten level api headers (low level api) + list(find_files('*.h', '@PADDLE_SOURCE_DIR@/paddle/pten/core', recursive=True)) + # pten core headers + # utila api headers ['@PADDLE_SOURCE_DIR@/paddle/utils/any.h'] + ['@PADDLE_SOURCE_DIR@/paddle/utils/small_vector.h']) @@ -620,8 +622,6 @@ class InstallHeaders(Command): elif 'third_party' not in header: # paddle headers install_dir = re.sub('@PADDLE_SOURCE_DIR@/', '', header) - if 'fluid' in install_dir: - install_dir = "paddle/pten/common/" else: # third_party install_dir = re.sub('${THIRD_PARTY_PATH}', 'third_party', header) -- GitLab