From 73f02aa6dca0647865284e07979210c5efdd80b2 Mon Sep 17 00:00:00 2001 From: German Date: Thu, 16 Feb 2023 15:48:57 -0500 Subject: [PATCH] SWDEV-382397 - Move VirtualGPU destruction back to the thread exit OS can terminate unfinished queue thread from default stream at any time. Potentially leaving the queue lock in a bad state and causing a deadlock if runtime destroys VirtualGPU later from the host thread. Change-Id: I247f102ee84e6b4dba947504933395071945c85d [ROCm/clr commit: 28daf98f1f258a242c275a922d37696420f8cafe] --- projects/clr/rocclr/platform/commandqueue.cpp | 1 + projects/clr/rocclr/platform/commandqueue.hpp | 10 +++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/projects/clr/rocclr/platform/commandqueue.cpp b/projects/clr/rocclr/platform/commandqueue.cpp index 90573b4cc5..8b27b4ce30 100644 --- a/projects/clr/rocclr/platform/commandqueue.cpp +++ b/projects/clr/rocclr/platform/commandqueue.cpp @@ -66,6 +66,7 @@ bool HostQueue::terminate() { marker->awaitCompletion(); marker->release(); } + thread_.Release(); thread_.acceptingCommands_ = false; } else { if (Os::isThreadAlive(thread_)) { diff --git a/projects/clr/rocclr/platform/commandqueue.hpp b/projects/clr/rocclr/platform/commandqueue.hpp index ea702a5eec..f98332bf33 100644 --- a/projects/clr/rocclr/platform/commandqueue.hpp +++ b/projects/clr/rocclr/platform/commandqueue.hpp @@ -164,19 +164,13 @@ class HostQueue : public CommandQueue { acceptingCommands_(false), virtualDevice_(nullptr) {} - virtual ~Thread() { - if (virtualDevice_ != nullptr) { - delete virtualDevice_; - virtualDevice_ = nullptr; - } - } - //! The command queue thread entry point. void run(void* data) { HostQueue* queue = static_cast(data); virtualDevice_ = queue->device().createVirtualDevice(queue); if (virtualDevice_ != nullptr) { queue->loop(virtualDevice_); + Release(); } else { acceptingCommands_ = false; queue->flush(); @@ -190,6 +184,8 @@ class HostQueue : public CommandQueue { } } + void Release() const { delete virtualDevice_; } + //! Get virtual device for the current thread device::VirtualDevice* vdev() const { return virtualDevice_; }