Skip to content

Commit

Permalink
Merge pull request oneapi-src#2080 from pbalcer/dont-return-events-on…
Browse files Browse the repository at this point in the history
…-fail

fix urEnqueueEventsWaitWithBarrier returning events on failures
  • Loading branch information
pbalcer authored Sep 12, 2024
2 parents 24a8299 + a5f142f commit 904fa18
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 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,21 @@ 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,14 +368,14 @@ 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,
IsInternal));
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,
IsInternal));
UR_CALL(insertBarrierIntoCmdList(CmdLists[0], _ur_ze_event_list_t{},
ResultEvent, IsInternal));
}

// Execute each command list so the barriers can be encountered.
Expand All @@ -384,8 +391,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 904fa18

Please sign in to comment.