From 61a933acd5033414742b66c85b422604572183b9 Mon Sep 17 00:00:00 2001 From: HongyuJia Date: Tue, 14 Feb 2023 14:10:31 +0800 Subject: [PATCH] [Polish Namespace] Polish operants namespace (#50420) * polish namespace * change static_tensor_operants * polish namespace --- paddle/fluid/framework/custom_operator.cc | 7 +++---- paddle/fluid/prim/tests/init_env_utils.cc | 10 +++++----- paddle/fluid/prim/tests/test_static_prim.cc | 14 +++++++------- .../prim/utils/eager/eager_tensor_operants.cc | 4 ++-- .../prim/utils/eager/eager_tensor_operants.h | 9 ++++++--- .../prim/utils/static/static_tensor_operants.cc | 4 ++-- .../prim/utils/static/static_tensor_operants.h | 9 ++++++--- paddle/fluid/pybind/eager_functions.cc | 15 +++++++-------- paddle/phi/{core => api/include}/operants_base.h | 0 .../phi/{core => api/include}/operants_manager.h | 6 ++---- paddle/phi/api/include/tensor_operants.h | 2 +- paddle/phi/api/lib/CMakeLists.txt | 4 ++++ paddle/phi/{core => api/lib}/operants_manager.cc | 5 +---- paddle/phi/api/lib/tensor.cc | 4 ++-- paddle/phi/core/CMakeLists.txt | 5 ----- 15 files changed, 48 insertions(+), 50 deletions(-) rename paddle/phi/{core => api/include}/operants_base.h (100%) rename paddle/phi/{core => api/include}/operants_manager.h (95%) rename paddle/phi/{core => api/lib}/operants_manager.cc (96%) diff --git a/paddle/fluid/framework/custom_operator.cc b/paddle/fluid/framework/custom_operator.cc index 98d07da65e8..83d274789c5 100644 --- a/paddle/fluid/framework/custom_operator.cc +++ b/paddle/fluid/framework/custom_operator.cc @@ -46,8 +46,8 @@ limitations under the License. */ #endif #include "gflags/gflags.h" +#include "paddle/phi/api/include/operants_manager.h" #include "paddle/phi/api/include/tensor_operants.h" -#include "paddle/phi/core/operants_manager.h" DECLARE_string(tensor_operants_mode); @@ -278,9 +278,8 @@ static void RunKernelFunc(const framework::ExecutionContext& ctx, VLOG(3) << "Custom Operator: Run ComputeFunc."; FLAGS_tensor_operants_mode = "phi"; - if (paddle::operants::OperantsManager::Instance().phi_operants.get() == - nullptr) { - paddle::operants::OperantsManager::Instance().phi_operants.reset( + if (paddle::OperantsManager::Instance().phi_operants.get() == nullptr) { + paddle::OperantsManager::Instance().phi_operants.reset( new paddle::operants::PhiTensorOperants()); VLOG(4) << "Initialize phi tensor operants successfully"; } diff --git a/paddle/fluid/prim/tests/init_env_utils.cc b/paddle/fluid/prim/tests/init_env_utils.cc index 708c187e678..78479a8f728 100644 --- a/paddle/fluid/prim/tests/init_env_utils.cc +++ b/paddle/fluid/prim/tests/init_env_utils.cc @@ -15,16 +15,16 @@ #include "paddle/fluid/prim/tests/init_env_utils.h" #include "paddle/fluid/prim/utils/eager/eager_tensor_operants.h" #include "paddle/fluid/prim/utils/static/static_tensor_operants.h" -#include "paddle/phi/core/operants_manager.h" +#include "paddle/phi/api/include/operants_manager.h" namespace paddle { namespace prim { void InitTensorOperants() { - paddle::operants::OperantsManager::Instance().eager_operants.reset( - new paddle::operants::EagerTensorOperants()); - paddle::operants::OperantsManager::Instance().static_operants.reset( - new paddle::operants::StaticTensorOperants()); + paddle::OperantsManager::Instance().eager_operants.reset( + new paddle::prim::EagerTensorOperants()); + paddle::OperantsManager::Instance().static_operants.reset( + new paddle::prim::StaticTensorOperants()); } } // namespace prim diff --git a/paddle/fluid/prim/tests/test_static_prim.cc b/paddle/fluid/prim/tests/test_static_prim.cc index b93e16b507f..4ca26f87efb 100644 --- a/paddle/fluid/prim/tests/test_static_prim.cc +++ b/paddle/fluid/prim/tests/test_static_prim.cc @@ -23,9 +23,9 @@ #include "paddle/fluid/prim/utils/static/desc_tensor.h" #include "paddle/fluid/prim/utils/static/static_tensor_operants.h" #include "paddle/fluid/prim/utils/utils.h" +#include "paddle/phi/api/include/operants_manager.h" #include "paddle/phi/core/enforce.h" #include "paddle/phi/core/kernel_registry.h" -#include "paddle/phi/core/operants_manager.h" DECLARE_bool(prim_enabled); DECLARE_string(tensor_operants_mode); @@ -148,8 +148,8 @@ class TestCompositeGradMaker : public CompositeGradOpMakerBase { TEST(StaticPrim, TanhBackwardComposite) { // Initialized environment FLAGS_tensor_operants_mode = "static"; - paddle::operants::OperantsManager::Instance().static_operants.reset( - new paddle::operants::StaticTensorOperants()); + paddle::OperantsManager::Instance().static_operants.reset( + new paddle::prim::StaticTensorOperants()); TestBaseProgram base_program = TestBaseProgram(); auto* target_block = base_program.GetBlock(0); @@ -234,8 +234,8 @@ TEST(StaticPrim, TanhBackwardComposite) { TEST(StaticCompositeGradMaker, TestMutiInputMethod) { // Initialized environment FLAGS_tensor_operants_mode = "static"; - paddle::operants::OperantsManager::Instance().static_operants.reset( - new paddle::operants::StaticTensorOperants()); + paddle::OperantsManager::Instance().static_operants.reset( + new paddle::prim::StaticTensorOperants()); TestBaseProgram base_program = TestBaseProgram(); auto* target_block = base_program.GetBlock(0); @@ -301,8 +301,8 @@ TEST(StaticCompositeGradMaker, TestMutiInputMethod) { TEST(StaticCompositeGradMaker, TestMutiOutputMethod) { // Initialized environment FLAGS_tensor_operants_mode = "static"; - paddle::operants::OperantsManager::Instance().static_operants.reset( - new paddle::operants::StaticTensorOperants()); + paddle::OperantsManager::Instance().static_operants.reset( + new paddle::prim::StaticTensorOperants()); TestBaseProgram base_program = TestBaseProgram(); auto* target_block = base_program.GetBlock(0); diff --git a/paddle/fluid/prim/utils/eager/eager_tensor_operants.cc b/paddle/fluid/prim/utils/eager/eager_tensor_operants.cc index e42a0d6dd91..fa25334d334 100644 --- a/paddle/fluid/prim/utils/eager/eager_tensor_operants.cc +++ b/paddle/fluid/prim/utils/eager/eager_tensor_operants.cc @@ -19,11 +19,11 @@ namespace paddle { -namespace operants { +namespace prim { Tensor EagerTensorOperants::multiply(const Tensor& x, const Tensor& y) { return ::multiply_ad_func(x, y); } -} // namespace operants +} // namespace prim } // namespace paddle diff --git a/paddle/fluid/prim/utils/eager/eager_tensor_operants.h b/paddle/fluid/prim/utils/eager/eager_tensor_operants.h index b7571de350f..86cd41496bd 100644 --- a/paddle/fluid/prim/utils/eager/eager_tensor_operants.h +++ b/paddle/fluid/prim/utils/eager/eager_tensor_operants.h @@ -14,13 +14,16 @@ #pragma once +#include "paddle/phi/api/include/operants_base.h" #include "paddle/phi/api/include/tensor.h" #include "paddle/phi/core/macros.h" -#include "paddle/phi/core/operants_base.h" namespace paddle { -namespace operants { +namespace prim { + +using Tensor = paddle::experimental::Tensor; +using TensorOperantsBase = paddle::operants::TensorOperantsBase; class EagerTensorOperants : public TensorOperantsBase { public: @@ -32,5 +35,5 @@ class EagerTensorOperants : public TensorOperantsBase { DISABLE_COPY_AND_ASSIGN(EagerTensorOperants); }; -} // namespace operants +} // namespace prim } // namespace paddle diff --git a/paddle/fluid/prim/utils/static/static_tensor_operants.cc b/paddle/fluid/prim/utils/static/static_tensor_operants.cc index ada4cca58a9..3697c1ee555 100644 --- a/paddle/fluid/prim/utils/static/static_tensor_operants.cc +++ b/paddle/fluid/prim/utils/static/static_tensor_operants.cc @@ -20,12 +20,12 @@ namespace paddle { -namespace operants { +namespace prim { using DescTensor = paddle::prim::DescTensor; Tensor StaticTensorOperants::multiply(const Tensor& x, const Tensor& y) { return paddle::prim::multiply(x, y); } -} // namespace operants +} // namespace prim } // namespace paddle diff --git a/paddle/fluid/prim/utils/static/static_tensor_operants.h b/paddle/fluid/prim/utils/static/static_tensor_operants.h index 26365fcf233..f11cec8895c 100644 --- a/paddle/fluid/prim/utils/static/static_tensor_operants.h +++ b/paddle/fluid/prim/utils/static/static_tensor_operants.h @@ -14,13 +14,16 @@ #pragma once +#include "paddle/phi/api/include/operants_base.h" #include "paddle/phi/api/include/tensor.h" #include "paddle/phi/core/macros.h" -#include "paddle/phi/core/operants_base.h" namespace paddle { -namespace operants { +namespace prim { + +using Tensor = paddle::experimental::Tensor; +using TensorOperantsBase = paddle::operants::TensorOperantsBase; class StaticTensorOperants : public TensorOperantsBase { public: @@ -32,5 +35,5 @@ class StaticTensorOperants : public TensorOperantsBase { DISABLE_COPY_AND_ASSIGN(StaticTensorOperants); }; -} // namespace operants +} // namespace prim } // namespace paddle diff --git a/paddle/fluid/pybind/eager_functions.cc b/paddle/fluid/pybind/eager_functions.cc index 97343b51142..aeb9f048a80 100644 --- a/paddle/fluid/pybind/eager_functions.cc +++ b/paddle/fluid/pybind/eager_functions.cc @@ -61,8 +61,8 @@ typedef SSIZE_T ssize_t; #endif #include "gflags/gflags.h" +#include "paddle/phi/api/include/operants_manager.h" #include "paddle/phi/api/include/tensor_operants.h" -#include "paddle/phi/core/operants_manager.h" DECLARE_string(tensor_operants_mode); @@ -503,10 +503,10 @@ static PyObject* eager_api_init_eager_and_static_tensor_operants( PyObject* self, PyObject* args, PyObject* kwargs) { EAGER_TRY - paddle::operants::OperantsManager::Instance().eager_operants.reset( - new paddle::operants::EagerTensorOperants()); - paddle::operants::OperantsManager::Instance().static_operants.reset( - new paddle::operants::StaticTensorOperants()); + paddle::OperantsManager::Instance().eager_operants.reset( + new paddle::prim::EagerTensorOperants()); + paddle::OperantsManager::Instance().static_operants.reset( + new paddle::prim::StaticTensorOperants()); VLOG(4) << "Initialize eager and static tensor operants successfully"; RETURN_PY_NONE @@ -518,9 +518,8 @@ static PyObject* eager_api_run_custom_op(PyObject* self, PyObject* kwargs) { EAGER_TRY FLAGS_tensor_operants_mode = "phi"; - if (paddle::operants::OperantsManager::Instance().phi_operants.get() == - nullptr) { - paddle::operants::OperantsManager::Instance().phi_operants.reset( + if (paddle::OperantsManager::Instance().phi_operants.get() == nullptr) { + paddle::OperantsManager::Instance().phi_operants.reset( new paddle::operants::PhiTensorOperants()); VLOG(4) << "Initialize phi tensor operants successfully"; } diff --git a/paddle/phi/core/operants_base.h b/paddle/phi/api/include/operants_base.h similarity index 100% rename from paddle/phi/core/operants_base.h rename to paddle/phi/api/include/operants_base.h diff --git a/paddle/phi/core/operants_manager.h b/paddle/phi/api/include/operants_manager.h similarity index 95% rename from paddle/phi/core/operants_manager.h rename to paddle/phi/api/include/operants_manager.h index 5bed59d6591..39181973729 100644 --- a/paddle/phi/core/operants_manager.h +++ b/paddle/phi/api/include/operants_manager.h @@ -14,15 +14,14 @@ #pragma once +#include "paddle/phi/api/include/operants_base.h" #include "paddle/phi/api/include/tensor.h" #include "paddle/phi/core/macros.h" -#include "paddle/phi/core/operants_base.h" namespace paddle { -namespace operants { - using Tensor = paddle::experimental::Tensor; +using TensorOperantsBase = paddle::operants::TensorOperantsBase; /** * [ Why need OperantsManager? ] @@ -73,5 +72,4 @@ class OperantsManager { DISABLE_COPY_AND_ASSIGN(OperantsManager); }; -} // namespace operants } // namespace paddle diff --git a/paddle/phi/api/include/tensor_operants.h b/paddle/phi/api/include/tensor_operants.h index 89ac46a1953..f801e9cd42d 100644 --- a/paddle/phi/api/include/tensor_operants.h +++ b/paddle/phi/api/include/tensor_operants.h @@ -14,9 +14,9 @@ #pragma once +#include "paddle/phi/api/include/operants_base.h" #include "paddle/phi/api/include/tensor.h" #include "paddle/phi/core/macros.h" -#include "paddle/phi/core/operants_base.h" namespace paddle { diff --git a/paddle/phi/api/lib/CMakeLists.txt b/paddle/phi/api/lib/CMakeLists.txt index f6ade16361e..7906a14d1f6 100644 --- a/paddle/phi/api/lib/CMakeLists.txt +++ b/paddle/phi/api/lib/CMakeLists.txt @@ -316,3 +316,7 @@ cc_library( phi_tensor_operants SRCS tensor_operants.cc DEPS phi_function_api) +cc_library( + operants_manager + SRCS operants_manager.cc + DEPS flags) diff --git a/paddle/phi/core/operants_manager.cc b/paddle/phi/api/lib/operants_manager.cc similarity index 96% rename from paddle/phi/core/operants_manager.cc rename to paddle/phi/api/lib/operants_manager.cc index 14db7320de7..ba68f68d47d 100644 --- a/paddle/phi/core/operants_manager.cc +++ b/paddle/phi/api/lib/operants_manager.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/phi/core/operants_manager.h" +#include "paddle/phi/api/include/operants_manager.h" #include "gflags/gflags.h" #include "glog/logging.h" @@ -23,8 +23,6 @@ DECLARE_string(tensor_operants_mode); namespace paddle { -namespace operants { - OperantsManager& OperantsManager::Instance() { static OperantsManager g_op_manager; return g_op_manager; @@ -63,5 +61,4 @@ Tensor OperantsManager::multiply(const Tensor& x, const Tensor& y) { } } -} // namespace operants } // namespace paddle diff --git a/paddle/phi/api/lib/tensor.cc b/paddle/phi/api/lib/tensor.cc index d1883b5b87a..e1b68e03a8b 100644 --- a/paddle/phi/api/lib/tensor.cc +++ b/paddle/phi/api/lib/tensor.cc @@ -21,13 +21,13 @@ limitations under the License. */ #include "glog/logging.h" #include "paddle/phi/api/include/context_pool.h" +#include "paddle/phi/api/include/operants_manager.h" #include "paddle/phi/api/lib/utils/allocator.h" #include "paddle/phi/backends/gpu/gpu_context.h" #include "paddle/phi/backends/gpu/gpu_info.h" #include "paddle/phi/core/ddim.h" #include "paddle/phi/core/dense_tensor.h" #include "paddle/phi/core/enforce.h" -#include "paddle/phi/core/operants_manager.h" #include "paddle/phi/core/selected_rows.h" #include "paddle/phi/core/sparse_coo_tensor.h" #include "paddle/phi/core/sparse_csr_tensor.h" @@ -435,7 +435,7 @@ void Tensor::reset_inplace_version(bool set_to_zero) { } PADDLE_API Tensor operator*(const Tensor &x, const Tensor &y) { - return paddle::operants::OperantsManager::Instance().multiply(x, y); + return paddle::OperantsManager::Instance().multiply(x, y); } } // namespace experimental diff --git a/paddle/phi/core/CMakeLists.txt b/paddle/phi/core/CMakeLists.txt index 48a8779de12..85df40cc47c 100644 --- a/paddle/phi/core/CMakeLists.txt +++ b/paddle/phi/core/CMakeLists.txt @@ -114,11 +114,6 @@ cc_library( SRCS custom_kernel.cc DEPS kernel_factory) -cc_library( - operants_manager - SRCS operants_manager.cc - DEPS phi_enforce) - cc_library( mixed_vector SRCS mixed_vector.cc -- GitLab