From 99bf7007d0d04a80382f1b2d47ae41f7644340ea Mon Sep 17 00:00:00 2001 From: zmxdream Date: Wed, 20 Jul 2022 16:46:11 +0800 Subject: [PATCH] [GPUPS]Fix psgpuwrapper initialization (#44468) * Update ps_gpu_wrapper.h * Update ps_gpu_wrapper.h * Update ps_gpu_wrapper.cc --- paddle/fluid/framework/fleet/ps_gpu_wrapper.cc | 1 + paddle/fluid/framework/fleet/ps_gpu_wrapper.h | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/framework/fleet/ps_gpu_wrapper.cc b/paddle/fluid/framework/fleet/ps_gpu_wrapper.cc index d9bb6e946f..622793653d 100644 --- a/paddle/fluid/framework/fleet/ps_gpu_wrapper.cc +++ b/paddle/fluid/framework/fleet/ps_gpu_wrapper.cc @@ -95,6 +95,7 @@ int AfsWrapper::mv(const std::string& old_path, const std::string& dest_path) { std::shared_ptr PSGPUWrapper::s_instance_ = NULL; bool PSGPUWrapper::is_initialized_ = false; +std::mutex PSGPUWrapper::ins_mutex; #ifdef PADDLE_WITH_PSLIB void PSGPUWrapper::InitAfsApi(const std::string& fs_name, const std::string& fs_user, diff --git a/paddle/fluid/framework/fleet/ps_gpu_wrapper.h b/paddle/fluid/framework/fleet/ps_gpu_wrapper.h index 0d1669a42b..cce120bcef 100644 --- a/paddle/fluid/framework/fleet/ps_gpu_wrapper.h +++ b/paddle/fluid/framework/fleet/ps_gpu_wrapper.h @@ -20,6 +20,7 @@ limitations under the License. */ #include #include #include +#include #include #include #include @@ -429,8 +430,11 @@ class PSGPUWrapper { // PSGPUWrapper singleton static std::shared_ptr GetInstance() { - if (NULL == s_instance_) { - s_instance_.reset(new paddle::framework::PSGPUWrapper()); + { + std::lock_guard lk(ins_mutex); + if (NULL == s_instance_) { + s_instance_.reset(new paddle::framework::PSGPUWrapper()); + } } return s_instance_; } @@ -537,6 +541,7 @@ class PSGPUWrapper { private: static std::shared_ptr s_instance_; + static std::mutex ins_mutex; Dataset* dataset_; #ifdef PADDLE_WITH_PSLIB paddle::ps::AfsApiWrapper afs_handler_; -- GitLab