diff --git a/hipamd/api/hip/hip_event.cpp b/hipamd/api/hip/hip_event.cpp index 1507629321..4d2eea3985 100644 --- a/hipamd/api/hip/hip_event.cpp +++ b/hipamd/api/hip/hip_event.cpp @@ -100,6 +100,12 @@ hipError_t Event::streamWait(hipStream_t stream, uint flags) { if (stream_ == hostQueue) return hipSuccess; amd::ScopedLock lock(lock_); + bool retain = false; + + if (event_ == nullptr) { + event_ = stream_->getLastQueuedCommand(true); + retain = true; + } if (!event_->notifyCmdQueue()) { return hipErrorUnknown; @@ -114,6 +120,11 @@ hipError_t Event::streamWait(hipStream_t stream, uint flags) { command->enqueue(); command->release(); + if (retain) { + event_->release(); + event_ = nullptr; + } + return hipSuccess; } diff --git a/hipamd/api/hip/hip_event.hpp b/hipamd/api/hip/hip_event.hpp index 953665ed5b..4c6fb132e8 100644 --- a/hipamd/api/hip/hip_event.hpp +++ b/hipamd/api/hip/hip_event.hpp @@ -39,7 +39,7 @@ public: class Event { public: - Event(unsigned int flags) : flags(flags), lock_("hipEvent_t"), stream_(nullptr), event_(nullptr) {} + Event(unsigned int flags) : flags(flags), lock_("hipEvent_t"), stream_(getNullStream()), event_(nullptr) {} ~Event() { if (event_ != nullptr) { event_->release();