From 6c9a380dc5289956aa5eb18648de4f399a16a706 Mon Sep 17 00:00:00 2001 From: Sergey Semenov Date: Sun, 23 Oct 2022 13:37:30 +0200 Subject: [PATCH] [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. --- sycl/source/detail/event_impl.cpp | 5 +++-- sycl/unittests/scheduler/QueueFlushing.cpp | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/sycl/source/detail/event_impl.cpp b/sycl/source/detail/event_impl.cpp index 7d88e52baf27d..6f8bd84337c27 100644 --- a/sycl/source/detail/event_impl.cpp +++ b/sycl/source/detail/event_impl.cpp @@ -402,7 +402,9 @@ std::vector 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(); @@ -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( MEvent, PI_EVENT_INFO_COMMAND_EXECUTION_STATUS, sizeof(pi_int32), &Status, diff --git a/sycl/unittests/scheduler/QueueFlushing.cpp b/sycl/unittests/scheduler/QueueFlushing.cpp index a6916e5dc2f5c..d40e9f5f6e3f6 100644 --- a/sycl/unittests/scheduler/QueueFlushing.cpp +++ b/sycl/unittests/scheduler/QueueFlushing.cpp @@ -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(param_value); *Status = EventStatus; @@ -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); + } }