diff --git a/source/adapters/level_zero/queue.cpp b/source/adapters/level_zero/queue.cpp index 0388b8fdbb..2dcdcfd51e 100755 --- a/source/adapters/level_zero/queue.cpp +++ b/source/adapters/level_zero/queue.cpp @@ -1406,8 +1406,18 @@ ur_result_t ur_queue_handle_t_::synchronize() { if (ImmCmdList == Queue->CommandListMap.end()) return UR_RESULT_SUCCESS; - // wait for all commands previously submitted to this immediate command list - ZE2UR_CALL(zeCommandListHostSynchronize, (ImmCmdList->first, UINT64_MAX)); + ur_event_handle_t Event{}; + ur_result_t Res = createEventAndAssociateQueue( + reinterpret_cast(Queue), &Event, + UR_EXT_COMMAND_TYPE_USER, ImmCmdList, /* IsInternal */ false); + if (Res != UR_RESULT_SUCCESS) + return Res; + auto zeEvent = Event->ZeEvent; + ZE2UR_CALL(zeCommandListAppendBarrier, + (ImmCmdList->first, zeEvent, 0, nullptr)); + ZE2UR_CALL(zeHostSynchronize, (zeEvent)); + Event->Completed = true; + UR_CALL(urEventRelease(Event)); // Cleanup all events from the synced command list. CleanupEventListFromResetCmdList(ImmCmdList->second.EventList, true);