Skip to content

Commit 968f9e7

Browse files
authored
[SYCL] Fix memory leak in piEnqueueEventsWaitWithBarrier with discarded output event (#7229)
Fix memory leak piEnqueueEventsWaitWithBarrier for the Level Zero backend when output event is discarded. Take into account IsInternal flag when creating an event which is used as the output event.
1 parent 2ba28e8 commit 968f9e7

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6465,15 +6465,15 @@ pi_result piEnqueueEventsWaitWithBarrier(pi_queue Queue,
64656465
}
64666466
}
64676467

6468-
// Insert a barrier into each unique command queue using the available
6469-
// command-lists.
6470-
std::vector<pi_event> EventWaitVector(CmdLists.size());
6471-
for (size_t I = 0; I < CmdLists.size(); ++I)
6472-
if (auto Res = insertBarrierIntoCmdList(CmdLists[I], _pi_ze_event_list_t{},
6473-
EventWaitVector[I], false))
6474-
return Res;
6475-
64766468
if (CmdLists.size() > 1) {
6469+
// Insert a barrier into each unique command queue using the available
6470+
// command-lists.
6471+
std::vector<pi_event> EventWaitVector(CmdLists.size());
6472+
for (size_t I = 0; I < CmdLists.size(); ++I)
6473+
if (auto Res = insertBarrierIntoCmdList(
6474+
CmdLists[I], _pi_ze_event_list_t{}, EventWaitVector[I], false))
6475+
return Res;
6476+
64776477
// If there were multiple queues we need to create a "convergence" event to
64786478
// be our active barrier. This convergence event is signalled by a barrier
64796479
// on all the events from the barriers we have inserted into each queue.
@@ -6497,10 +6497,13 @@ pi_result piEnqueueEventsWaitWithBarrier(pi_queue Queue,
64976497
*Event, IsInternal))
64986498
return Res;
64996499
} else {
6500-
// If there is only a single queue we have inserted all the barriers we need
6501-
// and the single result event can be used as our active barrier and used as
6502-
// the return event.
6503-
*Event = EventWaitVector[0];
6500+
PI_ASSERT(CmdLists.size() == 1, PI_ERROR_INVALID_QUEUE);
6501+
// If there is only a single queue then insert a barrier and the single
6502+
// result event can be used as our active barrier and used as the return
6503+
// event. Take into account whether output event is discarded or not.
6504+
if (auto Res = insertBarrierIntoCmdList(CmdLists[0], _pi_ze_event_list_t{},
6505+
*Event, IsInternal))
6506+
return Res;
65046507
}
65056508

65066509
// Execute each command list so the barriers can be encountered.

0 commit comments

Comments
 (0)