From f421741cfa5ce53470540c02ff20408f4d9ca82e Mon Sep 17 00:00:00 2001 From: Zeng Jinle <32832641+sneaxiy@users.noreply.github.com> Date: Fri, 13 Aug 2021 17:54:41 +0800 Subject: [PATCH] fix generator thread safety bug (#34888) --- paddle/fluid/framework/generator.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/framework/generator.cc b/paddle/fluid/framework/generator.cc index 737dbafb64c..4b64722a7ab 100644 --- a/paddle/fluid/framework/generator.cc +++ b/paddle/fluid/framework/generator.cc @@ -156,17 +156,15 @@ uint64_t Generator::Random64() { std::pair Generator::IncrementOffset( uint64_t increament_offset) { - uint64_t cur_offset = this->state_.thread_offset; #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) std::lock_guard lock(this->mu_); - + uint64_t cur_offset = this->state_.thread_offset; this->state_.thread_offset += increament_offset; - + return std::make_pair(this->state_.current_seed, cur_offset); #else PADDLE_THROW(platform::errors::PermissionDenied( "Increment Offset only support in CUDA place")); #endif - return std::make_pair(this->state_.current_seed, cur_offset); } void Generator::SetIsInitPy(bool is_init_py) { -- GitLab