diff --git a/sycl/plugins/level_zero/pi_level_zero.cpp b/sycl/plugins/level_zero/pi_level_zero.cpp index def60bc219aca..ee96398535c66 100644 --- a/sycl/plugins/level_zero/pi_level_zero.cpp +++ b/sycl/plugins/level_zero/pi_level_zero.cpp @@ -6465,15 +6465,15 @@ pi_result piEnqueueEventsWaitWithBarrier(pi_queue Queue, } } - // Insert a barrier into each unique command queue using the available - // command-lists. - std::vector EventWaitVector(CmdLists.size()); - for (size_t I = 0; I < CmdLists.size(); ++I) - if (auto Res = insertBarrierIntoCmdList(CmdLists[I], _pi_ze_event_list_t{}, - EventWaitVector[I], false)) - return Res; - if (CmdLists.size() > 1) { + // Insert a barrier into each unique command queue using the available + // command-lists. + std::vector EventWaitVector(CmdLists.size()); + for (size_t I = 0; I < CmdLists.size(); ++I) + if (auto Res = insertBarrierIntoCmdList( + CmdLists[I], _pi_ze_event_list_t{}, EventWaitVector[I], false)) + return Res; + // If there were multiple queues we need to create a "convergence" event to // be our active barrier. This convergence event is signalled by a barrier // on all the events from the barriers we have inserted into each queue. @@ -6497,10 +6497,13 @@ pi_result piEnqueueEventsWaitWithBarrier(pi_queue Queue, *Event, IsInternal)) return Res; } else { - // If there is only a single queue we have inserted all the barriers we need - // and the single result event can be used as our active barrier and used as - // the return event. - *Event = EventWaitVector[0]; + PI_ASSERT(CmdLists.size() == 1, PI_ERROR_INVALID_QUEUE); + // If there is only a single queue then insert a barrier and the single + // result event can be used as our active barrier and used as the return + // event. Take into account whether output event is discarded or not. + if (auto Res = insertBarrierIntoCmdList(CmdLists[0], _pi_ze_event_list_t{}, + *Event, IsInternal)) + return Res; } // Execute each command list so the barriers can be encountered.