From dfbdbfecb525d3377909920c45017a3c4e7d8750 Mon Sep 17 00:00:00 2001 From: Christophe Paquot Date: Wed, 16 Jun 2021 09:13:58 -0700 Subject: [PATCH] SWDEV-240806 - Release resources in Command::terminate for HIP We do not want to release resources during setStatus in HIP because of Graphs Change-Id: Idc7b188ab5f8be6975ea91005dd2bbf177401f8c [ROCm/clr commit: 133287f31f4fafbdf5b9c3c346ae835d9e56a2bc] --- projects/clr/rocclr/platform/command.cpp | 4 +++- projects/clr/rocclr/platform/command.hpp | 5 ++++- projects/clr/rocclr/platform/commandqueue.cpp | 9 ++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/projects/clr/rocclr/platform/command.cpp b/projects/clr/rocclr/platform/command.cpp index ed0c5fa0f6..082deaacc9 100644 --- a/projects/clr/rocclr/platform/command.cpp +++ b/projects/clr/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/projects/clr/rocclr/platform/command.hpp b/projects/clr/rocclr/platform/command.hpp index 21bce75a09..ec9843a1bf 100644 --- a/projects/clr/rocclr/platform/command.hpp +++ b/projects/clr/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/projects/clr/rocclr/platform/commandqueue.cpp b/projects/clr/rocclr/platform/commandqueue.cpp index 85bb08979c..998dcb5048 100644 --- a/projects/clr/rocclr/platform/commandqueue.cpp +++ b/projects/clr/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) {