diff --git a/paddle/fluid/memory/allocation/stream_safe_cuda_allocator.cc b/paddle/fluid/memory/allocation/stream_safe_cuda_allocator.cc index 1967dd8502808835346fe5fd6fe84ac0404b1951..903f50d9a4cb7c69f09c2078dc3acfff83a24711 100644 --- a/paddle/fluid/memory/allocation/stream_safe_cuda_allocator.cc +++ b/paddle/fluid/memory/allocation/stream_safe_cuda_allocator.cc @@ -266,7 +266,7 @@ uint64_t StreamSafeCUDAAllocator::ProcessUnfreedAllocationsAndRelease() { return underlying_allocator_->Release(place_); } -std::once_flag StreamSafeCUDAAllocation::once_flag_; +thread_local std::once_flag StreamSafeCUDAAllocation::once_flag_; std::map> StreamSafeCUDAAllocator::allocator_map_; diff --git a/paddle/fluid/memory/allocation/stream_safe_cuda_allocator.h b/paddle/fluid/memory/allocation/stream_safe_cuda_allocator.h index 5f9b6208100d3904f6df491114cff9d222ecd412..08ecdd496973032c023699244ed407da92c8bac1 100644 --- a/paddle/fluid/memory/allocation/stream_safe_cuda_allocator.h +++ b/paddle/fluid/memory/allocation/stream_safe_cuda_allocator.h @@ -45,7 +45,7 @@ class StreamSafeCUDAAllocation : public Allocation { gpuStream_t GetOwningStream() const; private: - static std::once_flag once_flag_; + thread_local static std::once_flag once_flag_; void RecordGraphCapturingStreams(); void RecordStreamWithNoGraphCapturing(gpuStream_t stream); DecoratedAllocationPtr underlying_allocation_;