Skip to content

Commit 5c91e76

Browse files
committed
fix urEnqueueEventsWaitWithBarrier returning events on failures
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.
1 parent 24a8299 commit 5c91e76

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

source/adapters/level_zero/event.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,8 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
221221
return UR_RESULT_SUCCESS;
222222
}
223223

224-
ur_event_handle_t InternalEvent;
224+
ur_event_handle_t ResultEvent = nullptr;
225225
bool IsInternal = OutEvent == nullptr;
226-
ur_event_handle_t *Event = OutEvent ? OutEvent : &InternalEvent;
227226

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

@@ -264,16 +266,20 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
264266
EventWaitList, OkToBatch));
265267

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

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

271273
// Because of the dependency between commands in the in-order queue we don't
272274
// need to keep track of any active barriers if we have in-order queue.
273275
if (UseMultipleCmdlistBarriers && !Queue->isInOrderQueue()) {
274-
auto UREvent = reinterpret_cast<ur_event_handle_t>(*Event);
276+
auto UREvent = reinterpret_cast<ur_event_handle_t>(ResultEvent);
275277
Queue->ActiveBarriers.add(UREvent);
276278
}
279+
280+
if (OutEvent) {
281+
*OutEvent = ResultEvent;
282+
}
277283
return UR_RESULT_SUCCESS;
278284
}
279285

@@ -361,13 +367,13 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
361367
// Insert a barrier with the events from each command-queue into the
362368
// convergence command list. The resulting event signals the convergence of
363369
// all barriers.
364-
UR_CALL(insertBarrierIntoCmdList(ConvergenceCmdList, BaseWaitList, *Event,
370+
UR_CALL(insertBarrierIntoCmdList(ConvergenceCmdList, BaseWaitList, ResultEvent,
365371
IsInternal));
366372
} else {
367373
// If there is only a single queue then insert a barrier and the single
368374
// result event can be used as our active barrier and used as the return
369375
// event. Take into account whether output event is discarded or not.
370-
UR_CALL(insertBarrierIntoCmdList(CmdLists[0], _ur_ze_event_list_t{}, *Event,
376+
UR_CALL(insertBarrierIntoCmdList(CmdLists[0], _ur_ze_event_list_t{}, ResultEvent,
371377
IsInternal));
372378
}
373379

@@ -384,8 +390,10 @@ ur_result_t urEnqueueEventsWaitWithBarrier(
384390
}
385391

386392
UR_CALL(Queue->ActiveBarriers.clear());
387-
auto UREvent = reinterpret_cast<ur_event_handle_t>(*Event);
388-
Queue->ActiveBarriers.add(UREvent);
393+
Queue->ActiveBarriers.add(ResultEvent);
394+
if (OutEvent) {
395+
*OutEvent = ResultEvent;
396+
}
389397
return UR_RESULT_SUCCESS;
390398
}
391399

0 commit comments

Comments
 (0)