From 017d9cc0d612f2d5c11ffcd2f8ea18075caa5e11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Mestre?= Date: Wed, 18 Dec 2024 17:57:59 +0000 Subject: [PATCH] Move event resets from SignalCommandList to ComputeCommandList Moves the call to event reset for the WaitEvent and AllResetEvent to the ComputeCommandList. This fixes a potential race condition where, if the SignalCommandList executes before the ComputeCommandList, the WaitEvent could be reset before the ComputeCommandList can wait on it and, consequently, create a deadlock. --- source/adapters/level_zero/command_buffer.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/source/adapters/level_zero/command_buffer.cpp b/source/adapters/level_zero/command_buffer.cpp index b96aeeede9..e678deb3e5 100644 --- a/source/adapters/level_zero/command_buffer.cpp +++ b/source/adapters/level_zero/command_buffer.cpp @@ -1683,10 +1683,15 @@ ur_result_t enqueueWaitEventPath(ur_exp_command_buffer_handle_t CommandBuffer, (ZeCopyCommandQueue, 1, &CommandBuffer->ZeCopyCommandList, nullptr)); } + ZE2UR_CALL(zeCommandListAppendBarrier, + (SignalCommandList->first, nullptr, 1, + &(CommandBuffer->ExecutionFinishedEvent->ZeEvent))); + // Reset the wait-event for the UR command-buffer that is signaled when its // submission dependencies have been satisfied. ZE2UR_CALL(zeCommandListAppendEventReset, (SignalCommandList->first, CommandBuffer->WaitEvent->ZeEvent)); + // Reset the all-reset-event for the UR command-buffer that is signaled when // all events of the main command-list have been reset. ZE2UR_CALL(zeCommandListAppendEventReset, @@ -1694,14 +1699,12 @@ ur_result_t enqueueWaitEventPath(ur_exp_command_buffer_handle_t CommandBuffer, if (DoProfiling) { UR_CALL(appendProfilingQueries(CommandBuffer, SignalCommandList->first, - *Event, - CommandBuffer->ExecutionFinishedEvent)); - } else { - ZE2UR_CALL(zeCommandListAppendBarrier, - (SignalCommandList->first, (*Event)->ZeEvent, 1, - &(CommandBuffer->ExecutionFinishedEvent->ZeEvent))); + nullptr, nullptr)); } + ZE2UR_CALL(zeCommandListAppendBarrier, + (SignalCommandList->first, (*Event)->ZeEvent, 0, nullptr)); + UR_CALL(Queue->executeCommandList(SignalCommandList, false /*IsBlocking*/, false /*OKToBatchCommand*/));