Skip to content

Commit 3fd3e50

Browse files
authored
Merge pull request #11346 from reyoung/feature/add_lock_to_device_ctx
Add lock to record_event.
2 parents 4581524 + a1254a8 commit 3fd3e50

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

paddle/fluid/platform/device_context.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ limitations under the License. */
1111
#pragma once
1212

1313
#include <memory>
14+
#include <mutex> // NOLINT
1415
#include <string>
1516
#include <unordered_map>
1617
#include <vector>
@@ -100,6 +101,7 @@ class CUDADeviceContext : public DeviceContext {
100101

101102
template <typename Callback>
102103
void RecordEvent(cudaEvent_t ev, Callback callback) {
104+
std::lock_guard<std::mutex> guard(mtx_);
103105
callback();
104106
PADDLE_ENFORCE(cudaEventRecord(ev, stream_));
105107
}
@@ -116,6 +118,8 @@ class CUDADeviceContext : public DeviceContext {
116118
int compute_capability;
117119
int multi_process;
118120
int max_threads_per_mp;
121+
122+
std::mutex mtx_;
119123
};
120124

121125
template <>

0 commit comments

Comments
 (0)