Skip to content

Commit

Permalink
fix urEnqueueEventsWaitWithBarrier returning events on failures
Browse files Browse the repository at this point in the history
SYCL RT may sometimes ignore errors and call release on returned
handles from failing functions. This patch makes sure that the
OutEvent remains unmodified when the urEnqueueEventsWaitWithBarrier
function returns an error.
  • Loading branch information
pbalcer committed Sep 11, 2024
1 parent 24a8299 commit 5c91e76
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions source/adapters/level_zero/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,8 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
return UR_RESULT_SUCCESS;
}

ur_event_handle_t InternalEvent;
ur_event_handle_t ResultEvent = nullptr;
bool IsInternal = OutEvent == nullptr;
ur_event_handle_t *Event = OutEvent ? OutEvent : &InternalEvent;

// For in-order queue and wait-list which is empty or has events from
// the same queue just use the last command event as the barrier event.
Expand All @@ -234,7 +233,10 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
EventWaitList) &&
Queue->LastCommandEvent && !Queue->LastCommandEvent->IsDiscarded) {
UR_CALL(ur::level_zero::urEventRetain(Queue->LastCommandEvent));
*Event = Queue->LastCommandEvent;
ResultEvent = Queue->LastCommandEvent;
if (OutEvent) {
*OutEvent = ResultEvent;
}
return UR_RESULT_SUCCESS;
}

Expand Down Expand Up @@ -264,16 +266,20 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
EventWaitList, OkToBatch));

// Insert the barrier into the command-list and execute.
UR_CALL(insertBarrierIntoCmdList(CmdList, TmpWaitList, *Event, IsInternal));
UR_CALL(insertBarrierIntoCmdList(CmdList, TmpWaitList, ResultEvent, IsInternal));

UR_CALL(Queue->executeCommandList(CmdList, false, OkToBatch));

// Because of the dependency between commands in the in-order queue we don't
// need to keep track of any active barriers if we have in-order queue.
if (UseMultipleCmdlistBarriers && !Queue->isInOrderQueue()) {
auto UREvent = reinterpret_cast<ur_event_handle_t>(*Event);
auto UREvent = reinterpret_cast<ur_event_handle_t>(ResultEvent);
Queue->ActiveBarriers.add(UREvent);
}

if (OutEvent) {
*OutEvent = ResultEvent;
}
return UR_RESULT_SUCCESS;
}

Expand Down Expand Up @@ -361,13 +367,13 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
// Insert a barrier with the events from each command-queue into the
// convergence command list. The resulting event signals the convergence of
// all barriers.
UR_CALL(insertBarrierIntoCmdList(ConvergenceCmdList, BaseWaitList, *Event,
UR_CALL(insertBarrierIntoCmdList(ConvergenceCmdList, BaseWaitList, ResultEvent,
IsInternal));
} else {
// 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.
UR_CALL(insertBarrierIntoCmdList(CmdLists[0], _ur_ze_event_list_t{}, *Event,
UR_CALL(insertBarrierIntoCmdList(CmdLists[0], _ur_ze_event_list_t{}, ResultEvent,
IsInternal));
}

Expand All @@ -384,8 +390,10 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
}

UR_CALL(Queue->ActiveBarriers.clear());
auto UREvent = reinterpret_cast<ur_event_handle_t>(*Event);
Queue->ActiveBarriers.add(UREvent);
Queue->ActiveBarriers.add(ResultEvent);
if (OutEvent) {
*OutEvent = ResultEvent;
}
return UR_RESULT_SUCCESS;
}

Expand Down

0 comments on commit 5c91e76

Please sign in to comment.