From a1254a86bab4fd99a7801fd3eb3f3cccb0130ba1 Mon Sep 17 00:00:00 2001 From: yuyang18 Date: Mon, 11 Jun 2018 12:43:41 +0800 Subject: [PATCH] Add lock to record_event. --- paddle/fluid/platform/device_context.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/paddle/fluid/platform/device_context.h b/paddle/fluid/platform/device_context.h index 6b82d93237b..292ffef1aef 100644 --- a/paddle/fluid/platform/device_context.h +++ b/paddle/fluid/platform/device_context.h @@ -11,6 +11,7 @@ limitations under the License. */ #pragma once #include +#include // NOLINT #include #include #include @@ -100,6 +101,7 @@ class CUDADeviceContext : public DeviceContext { template void RecordEvent(cudaEvent_t ev, Callback callback) { + std::lock_guard guard(mtx_); callback(); PADDLE_ENFORCE(cudaEventRecord(ev, stream_)); } @@ -116,6 +118,8 @@ class CUDADeviceContext : public DeviceContext { int compute_capability; int multi_process; int max_threads_per_mp; + + std::mutex mtx_; }; template <> -- GitLab