From d491dbd7965b7ce395f2b6b0c1c772ea2c4de917 Mon Sep 17 00:00:00 2001 From: German Andryeyev Date: Wed, 15 Jul 2020 15:11:59 -0400 Subject: [PATCH] Grab the event lock before fetching the last command Hip applications assume that hipEventRecord called from multiple threads will contain exactly the last queued command to the stream. Change-Id: I1da3259f143d7670d0870d9a47c08e32336b2222 --- rocclr/hip_event.cpp | 7 +++++-- rocclr/hip_event.hpp | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/rocclr/hip_event.cpp b/rocclr/hip_event.cpp index d4aca089ed..a9ea30e15c 100644 --- a/rocclr/hip_event.cpp +++ b/rocclr/hip_event.cpp @@ -230,6 +230,7 @@ hipError_t hipEventElapsedTime(float *ms, hipEvent_t start, hipEvent_t stop) { HIP_RETURN(eStart->elapsedTime(*eStop, *ms), "Elapsed Time = ", *ms); } +// ================================================================================================ hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream) { HIP_INIT_API(hipEventRecord, event, stream); @@ -237,6 +238,9 @@ hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream) { HIP_RETURN(hipErrorInvalidHandle); } + hip::Event* e = reinterpret_cast(event); + amd::ScopedLock lock(e->lock()); + amd::HostQueue* queue = hip::getQueue(stream); amd::Command* command = queue->getLastQueuedCommand(true); if (command == nullptr) { @@ -244,12 +248,11 @@ hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream) { command->enqueue(); } - hip::Event* e = reinterpret_cast(event); e->addMarker(queue, command, true); - HIP_RETURN(hipSuccess); } +// ================================================================================================ hipError_t hipEventSynchronize(hipEvent_t event) { HIP_INIT_API(hipEventSynchronize, event); diff --git a/rocclr/hip_event.hpp b/rocclr/hip_event.hpp index 78e081d4dc..dbd43b1a5c 100644 --- a/rocclr/hip_event.hpp +++ b/rocclr/hip_event.hpp @@ -37,7 +37,7 @@ public: class Event { public: - Event(unsigned int flags) : flags(flags), lock_("hipEvent_t"), + Event(unsigned int flags) : flags(flags), lock_("hipEvent_t", true), event_(nullptr), recorded_(false) { // No need to init event_ here as addMarker does that } @@ -56,6 +56,8 @@ public: void addMarker(amd::HostQueue* queue, amd::Command* command, bool record); + amd::Monitor& lock() { return lock_; } + private: amd::Monitor lock_; amd::HostQueue* stream_;