From 7fe7eebc58af5a66d62cf5e9a42b5c3ace4cab9e Mon Sep 17 00:00:00 2001 From: LiYuRio <63526175+LiYuRio@users.noreply.github.com> Date: Fri, 4 Nov 2022 13:13:43 +0800 Subject: [PATCH] remove global var (#47659) --- paddle/fluid/distributed/collective/ProcessGroup.h | 2 +- .../fluid/distributed/collective/ProcessGroupCustom.h | 4 +--- paddle/fluid/distributed/collective/ProcessGroupGloo.h | 6 +----- paddle/fluid/distributed/collective/ProcessGroupHCCL.h | 10 +++------- .../fluid/distributed/collective/ProcessGroupHeter.h | 6 +----- paddle/fluid/distributed/collective/ProcessGroupMPI.h | 6 +----- paddle/fluid/distributed/collective/ProcessGroupNCCL.h | 6 +----- 7 files changed, 9 insertions(+), 31 deletions(-) diff --git a/paddle/fluid/distributed/collective/ProcessGroup.h b/paddle/fluid/distributed/collective/ProcessGroup.h index afe75baeb2..3926ce16f1 100644 --- a/paddle/fluid/distributed/collective/ProcessGroup.h +++ b/paddle/fluid/distributed/collective/ProcessGroup.h @@ -92,7 +92,7 @@ class ProcessGroup { int GetSize() const { return size_; } - virtual const std::string GetBackendName() const = 0; + virtual std::string GetBackendName() const = 0; virtual const phi::DeviceContext& GetDeviceContext(const Place& place) const { PADDLE_THROW(platform::errors::InvalidArgument( "Does not support to get device_context from ProcessGroup%s.", diff --git a/paddle/fluid/distributed/collective/ProcessGroupCustom.h b/paddle/fluid/distributed/collective/ProcessGroupCustom.h index 38a794a0e7..15d6193237 100644 --- a/paddle/fluid/distributed/collective/ProcessGroupCustom.h +++ b/paddle/fluid/distributed/collective/ProcessGroupCustom.h @@ -69,9 +69,7 @@ class ProcessGroupCustom : public ProcessGroup { const platform::Place& place, int gid); - const std::string GetBackendName() const override { - return "XCCL_" + device_type_; - } + std::string GetBackendName() const override { return "XCCL_" + device_type_; } std::shared_ptr AllGather( std::vector& in_tensors, diff --git a/paddle/fluid/distributed/collective/ProcessGroupGloo.h b/paddle/fluid/distributed/collective/ProcessGroupGloo.h index f20f39b31a..d7412a1975 100644 --- a/paddle/fluid/distributed/collective/ProcessGroupGloo.h +++ b/paddle/fluid/distributed/collective/ProcessGroupGloo.h @@ -26,8 +26,6 @@ #include "paddle/fluid/distributed/store/store.h" #include "paddle/fluid/distributed/store/tcp_store.h" -constexpr const char* GLOO_BACKEND_NAME = "GLOO"; - namespace paddle { namespace distributed { @@ -146,9 +144,7 @@ class ProcessGroupGloo : public ProcessGroup { std::shared_ptr<::gloo::Context> get_context() { return _context; } uint64_t next_tag() { return _tag++; } - const std::string GetBackendName() const override { - return GLOO_BACKEND_NAME; - } + std::string GetBackendName() const override { return "GLOO"; } const phi::DeviceContext& GetDeviceContext( const Place& place) const override { diff --git a/paddle/fluid/distributed/collective/ProcessGroupHCCL.h b/paddle/fluid/distributed/collective/ProcessGroupHCCL.h index b1aea13f99..06ef3089b1 100644 --- a/paddle/fluid/distributed/collective/ProcessGroupHCCL.h +++ b/paddle/fluid/distributed/collective/ProcessGroupHCCL.h @@ -30,8 +30,6 @@ #include "paddle/fluid/platform/gen_comm_id_helper.h" #include "paddle/fluid/platform/place.h" -constexpr const char* HCCL_BACKEND_NAME = "HCCL"; - namespace paddle { namespace distributed { @@ -77,9 +75,7 @@ class ProcessGroupHCCL : public ProcessGroup { const platform::Place& place, int gid); - const std::string GetBackendName() const override { - return std::string(HCCL_BACKEND_NAME); - } + std::string GetBackendName() const override { return "HCCL"; } std::shared_ptr AllReduce( std::vector& in_tensors, @@ -114,8 +110,8 @@ class ProcessGroupHCCL : public ProcessGroup { std::set used_place_ids_; private: - void BcastHCCLId(std::vector& hccl_ids, - int root, // NOLINT + void BcastHCCLId(std::vector& hccl_ids, // NOLINT + int root, // NOLINT int server_fd); void BroadcastUniqueHCCLID(std::vector& hccl_ids); // NOLINT diff --git a/paddle/fluid/distributed/collective/ProcessGroupHeter.h b/paddle/fluid/distributed/collective/ProcessGroupHeter.h index 12a568f5ac..c910466787 100644 --- a/paddle/fluid/distributed/collective/ProcessGroupHeter.h +++ b/paddle/fluid/distributed/collective/ProcessGroupHeter.h @@ -58,8 +58,6 @@ #include "paddle/fluid/distributed/collective/Common.h" -constexpr const char* HETER_BACKEND_NAME = "HETER_BACKEND"; - namespace paddle { namespace distributed { @@ -99,9 +97,7 @@ class ProcessGroupHeter : public ProcessGroup { int src_rank, int dst_rank); - const std::string GetBackendName() const override { - return std::string(HETER_BACKEND_NAME); - } + std::string GetBackendName() const override { return "HETER_BACKEND"; } std::shared_ptr AllReduce( std::vector&, diff --git a/paddle/fluid/distributed/collective/ProcessGroupMPI.h b/paddle/fluid/distributed/collective/ProcessGroupMPI.h index 6a23b2fbb0..d877f856dc 100644 --- a/paddle/fluid/distributed/collective/ProcessGroupMPI.h +++ b/paddle/fluid/distributed/collective/ProcessGroupMPI.h @@ -33,8 +33,6 @@ #include "paddle/fluid/distributed/collective/MPITools.h" #endif -constexpr const char* MPI_BACKEND_NAME = "MPI"; - namespace paddle { namespace distributed { @@ -137,9 +135,7 @@ class ProcessGroupMPI : public ProcessGroup { virtual ~ProcessGroupMPI(); - const std::string GetBackendName() const override { - return std::string(MPI_BACKEND_NAME); - } + std::string GetBackendName() const override { return "MPI"; } std::shared_ptr AllReduce( std::vector& in_tensors, diff --git a/paddle/fluid/distributed/collective/ProcessGroupNCCL.h b/paddle/fluid/distributed/collective/ProcessGroupNCCL.h index a501bf5302..8be5a63c1a 100644 --- a/paddle/fluid/distributed/collective/ProcessGroupNCCL.h +++ b/paddle/fluid/distributed/collective/ProcessGroupNCCL.h @@ -39,8 +39,6 @@ #include "paddle/fluid/platform/dynload/nccl.h" #endif -constexpr const char* NCCL_BACKEND_NAME = "NCCL"; - namespace paddle { namespace distributed { @@ -94,9 +92,7 @@ class ProcessGroupNCCL : public ProcessGroupStream { const platform::Place& place, int gid); - const std::string GetBackendName() const override { - return std::string(NCCL_BACKEND_NAME); - } + std::string GetBackendName() const override { return "NCCL"; } const phi::DeviceContext& GetDeviceContext(const Place& place) const override; -- GitLab