From ef80d281174dd3c550a646ca13cd5d2779179e1b Mon Sep 17 00:00:00 2001 From: "Larsen, Steffen" Date: Tue, 23 Aug 2022 03:41:12 -0700 Subject: [PATCH 1/2] [SYCL] Fix depends_on with default-constructed events Using depends_on with default constructed events caused commands to incorrectly expect the events to have associated PI events. Since default-constructed events are automatically considered finished, they can be ignored if they do not have an associated native event. These changes allows commands to ignore uninitialized events in dependency events. Signed-off-by: Larsen, Steffen --- sycl/source/detail/event_impl.hpp | 9 +++++++++ sycl/source/detail/queue_impl.hpp | 3 ++- sycl/source/detail/scheduler/commands.cpp | 10 ++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/sycl/source/detail/event_impl.hpp b/sycl/source/detail/event_impl.hpp index f542f9d20a25d..bc343ea662413 100644 --- a/sycl/source/detail/event_impl.hpp +++ b/sycl/source/detail/event_impl.hpp @@ -212,6 +212,15 @@ class event_impl { } bool needsCleanupAfterWait() { return MNeedsCleanupAfterWait; } + /// Checks if an event is in a fully intialized state. Default-constructed + /// events will return true only after having initialized its native event, + /// while other events will assume that they are fully initialized at + /// construction, relying on external sources to supply member data. + /// + /// \return true if the event is considered to be in a fully initialized + /// state. + bool isInitialized() const noexcept { return MIsInitialized; } + private: // When instrumentation is enabled emits trace event for event wait begin and // returns the telemetry event generated for the wait diff --git a/sycl/source/detail/queue_impl.hpp b/sycl/source/detail/queue_impl.hpp index ae0cd7e390ca6..ec98c3ac3d8b6 100644 --- a/sycl/source/detail/queue_impl.hpp +++ b/sycl/source/detail/queue_impl.hpp @@ -530,7 +530,8 @@ class queue_impl { // Host and interop tasks, however, are not submitted to low-level runtimes // and require separate dependency management. const CG::CGTYPE Type = Handler.getType(); - event Event; + event Event = detail::createSyclObjFromImpl( + std::make_shared()); if (PostProcess) { bool IsKernel = Type == CG::Kernel; diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index dc802ba3d82e6..07fa41309fd50 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -582,11 +582,13 @@ Command *Command::processDepEvent(EventImplPtr DepEvent, const DepDesc &Dep, const ContextImplPtr &WorkerContext = WorkerQueue->getContextImplPtr(); // 1. Async work is not supported for host device. - // 2. Some types of commands do not produce PI events after they are enqueued - // (e.g. alloca). Note that we can't check the pi event to make that - // distinction since the command might still be unenqueued at this point. + // 2. Non-host events can be ignored if they are not fully initialized. + // 3. Some types of commands do not produce PI events after they are enqueued + // (e.g. alloca). Note that we can't check the pi event to make that + // distinction since the command might still be unenqueued at this point. bool PiEventExpected = - !DepEvent->is_host() || getType() == CommandType::HOST_TASK; + (!DepEvent->is_host() && DepEvent->isInitialized()) || + getType() == CommandType::HOST_TASK; if (auto *DepCmd = static_cast(DepEvent->getCommand())) PiEventExpected &= DepCmd->producesPiEvent(); From 4bb7dd7c37d0086fe0d9e8839c2c93d2dfb38113 Mon Sep 17 00:00:00 2001 From: "Larsen, Steffen" Date: Tue, 23 Aug 2022 04:37:47 -0700 Subject: [PATCH 2/2] Fix formatting Signed-off-by: Larsen, Steffen --- sycl/source/detail/scheduler/commands.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sycl/source/detail/scheduler/commands.cpp b/sycl/source/detail/scheduler/commands.cpp index 07fa41309fd50..800fa40490015 100644 --- a/sycl/source/detail/scheduler/commands.cpp +++ b/sycl/source/detail/scheduler/commands.cpp @@ -586,9 +586,8 @@ Command *Command::processDepEvent(EventImplPtr DepEvent, const DepDesc &Dep, // 3. Some types of commands do not produce PI events after they are enqueued // (e.g. alloca). Note that we can't check the pi event to make that // distinction since the command might still be unenqueued at this point. - bool PiEventExpected = - (!DepEvent->is_host() && DepEvent->isInitialized()) || - getType() == CommandType::HOST_TASK; + bool PiEventExpected = (!DepEvent->is_host() && DepEvent->isInitialized()) || + getType() == CommandType::HOST_TASK; if (auto *DepCmd = static_cast(DepEvent->getCommand())) PiEventExpected &= DepCmd->producesPiEvent();