From 2ccbb9aeeef64c4134399e7efac271c7b0fedac9 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Fri, 14 Jun 2024 10:54:08 +0100 Subject: [PATCH] Merge pull request #1749 from nrspruit/fix_NonBlocking_LastCommand [L0] Maintain Lock of Queue while syncing the Last Command Event and update Last Command Event only if matching --- source/adapters/level_zero/queue.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/source/adapters/level_zero/queue.cpp b/source/adapters/level_zero/queue.cpp index 877d9c101e..89c06f55a5 100644 --- a/source/adapters/level_zero/queue.cpp +++ b/source/adapters/level_zero/queue.cpp @@ -1651,15 +1651,9 @@ ur_result_t ur_queue_handle_t_::synchronize() { // If event is discarded then it can be in reset state or underlying level // zero handle can have device scope, so we can't synchronize the last // event. + auto savedLastCommandEvent = LastCommandEvent; if (isInOrderQueue() && !LastCommandEvent->IsDiscarded) { - if (UrL0QueueSyncNonBlocking) { - auto SyncZeEvent = LastCommandEvent->ZeEvent; - this->Mutex.unlock(); - ZE2UR_CALL(zeHostSynchronize, (SyncZeEvent)); - this->Mutex.lock(); - } else { - ZE2UR_CALL(zeHostSynchronize, (LastCommandEvent->ZeEvent)); - } + ZE2UR_CALL(zeHostSynchronize, (LastCommandEvent->ZeEvent)); // clean up all events known to have been completed as well, // so they can be reused later @@ -1699,7 +1693,12 @@ ur_result_t ur_queue_handle_t_::synchronize() { } } } - LastCommandEvent = nullptr; + // If the current version of the LastCommandEvent == savedLastCommandEvent, + // then LastCommandEvent = nullptr; Otherwise, if LastCommandEvent != + // savedLastCommandEvent, then LastCommandEvent is unchanged. + if (LastCommandEvent == savedLastCommandEvent) { + LastCommandEvent = nullptr; + } } // With the entire queue synchronized, the active barriers must be done so we