未验证 提交 f421741c 编写于 作者: Z Zeng Jinle 提交者: GitHub

fix generator thread safety bug (#34888)

上级 ac56d54e
......@@ -156,17 +156,15 @@ uint64_t Generator::Random64() {
std::pair<uint64_t, uint64_t> 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<std::mutex> 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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册