Skip to content

Commit c3ee9c6

Browse files
committed
[UR][L0] Fix Barrier Event Cleanup
- Fix barrier wait cleanup of events given an out event such that an additional refcnt release is done and with multi command lists and in order, the active barrier is properly cleared before reassignment. Signed-off-by: Neil R. Spruit <[email protected]>
1 parent 92121c9 commit c3ee9c6

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

unified-runtime/source/adapters/level_zero/event.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ ur_result_t urEnqueueEventsWaitWithBarrierExt(
302302
// need to keep track of any active barriers if we have in-order queue.
303303
if (UseMultipleCmdlistBarriers && !Queue->isInOrderQueue()) {
304304
auto UREvent = reinterpret_cast<ur_event_handle_t>(ResultEvent);
305+
// We must release the Active Barrier before we start the next one
306+
// otherwise we will leak an event that won't be released.
307+
UR_CALL(Queue->ActiveBarriers.clear());
305308
Queue->ActiveBarriers.add(UREvent);
306309
}
307310

@@ -884,12 +887,21 @@ ur_result_t
884887
urEventRelease(/** [in] handle of the event object */ ur_event_handle_t Event) {
885888
Event->RefCountExternal--;
886889
bool isEventsWaitCompleted =
887-
Event->CommandType == UR_COMMAND_EVENTS_WAIT && Event->Completed;
890+
(Event->CommandType == UR_COMMAND_EVENTS_WAIT ||
891+
Event->CommandType == UR_COMMAND_EVENTS_WAIT_WITH_BARRIER) &&
892+
Event->Completed;
888893
UR_CALL(urEventReleaseInternal(Event));
889894
// If this is a Completed Event Wait Out Event, then we need to cleanup the
890895
// event at user release and not at the time of completion.
896+
// If the event is labelled as completed and no additional references are
897+
// removed, then we still need to decrement the event, but not mark as
898+
// completed.
891899
if (isEventsWaitCompleted) {
892-
UR_CALL(CleanupCompletedEvent((Event), false, false));
900+
if (Event->CleanedUp) {
901+
UR_CALL(urEventReleaseInternal(Event));
902+
} else {
903+
UR_CALL(CleanupCompletedEvent((Event), false, false));
904+
}
893905
}
894906

895907
return UR_RESULT_SUCCESS;

unified-runtime/source/adapters/level_zero/queue.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -2374,10 +2374,11 @@ ur_queue_handle_t_::insertActiveBarriers(ur_command_list_ptr_t &CmdList,
23742374
Event->WaitList = ActiveBarriersWaitList;
23752375
Event->OwnNativeHandle = true;
23762376

2377-
// If there are more active barriers, insert a barrier on the command-list. We
2378-
// do not need an event for finishing so we pass nullptr.
2377+
// If there are more active barriers, insert a barrier on the command-list.
2378+
// We need to signal the current active barrier event otherwise we will leak
2379+
// the Event object when we replace the active barrier.
23792380
ZE2UR_CALL(zeCommandListAppendBarrier,
2380-
(CmdList->first, nullptr, ActiveBarriersWaitList.Length,
2381+
(CmdList->first, Event->ZeEvent, ActiveBarriersWaitList.Length,
23812382
ActiveBarriersWaitList.ZeEventList));
23822383
return UR_RESULT_SUCCESS;
23832384
}

0 commit comments

Comments
 (0)