From 73ec9b78d169046baad998e13b8fc6fb8be73ac0 Mon Sep 17 00:00:00 2001 From: Ruibiao Chen Date: Fri, 16 Dec 2022 10:18:28 +0800 Subject: [PATCH] Set once_flag to thread_local for StreamSafeCUDAAllcation (#49104) --- paddle/fluid/memory/allocation/stream_safe_cuda_allocator.cc | 2 +- paddle/fluid/memory/allocation/stream_safe_cuda_allocator.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/memory/allocation/stream_safe_cuda_allocator.cc b/paddle/fluid/memory/allocation/stream_safe_cuda_allocator.cc index 1967dd8502..903f50d9a4 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 5f9b620810..08ecdd4969 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_; -- GitLab