Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions paddle/fluid/platform/device_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ limitations under the License. */
#pragma once

#include <memory>
#include <mutex> // NOLINT
#include <string>
#include <unordered_map>
#include <vector>
Expand Down Expand Up @@ -100,6 +101,7 @@ class CUDADeviceContext : public DeviceContext {

template <typename Callback>
void RecordEvent(cudaEvent_t ev, Callback callback) {
std::lock_guard<std::mutex> guard(mtx_);
callback();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about replacing std::mutex with std::recursive_mutex? Because, if the callback() contains another RecordEvent() calling, it will be hang again.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This situation should not happen.

PADDLE_ENFORCE(cudaEventRecord(ev, stream_));
}
Expand All @@ -116,6 +118,8 @@ class CUDADeviceContext : public DeviceContext {
int compute_capability;
int multi_process;
int max_threads_per_mp;

std::mutex mtx_;
};

template <>
Expand Down