Skip to content

Commit

Permalink
[SYCL] Fix memory leak in piEnqueueEventsWaitWithBarrier with discard…
Browse files Browse the repository at this point in the history
…ed 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.
  • Loading branch information
againull authored Oct 31, 2022
1 parent 2ba28e8 commit 968f9e7
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<pi_event> 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<pi_event> 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.
Expand All @@ -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.
Expand Down

0 comments on commit 968f9e7

Please sign in to comment.