Skip to content

Commit 6c9a380

Browse files
[SYCL] Fix event status query during queue flushing (#7147)
Some events may have no native handle even at the point of cross queue dependency flushing (e.g. those produced by a 0 size memset, where no PI call is actually made). This patch changes the assertion of native handle's existence into a check so that we handle this case properly.
1 parent 20dbc70 commit 6c9a380

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

sycl/source/detail/event_impl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,9 @@ std::vector<EventImplPtr> event_impl::getWaitList() {
402402
}
403403

404404
void event_impl::flushIfNeeded(const QueueImplPtr &UserQueue) {
405-
if (MIsFlushed)
405+
// Some events might not have a native handle underneath even at this point,
406+
// e.g. those produced by memset with 0 size (no PI call is made).
407+
if (MIsFlushed || !MEvent)
406408
return;
407409

408410
QueueImplPtr Queue = MQueue.lock();
@@ -416,7 +418,6 @@ void event_impl::flushIfNeeded(const QueueImplPtr &UserQueue) {
416418
return;
417419

418420
// Check if the task for this event has already been submitted.
419-
assert(MEvent != nullptr);
420421
pi_event_status Status = PI_EVENT_QUEUED;
421422
getPlugin().call<PiApiKind::piEventGetInfo>(
422423
MEvent, PI_EVENT_INFO_COMMAND_EXECUTION_STATUS, sizeof(pi_int32), &Status,

sycl/unittests/scheduler/QueueFlushing.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ static pi_result redefinedEventGetInfo(pi_event event, pi_event_info param_name,
3030
size_t param_value_size,
3131
void *param_value,
3232
size_t *param_value_size_ret) {
33+
EXPECT_NE(event, nullptr);
3334
if (param_name == PI_EVENT_INFO_COMMAND_EXECUTION_STATUS) {
3435
auto *Status = reinterpret_cast<pi_event_status *>(param_value);
3536
*Status = EventStatus;
@@ -278,4 +279,15 @@ TEST_F(SchedulerTest, QueueFlushing) {
278279
access::mode::read_write};
279280
testEventStatusCheck(&CmdC, QueueImplB, MockReq, PI_EVENT_COMPLETE);
280281
}
282+
283+
// Check that nullptr pi_events are handled correctly.
284+
{
285+
resetTestCtx();
286+
detail::MapMemObject CmdA{&AllocaCmd, MockReq, &MockHostPtr, QueueImplA,
287+
access::mode::read_write};
288+
MockCommand DepCmd(QueueImplB);
289+
(void)CmdA.addDep(detail::DepDesc{&DepCmd, &MockReq, nullptr}, ToCleanUp);
290+
MockScheduler::enqueueCommand(&CmdA, Res, detail::NON_BLOCKING);
291+
EXPECT_FALSE(EventStatusQueried);
292+
}
281293
}

0 commit comments

Comments
 (0)