Skip to content

Commit

Permalink
[SYCL] Fix event status query during queue flushing (#7147)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sergey-semenov authored Oct 23, 2022
1 parent 20dbc70 commit 6c9a380
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sycl/source/detail/event_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ std::vector<EventImplPtr> event_impl::getWaitList() {
}

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

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

// Check if the task for this event has already been submitted.
assert(MEvent != nullptr);
pi_event_status Status = PI_EVENT_QUEUED;
getPlugin().call<PiApiKind::piEventGetInfo>(
MEvent, PI_EVENT_INFO_COMMAND_EXECUTION_STATUS, sizeof(pi_int32), &Status,
Expand Down
12 changes: 12 additions & 0 deletions sycl/unittests/scheduler/QueueFlushing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static pi_result redefinedEventGetInfo(pi_event event, pi_event_info param_name,
size_t param_value_size,
void *param_value,
size_t *param_value_size_ret) {
EXPECT_NE(event, nullptr);
if (param_name == PI_EVENT_INFO_COMMAND_EXECUTION_STATUS) {
auto *Status = reinterpret_cast<pi_event_status *>(param_value);
*Status = EventStatus;
Expand Down Expand Up @@ -278,4 +279,15 @@ TEST_F(SchedulerTest, QueueFlushing) {
access::mode::read_write};
testEventStatusCheck(&CmdC, QueueImplB, MockReq, PI_EVENT_COMPLETE);
}

// Check that nullptr pi_events are handled correctly.
{
resetTestCtx();
detail::MapMemObject CmdA{&AllocaCmd, MockReq, &MockHostPtr, QueueImplA,
access::mode::read_write};
MockCommand DepCmd(QueueImplB);
(void)CmdA.addDep(detail::DepDesc{&DepCmd, &MockReq, nullptr}, ToCleanUp);
MockScheduler::enqueueCommand(&CmdA, Res, detail::NON_BLOCKING);
EXPECT_FALSE(EventStatusQueried);
}
}

0 comments on commit 6c9a380

Please sign in to comment.