diff --git a/source/adapters/level_zero/context.cpp b/source/adapters/level_zero/context.cpp index 19696142f5..85fe582ec3 100644 --- a/source/adapters/level_zero/context.cpp +++ b/source/adapters/level_zero/context.cpp @@ -679,6 +679,11 @@ ur_result_t ur_context_handle_t_::getAvailableCommandList( if (Queue->hasOpenCommandList(UseCopyEngine)) { if (AllowBatching) { bool batchingAllowed = true; + if (ForcedCmdQueue && + CommandBatch.OpenCommandList->second.ZeQueue != *ForcedCmdQueue) { + // Current open batch doesn't match the forced command queue + batchingAllowed = false; + } if (!UrL0OutOfOrderIntegratedSignalEvent && Queue->Device->isIntegrated()) { batchingAllowed = eventCanBeBatched(Queue, UseCopyEngine, diff --git a/source/adapters/level_zero/event.cpp b/source/adapters/level_zero/event.cpp index 033cc3550b..0e853062c8 100644 --- a/source/adapters/level_zero/event.cpp +++ b/source/adapters/level_zero/event.cpp @@ -368,8 +368,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueEventsWaitWithBarrier( } // Execute each command list so the barriers can be encountered. - for (ur_command_list_ptr_t &CmdList : CmdLists) + for (ur_command_list_ptr_t &CmdList : CmdLists) { + bool IsCopy = + CmdList->second.isCopy(reinterpret_cast(Queue)); + const auto &CommandBatch = + (IsCopy) ? Queue->CopyCommandBatch : Queue->ComputeCommandBatch; + // Only batch if the matching CmdList is already open. + OkToBatch = CommandBatch.OpenCommandList == CmdList; + UR_CALL(Queue->executeCommandList(CmdList, false, OkToBatch)); + } UR_CALL(Queue->ActiveBarriers.clear()); auto UREvent = reinterpret_cast(*Event);