Skip to content

fix urEnqueueEventsWaitWithBarrier returning events on failures #2080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading