From 562f3ef09834ea103efc41eda0d40e5890b09dac Mon Sep 17 00:00:00 2001 From: German Andryeyev Date: Tue, 16 Apr 2024 17:41:21 -0400 Subject: [PATCH] SWDEV-440746 - Fix the hostcall buffer creation Avoid a deadlock on the host call buffer creation. Since the buffer will be allocated in the queue thread, then use direct device memory allocation skipping the global context lock. Change-Id: I09b55ee03bb42ab5d320c152b52a8c842c5fdcc1 [ROCm/clr commit: 62559a6e5ab26880576cf1a80863ad8628a0deed] --- projects/clr/rocclr/device/devhostcall.cpp | 5 ++++- projects/clr/rocclr/device/pal/palvirtual.cpp | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/projects/clr/rocclr/device/devhostcall.cpp b/projects/clr/rocclr/device/devhostcall.cpp index ca68f3ede5..9a0fb9629b 100644 --- a/projects/clr/rocclr/device/devhostcall.cpp +++ b/projects/clr/rocclr/device/devhostcall.cpp @@ -284,7 +284,10 @@ static struct Init { ~Init() { if (state == State::kInit) { state = State::kDestroy; - while (state == State::kDestroy) {} + // @note: Under Linux thread destruction can be delayed and + // ROCR may crash in a wait for event occasionally. Hence, runtime needs + // an early exit. The logic isn't required for Windows. + while (IS_LINUX && (state == State::kDestroy)) {} } } } kHostThreadActive; diff --git a/projects/clr/rocclr/device/pal/palvirtual.cpp b/projects/clr/rocclr/device/pal/palvirtual.cpp index 388b68a028..a20577b24c 100644 --- a/projects/clr/rocclr/device/pal/palvirtual.cpp +++ b/projects/clr/rocclr/device/pal/palvirtual.cpp @@ -1154,7 +1154,7 @@ VirtualGPU::~VirtualGPU() { "deleting hostcall buffer %p for virtual queue %p", hostcallBuffer_, this); disableHostcalls(hostcallBuffer_); - dev().context().svmFree(hostcallBuffer_); + dev().svmFree(hostcallBuffer_); } } @@ -3766,7 +3766,8 @@ void* VirtualGPU::getOrCreateHostcallBuffer() { auto size = getHostcallBufferSize(numPackets); auto align = getHostcallBufferAlignment(); - hostcallBuffer_ = dev().context().svmAlloc(size, align, CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS); + hostcallBuffer_ = dev().svmAlloc(dev().context(), size, align, + CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS, nullptr); if (!hostcallBuffer_) { ClPrint(amd::LOG_ERROR, amd::LOG_QUEUE, "Failed to create hostcall buffer");