diff --git a/rocclr/platform/command.cpp b/rocclr/platform/command.cpp index ed0c5fa0f6..082deaacc9 100644 --- a/rocclr/platform/command.cpp +++ b/rocclr/platform/command.cpp @@ -145,7 +145,9 @@ bool Event::setStatus(int32_t status, uint64_t timeStamp) { if (status <= CL_COMPLETE) { // Before we notify the waiters that this event reached the CL_COMPLETE // status, we release all the resources associated with this instance. - releaseResources(); + if (!IS_HIP) { + releaseResources(); + } activity_.ReportEventTimestamps(command()); // Broadcast all the waiters. diff --git a/rocclr/platform/command.hpp b/rocclr/platform/command.hpp index 21bce75a09..ec9843a1bf 100644 --- a/rocclr/platform/command.hpp +++ b/rocclr/platform/command.hpp @@ -262,7 +262,10 @@ class Command : public Event { eventWaitList_(nullWaitList), commandWaitBits_(0) {} - bool terminate() { + virtual bool terminate() { + if (IS_HIP) { + releaseResources(); + } if (Agent::shouldPostEventEvents() && type() != 0) { Agent::postEventFree(as_cl(static_cast(this))); } diff --git a/rocclr/platform/commandqueue.cpp b/rocclr/platform/commandqueue.cpp index 85bb08979c..998dcb5048 100644 --- a/rocclr/platform/commandqueue.cpp +++ b/rocclr/platform/commandqueue.cpp @@ -123,6 +123,14 @@ void HostQueue::finish() { command->awaitCompletion(); } command->release(); + if (IS_HIP) { + ScopedLock sl(vdev()->execution()); + ScopedLock l(lastCmdLock_); + if (lastEnqueueCommand_ != nullptr) { + lastEnqueueCommand_->release(); + lastEnqueueCommand_ = nullptr; + } + } ClPrint(LOG_DEBUG, LOG_CMD, "All commands finished"); } @@ -238,7 +246,6 @@ Command* HostQueue::getLastQueuedCommand(bool retain) { // The batch update must be lock protected to avoid a race condition // when multiple threads submit/flush/update the batch at the same time ScopedLock sl(vdev()->execution()); - // Since the lastCmdLock_ is acquired, it is safe to read and retain the lastEnqueueCommand. // It is guaranteed that the pointer will not change. if (retain && lastEnqueueCommand_ != nullptr) {