diff --git a/unified-runtime/source/adapters/level_zero/event.cpp b/unified-runtime/source/adapters/level_zero/event.cpp index c53bfa1089100..ce81dee43caa5 100644 --- a/unified-runtime/source/adapters/level_zero/event.cpp +++ b/unified-runtime/source/adapters/level_zero/event.cpp @@ -75,76 +75,48 @@ ur_result_t urEnqueueEventsWait( /// [in,out][optional] return an event object that identifies this /// particular command instance. ur_event_handle_t *OutEvent) { - if (EventWaitList) { - bool UseCopyEngine = false; + bool UseCopyEngine = false; - // Lock automatically releases when this goes out of scope. - std::scoped_lock lock(Queue->Mutex); + // Lock automatically releases when this goes out of scope. + std::scoped_lock lock(Queue->Mutex); - ur_ze_event_list_t TmpWaitList = {}; + ur_command_list_ptr_t CommandList{}; + ur_ze_event_list_t TmpWaitList = {}; + if (NumEventsInWaitList) { UR_CALL(TmpWaitList.createAndRetainUrZeEventList( NumEventsInWaitList, EventWaitList, Queue, UseCopyEngine)); // Get a new command list to be used on this call - ur_command_list_ptr_t CommandList{}; UR_CALL(Queue->Context->getAvailableCommandList( Queue, CommandList, UseCopyEngine, NumEventsInWaitList, EventWaitList, false /*AllowBatching*/, nullptr /*ForceCmdQueue*/)); - - ze_event_handle_t ZeEvent = nullptr; - ur_event_handle_t InternalEvent; - bool IsInternal = OutEvent == nullptr; - ur_event_handle_t *Event = OutEvent ? OutEvent : &InternalEvent; - UR_CALL(createEventAndAssociateQueue(Queue, Event, UR_COMMAND_EVENTS_WAIT, - CommandList, IsInternal, false)); - - ZeEvent = (*Event)->ZeEvent; - (*Event)->WaitList = TmpWaitList; - - const auto &WaitList = (*Event)->WaitList; - auto ZeCommandList = CommandList->first; - ZE2UR_CALL(zeCommandListAppendWaitOnEvents, - (ZeCommandList, WaitList.Length, WaitList.ZeEventList)); - - ZE2UR_CALL(zeCommandListAppendSignalEvent, (ZeCommandList, ZeEvent)); - - // Execute command list asynchronously as the event will be used - // to track down its completion. - return Queue->executeCommandList(CommandList, false /*IsBlocking*/, - false /*OKToBatchCommand*/); + } else { + UR_CALL(Queue->Context->getAvailableCommandList( + Queue, CommandList, UseCopyEngine, 0, nullptr, false /*AllowBatching*/, + nullptr /*ForceCmdQueue*/)); } - { - // If wait-list is empty, then this particular command should wait until - // all previous enqueued commands to the command-queue have completed. - // - // TODO: find a way to do that without blocking the host. - - // Lock automatically releases when this goes out of scope. - std::scoped_lock lock(Queue->Mutex); - - if (OutEvent) { - UR_CALL(createEventAndAssociateQueue(Queue, OutEvent, - UR_COMMAND_EVENTS_WAIT, - Queue->CommandListMap.end(), false, - /* IsInternal */ false)); - } + ze_event_handle_t ZeEvent = nullptr; + ur_event_handle_t InternalEvent; + bool IsInternal = OutEvent == nullptr; + ur_event_handle_t *Event = OutEvent ? OutEvent : &InternalEvent; + UR_CALL(createEventAndAssociateQueue(Queue, Event, UR_COMMAND_EVENTS_WAIT, + CommandList, IsInternal, false)); - UR_CALL(Queue->synchronize()); + ZeEvent = (*Event)->ZeEvent; + (*Event)->WaitList = TmpWaitList; + const auto &WaitList = (*Event)->WaitList; - if (OutEvent) { - Queue->LastCommandEvent = reinterpret_cast(*OutEvent); + auto ZeCommandList = CommandList->first; + ZE2UR_CALL(zeCommandListAppendWaitOnEvents, + (ZeCommandList, WaitList.Length, WaitList.ZeEventList)); - if (!(*OutEvent)->CounterBasedEventsEnabled) - ZE2UR_CALL(zeEventHostSignal, ((*OutEvent)->ZeEvent)); - (*OutEvent)->Completed = true; - } - } + ZE2UR_CALL(zeCommandListAppendSignalEvent, (ZeCommandList, ZeEvent)); - if (!Queue->UsingImmCmdLists) { - std::unique_lock Lock(Queue->Mutex); - resetCommandLists(Queue); - } + // Execute command list asynchronously as the event will be used + // to track down its completion. + return Queue->executeCommandList(CommandList, false /*IsBlocking*/, + false /*OKToBatchCommand*/); return UR_RESULT_SUCCESS; }