From b48b401a09323d040e86f6024f02bec89238d2ba Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Tue, 29 Apr 2025 14:47:25 +0000 Subject: [PATCH] rocr: Fix logic for scratch reclaim Fix logic error that can cause scratch memory to be reclaimed while a dispatch is still using it. [ROCm/ROCR-Runtime commit: 4ed5950beb1c0af8595fe365506491365e16392d] --- .../runtime/hsa-runtime/core/runtime/amd_aql_queue.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_aql_queue.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_aql_queue.cpp index 95e759ebad..a4ff1577ac 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_aql_queue.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_aql_queue.cpp @@ -934,11 +934,10 @@ void AqlQueue::AsyncReclaimMainScratch() { */ amd_queue_.scratch_max_use_index = getMaxMainScratchUseIndex(); - Resume(); // If current dispatch is using scratch, wait for it to finish - while (amd_queue_.scratch_max_use_index > amd_queue_.read_dispatch_id) { + while (amd_queue_.scratch_max_use_index >= LoadReadIndexRelaxed()) { //TODO: if mwaitx supported, //mwaitx(amd_queue_.read_dispatch_id); os::YieldThread(); } @@ -994,8 +993,8 @@ void AqlQueue::AsyncReclaimAltScratch() { Resume(); // If current dispatch is using alt scratch, wait for it to finish - while (amd_queue_.alt_scratch_max_use_index > amd_queue_.read_dispatch_id) { - //DYSDEBUG TODO: if mwaitx supported, //mwaitx(amd_queue_.read_dispatch_id); + while (amd_queue_.alt_scratch_max_use_index >= LoadReadIndexRelaxed()) { + //TODO: if mwaitx supported, //mwaitx(amd_queue_.read_dispatch_id); os::YieldThread(); }