Skip to content

Commit

Permalink
Merge pull request #2481 from Bensuo/fabio/fix_potential_race_condition
Browse files Browse the repository at this point in the history
Fix potential deadlock in the WaitEvent path of CmdBuffers
  • Loading branch information
martygrant authored Jan 3, 2025
2 parents 9c68315 + 017d9cc commit ab5e53f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions source/adapters/level_zero/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1682,25 +1682,28 @@ 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,
(SignalCommandList->first, CommandBuffer->AllResetEvent->ZeEvent));

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*/));

Expand Down

0 comments on commit ab5e53f

Please sign in to comment.