Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] Support incomplete user events in SYCL runtime (#38677)

Akihiro-Tabuchi3f4d1ba9b48c
diff --git a/src/plugins/intel_gpu/src/runtime/sycl/sycl_event.hpp b/src/plugins/intel_gpu/src/runtime/sycl/sycl_event.hpp
index 585ee043257..b340188f992 100644
--- a/src/plugins/intel_gpu/src/runtime/sycl/sycl_event.hpp
+++ b/src/plugins/intel_gpu/src/runtime/sycl/sycl_event.hpp
@@ -8,6 +8,7 @@
#include "sycl_common.hpp"
#include "sycl_base_event.hpp"
+#include "sycl_user_event.hpp"
#include <vector>
#include <memory>
@@ -63,28 +64,30 @@ private:
void set_impl() override;
bool is_set_impl() override;
+ void update_last_sycl_event(const event::ptr& ev) {
+ if (auto base_ev = dynamic_cast<sycl_event*>(ev.get())) {
+ auto current_ev_queue_stamp = base_ev->get_queue_stamp();
+ if ((_queue_stamp == 0) || (current_ev_queue_stamp > _queue_stamp)) {
+ _queue_stamp = current_ev_queue_stamp;
+ _last_sycl_event = base_ev->get();
+ }
+ } else if (auto user_ev = dynamic_cast<sycl_user_event*>(ev.get())) {
+ OPENVINO_ASSERT(user_ev->is_set(),
+ "[GPU] A user event which is not set yet can't be grouped: SYCL runtime "
+ "can't represent its completion state.");
+ }
+ }
+
void process_events(const std::vector<event::ptr>& ev) {
for (size_t i = 0; i < ev.size(); i++) {
auto multiple_events = dynamic_cast<sycl_events*>(ev[i].get());
if (multiple_events) {
for (size_t j = 0; j < multiple_events->_events.size(); j++) {
- if (auto base_ev = dynamic_cast<sycl_event*>(multiple_events->_events[j].get())) {
- auto current_ev_queue_stamp = base_ev->get_queue_stamp();
- if ((_queue_stamp == 0) || (current_ev_queue_stamp > _queue_stamp)) {
- _queue_stamp = current_ev_queue_stamp;
- _last_sycl_event = base_ev->get();
- }
- }
+ update_last_sycl_event(multiple_events->_events[j]);
_events.push_back(multiple_events->_events[j]);
}
} else {
- if (auto base_ev = dynamic_cast<sycl_event*>(ev[i].get())) {
- auto current_ev_queue_stamp = base_ev->get_queue_stamp();
- if ((_queue_stamp == 0) || (current_ev_queue_stamp > _queue_stamp)) {
- _queue_stamp = current_ev_queue_stamp;
- _last_sycl_event = base_ev->get();
- }
- }
+ update_last_sycl_event(ev[i]);
_events.push_back(ev[i]);
}
}
diff --git a/src/plugins/intel_gpu/src/runtime/sycl/sycl_stream.cpp b/src/plugins/intel_gpu/src/runtime/sycl/sycl_stream.cpp
index c2ff51b15af..72b90930136 100644
--- a/src/plugins/intel_gpu/src/runtime/sycl/sycl_stream.cpp
+++ b/src/plugins/intel_gpu/src/runtime/sycl/sycl_stream.cpp
@@ -7,6 +7,7 @@
#include "sycl_stream.hpp"
#include "intel_gpu/runtime/stream.hpp"
#include "sycl_event.hpp"
+#include "sycl_user_event.hpp"
#include "sycl_command_queues_builder.hpp"
#include "intel_gpu/runtime/debug_configuration.hpp"
#include "sycl_base_kernel.hpp"
@@ -188,8 +189,9 @@ event::ptr sycl_stream::group_events(std::vector<event::ptr> const& deps) {
}
event::ptr sycl_stream::create_user_event(bool set) {
- OPENVINO_ASSERT(set, "[GPU] create user event with set=false is not supported in SYCL runtime");
- return std::make_shared<sycl_event>(::sycl::event(), _command_queue);
+ // SYCL has no native user event, so the completion state is kept on the host side.
+ // See sycl_user_event for the implications.
+ return std::make_shared<sycl_user_event>(set);
}
event::ptr sycl_stream::create_base_event() {
diff --git a/src/plugins/intel_gpu/src/runtime/sycl/sycl_user_event.cpp b/src/plugins/intel_gpu/src/runtime/sycl/sycl_user_event.cpp
new file mode 100644
index 00000000000..d3b23fc10c6
--- /dev/null
+++ b/src/plugins/intel_gpu/src/runtime/sycl/sycl_user_event.cpp
@@ -0,0 +1,46 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+// Copyright (C) 2026 FUJITSU LIMITED
+//
+
+#include "sycl_user_event.hpp"
+
+#include <list>
+#include <memory>
+
+namespace cldnn {
+namespace sycl {
+
+void sycl_user_event::set_impl() {
+ // There is nothing to signal on the SYCL side: cldnn::event::set() has already updated the host
+ // side state, which is the only representation of the completion of this event.
+ _duration = std::make_unique<instrumentation::profiling_period_basic>(_timer.uptime());
+}
+
+bool sycl_user_event::get_profiling_info_impl(std::list<instrumentation::profiling_interval>& info) {
+ if (_duration == nullptr) {
+ return false;
+ }
+
+ auto period = std::make_shared<instrumentation::profiling_period_basic>(_duration->value());
+ info.push_back({ instrumentation::profiling_stage::duration, period });
+ info.push_back({ instrumentation::profiling_stage::executing, period });
+ return true;
+}
+
+void sycl_user_event::wait_impl() {
+ // cldnn::event::wait() returns early when the event is already set, so reaching this point means
+ // somebody is waiting for a user event which will never be signaled.
+ OPENVINO_THROW("[GPU] sycl_user_event::wait_impl is called before marking event handle as complete");
+}
+
+bool sycl_user_event::is_set_impl() {
+ // The host side cldnn::event::_set flag is the only source of truth for this event, and
+ // cldnn::event::is_set() has already checked it before calling this. No other place holds the
+ // completion state, so the event is known to be not set here.
+ return false;
+}
+
+} // namespace sycl
+} // namespace cldnn
diff --git a/src/plugins/intel_gpu/src/runtime/sycl/sycl_user_event.hpp b/src/plugins/intel_gpu/src/runtime/sycl/sycl_user_event.hpp
new file mode 100644
index 00000000000..eb9c838cfd3
--- /dev/null
+++ b/src/plugins/intel_gpu/src/runtime/sycl/sycl_user_event.hpp
@@ -0,0 +1,67 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+// Copyright (C) 2026 FUJITSU LIMITED
+//
+
+#pragma once
+
+#include "intel_gpu/runtime/profiling.hpp"
+#include "sycl_base_event.hpp"
+#include <memory>
+#include <list>
+
+namespace cldnn {
+namespace sycl {
+
+// A user event, i.e. an event which is not backed by any command enqueued to a SYCL queue and whose
+// completion state is controlled by the host via set().
+//
+// SYCL provides no way to express such an event: a default constructed ::sycl::event is specified to
+// be always in the "complete" state and there is no API to signal it later (unlike cl::UserEvent or
+// zeEventHostSignal). Therefore the completion state is tracked purely on the host side by
+// cldnn::event::_set and the underlying ::sycl::event is only a placeholder.
+//
+// The consequence is that such an event is invisible to the device: it must never be used as a
+// dependency of an enqueued command before it is set, otherwise that command would not be ordered
+// against whatever the user event stands for. get() asserts on that to catch the misuse early.
+//
+// The queue stamp stays 0 because nothing is ever enqueued for this event. Giving it a real stamp
+// would not help: in barrier mode it would only make sycl_stream::sync_events() submit a barrier,
+// which waits for work already submitted to the queue, not for set(); SyncMethods::none ignores
+// stamps altogether. Hence the misuse is only caught where the native event is requested: get()
+// asserts in the events sync mode, and sycl_events rejects an incomplete user event on grouping.
+// In the barrier and no-sync modes it goes undetected, same as in the OCL and L0 runtimes.
+struct sycl_user_event : public sycl_base_event {
+public:
+ explicit sycl_user_event(bool is_set = false) : sycl_base_event(0) {
+ if (is_set) {
+ set();
+ }
+ }
+
+ void set_impl() override;
+ bool get_profiling_info_impl(std::list<instrumentation::profiling_interval>& info) override;
+ ::sycl::event& get() override {
+ OPENVINO_ASSERT(_set,
+ "[GPU] Can't get native ::sycl::event from a user event which is not set yet. "
+ "SYCL runtime can't represent an incomplete event, thus a user event must be set "
+ "before anything asks for its native counterpart.");
+ return _event;
+ }
+
+protected:
+ instrumentation::timer<> _timer;
+ std::unique_ptr<instrumentation::profiling_period_basic> _duration;
+
+ // Always in the "complete" state. get() only hands it out once the event is set, so by then
+ // that state matches the event it stands for.
+ ::sycl::event _event;
+
+private:
+ void wait_impl() override;
+ bool is_set_impl() override;
+};
+
+} // namespace sycl
+} // namespace cldnn
diff --git a/src/plugins/intel_gpu/tests/unit/module_tests/sycl/sycl_events_test.cpp b/src/plugins/intel_gpu/tests/unit/module_tests/sycl/sycl_events_test.cpp
index cddb18742c0..147a3cd44cb 100644
--- a/src/plugins/intel_gpu/tests/unit/module_tests/sycl/sycl_events_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/module_tests/sycl/sycl_events_test.cpp
@@ -8,8 +8,19 @@
#include "sycl_test_context.hpp"
+#include "intel_gpu/runtime/kernel.hpp"
+#include "intel_gpu/runtime/kernel_args.hpp"
+#include "intel_gpu/runtime/kernel_builder.hpp"
+
#include "runtime/sycl/sycl_base_event.hpp"
#include "runtime/sycl/sycl_event.hpp"
+#include "runtime/sycl/sycl_user_event.hpp"
+
+#include <chrono>
+#include <memory>
+#include <string>
+#include <thread>
+#include <vector>
using namespace cldnn;
using namespace sycl_tests;
@@ -23,24 +34,248 @@ TEST(sycl_event, can_create_user_event_as_complete) {
auto ctx = create_sycl_test_context();
auto user_ev = ctx.sycl_test_stream->create_user_event(true);
- ASSERT_NE(std::dynamic_pointer_cast<cldnn::sycl::sycl_base_event>(user_ev), nullptr);
+ ASSERT_NE(std::dynamic_pointer_cast<cldnn::sycl::sycl_user_event>(user_ev), nullptr);
ASSERT_TRUE(user_ev->is_set());
}
-// TODO: Add tests when create_user_event(false) is implemented
-// TEST(sycl_event, create_user_event_as_not_complete)
-// TEST(sycl_event, can_create_user_event_as_not_complete_and_set)
+TEST(sycl_event, can_create_user_event_as_not_complete) {
+ auto ctx = create_sycl_test_context();
+ auto user_ev = ctx.sycl_test_stream->create_user_event(false);
+
+ ASSERT_NE(std::dynamic_pointer_cast<cldnn::sycl::sycl_user_event>(user_ev), nullptr);
+ ASSERT_FALSE(user_ev->is_set());
+}
+
+TEST(sycl_event, can_create_user_event_as_not_complete_and_set) {
+ auto ctx = create_sycl_test_context();
+ auto user_ev = ctx.sycl_test_stream->create_user_event(false);
+ ASSERT_FALSE(user_ev->is_set());
+ user_ev->set();
+
+ ASSERT_NE(std::dynamic_pointer_cast<cldnn::sycl::sycl_user_event>(user_ev), nullptr);
+ ASSERT_TRUE(user_ev->is_set());
+}
TEST(sycl_event, can_create_user_event_as_complete_and_wait) {
auto ctx = create_sycl_test_context();
auto user_ev = ctx.sycl_test_stream->create_user_event(true);
user_ev->wait();
- ASSERT_NE(std::dynamic_pointer_cast<cldnn::sycl::sycl_base_event>(user_ev), nullptr);
+ ASSERT_NE(std::dynamic_pointer_cast<cldnn::sycl::sycl_user_event>(user_ev), nullptr);
ASSERT_TRUE(user_ev->is_set());
}
-// TODO: Add test when create_user_event(false) is implemented
-// TEST(sycl_event, can_create_user_event_as_not_complete_set_and_wait)
+TEST(sycl_event, can_create_user_event_as_not_complete_set_and_wait) {
+ auto ctx = create_sycl_test_context();
+ auto user_ev = ctx.sycl_test_stream->create_user_event(false);
+ user_ev->set();
+ user_ev->wait();
+
+ ASSERT_NE(std::dynamic_pointer_cast<cldnn::sycl::sycl_user_event>(user_ev), nullptr);
+ ASSERT_TRUE(user_ev->is_set());
+}
+
+TEST(sycl_event, fail_on_create_as_not_complete_and_wait) {
+ auto ctx = create_sycl_test_context();
+ auto user_ev = ctx.sycl_test_stream->create_user_event(false);
+ ASSERT_THROW(user_ev->wait(), std::runtime_error);
+}
+
+// A user event has no native ::sycl::event while it is not set, so get() must reject it.
+TEST(sycl_event, fail_on_get_native_event_when_not_set) {
+ auto ctx = create_sycl_test_context();
+ auto user_ev = ctx.sycl_test_stream->create_user_event(false);
+
+ auto sycl_ev = std::dynamic_pointer_cast<cldnn::sycl::sycl_base_event>(user_ev);
+ ASSERT_NE(sycl_ev, nullptr);
+ ASSERT_THROW(sycl_ev->get(), ov::Exception);
+
+ user_ev->set();
+ ASSERT_NO_THROW(sycl_ev->get());
+}
+
+// A user event has no native ::sycl::event while it is not set, and wait_for_events() collects the
+// native event of every dependency, so it goes through get() and is rejected.
+TEST(sycl_event, fail_on_wait_for_events_when_not_set) {
+ auto ctx = create_sycl_test_context();
+ auto user_ev = ctx.sycl_test_stream->create_user_event(false);
+
+ ASSERT_THROW(ctx.sycl_test_stream->wait_for_events({ user_ev }), std::runtime_error);
+
+ user_ev->set();
+ ASSERT_NO_THROW(ctx.sycl_test_stream->wait_for_events({ user_ev }));
+}
+
+// A user event has no native ::sycl::event while it is not set, so it can't be aggregated:
+// sycl_events picks one of its dependencies as the native event it waits on, and a user event
+// simply has none to offer until set() is called.
+TEST(sycl_event, fail_on_group_events_when_not_set) {
+ auto ctx = create_sycl_test_context();
+ auto user_ev = ctx.sycl_test_stream->create_user_event(false);
+ auto base_ev = ctx.sycl_test_stream->enqueue_marker({}, false);
+
+ // group_events() returns deps[0] as is for a single dependency, so a second event is needed to
+ // make it build a sycl_events aggregate and go through update_last_sycl_event().
+ // Both orders must be rejected: the guard runs before the queue stamp comparison, so detection
+ // does not depend on the position of the user event in the list.
+ ASSERT_THROW(ctx.sycl_test_stream->group_events({ user_ev, base_ev }), ov::Exception);
+ ASSERT_THROW(ctx.sycl_test_stream->group_events({ base_ev, user_ev }), ov::Exception);
+
+ user_ev->set();
+ ASSERT_NO_THROW(ctx.sycl_test_stream->group_events({ user_ev, base_ev }));
+}
+
+TEST(sycl_event, user_event_does_not_hide_incomplete_deps_in_group) {
+ auto ctx = create_sycl_test_context();
+ auto user_ev = ctx.sycl_test_stream->create_user_event(true);
+ auto base_ev = ctx.sycl_test_stream->enqueue_marker({}, false);
+
+ // The aggregate must rely on the native event of base_ev rather than on the placeholder event of
+ // the user event, which is always in the complete state.
+ auto grouped_ev = ctx.sycl_test_stream->group_events({ user_ev, base_ev });
+ auto grouped_sycl_ev = std::dynamic_pointer_cast<cldnn::sycl::sycl_base_event>(grouped_ev);
+ ASSERT_NE(grouped_sycl_ev, nullptr);
+
+ auto base_sycl_ev = std::dynamic_pointer_cast<cldnn::sycl::sycl_base_event>(base_ev);
+ ASSERT_NE(base_sycl_ev, nullptr);
+ ASSERT_EQ(grouped_sycl_ev->get(), base_sycl_ev->get());
+
+ ASSERT_NO_THROW(grouped_ev->wait());
+ ASSERT_TRUE(grouped_ev->is_set());
+}
+
+// The time of a user event is spent on the host, so like ocl_user_event it must be reported as a
+// "duration" interval, which the profiling report counts as CPU work, followed by "executing".
+// SYCL has no device clock sync for user events, so no start timestamp is synthesized.
+TEST(sycl_event, user_event_profiling_reports_duration_and_executing) {
+ auto ctx = create_sycl_test_context();
+ auto user_ev = ctx.sycl_test_stream->create_user_event(true);
+
+ const auto profiling_info = user_ev->get_profiling_info();
+
+ ASSERT_EQ(profiling_info.size(), 2);
+ EXPECT_EQ(profiling_info[0].stage, instrumentation::profiling_stage::duration);
+ EXPECT_EQ(profiling_info[1].stage, instrumentation::profiling_stage::executing);
+ EXPECT_EQ(profiling_info[0].value->value(), profiling_info[1].value->value());
+ EXPECT_FALSE(profiling_info[0].is_valid_start);
+ EXPECT_FALSE(profiling_info[1].is_valid_start);
+}
+
+// Nothing is measured until set(), so an incomplete user event reports no intervals, and that empty
+// result must not be cached: once set, the intervals cover the time from creation until set().
+TEST(sycl_event, user_event_profiling_is_captured_once_set) {
+ auto ctx = create_sycl_test_context();
+ auto user_ev = ctx.sycl_test_stream->create_user_event(false);
+
+ ASSERT_TRUE(user_ev->get_profiling_info().empty());
+
+ const auto delay = std::chrono::milliseconds(1);
+ std::this_thread::sleep_for(delay);
+ user_ev->set();
+
+ const auto profiling_info = user_ev->get_profiling_info();
+
+ ASSERT_EQ(profiling_info.size(), 2);
+ EXPECT_EQ(profiling_info[0].stage, instrumentation::profiling_stage::duration);
+ EXPECT_EQ(profiling_info[1].stage, instrumentation::profiling_stage::executing);
+ EXPECT_GE(profiling_info[0].value->value(), delay);
+ EXPECT_EQ(profiling_info[0].value->value(), profiling_info[1].value->value());
+}
+
+/*
+USER EVENTS AS DEPENDENCIES OF ENQUEUED COMMANDS:
+*/
+
+namespace {
+
+// Picks the config which makes stream::get_expected_sync_method() return the requested method:
+// profiling -> events, out_of_order queue -> barriers, in_order queue -> none.
+std::shared_ptr<cldnn::stream> create_stream_with_sync_method(cldnn::engine& engine, SyncMethods sync_method) {
+ auto config = ::tests::get_test_default_config(engine);
+ config.set_property(ov::enable_profiling(sync_method == SyncMethods::events));
+ config.set_property(ov::intel_gpu::queue_type(sync_method == SyncMethods::barriers ? QueueTypes::out_of_order
+ : QueueTypes::in_order));
+ auto stream = engine.create_stream(config);
+ OPENVINO_ASSERT(stream->get_sync_method() == sync_method, "[GPU] Unexpected sync method of the test stream");
+ return stream;
+}
+
+kernel::ptr build_noop_kernel(cldnn::engine& engine) {
+ const std::string source = R"__cl(
+ __kernel void noop() {}
+ )__cl";
+
+ std::vector<kernel::ptr> kernels;
+ engine.create_kernel_builder()->build_kernels(source.data(), source.size(), KernelFormat::SOURCE, "", kernels);
+ OPENVINO_ASSERT(kernels.size() == 1, "[GPU] Failed to build the noop kernel for tests");
+ return kernels[0];
+}
+
+std::string sync_method_name(const testing::TestParamInfo<SyncMethods>& info) {
+ switch (info.param) {
+ case SyncMethods::events: return "events";
+ case SyncMethods::barriers: return "barriers";
+ case SyncMethods::none: return "none";
+ default: return "unknown";
+ }
+}
+
+} // namespace
+
+// A user event which is not set yet can't be ordered against by the device. In the events sync mode
+// sycl_user_event::get() rejects it as a dependency. The barrier and no-sync modes don't check it,
+// same as the OCL and L0 runtimes, so only the events mode is covered here.
+class sycl_user_event_deps : public ::testing::TestWithParam<SyncMethods> {};
+
+TEST_P(sycl_user_event_deps, enqueue_marker_rejects_incomplete_user_event) {
+ auto ctx = create_sycl_test_context();
+ auto stream = create_stream_with_sync_method(*ctx.sycl_test_engine, GetParam());
+
+ auto user_ev = stream->create_user_event(false);
+ auto base_ev = stream->enqueue_marker({}, false);
+
+ // The position of the user event in the list must not matter.
+ ASSERT_THROW(stream->enqueue_marker({ user_ev }, false), ov::Exception);
+ ASSERT_THROW(stream->enqueue_marker({ user_ev, base_ev }, false), ov::Exception);
+ ASSERT_THROW(stream->enqueue_marker({ base_ev, user_ev }, false), ov::Exception);
+
+ user_ev->set();
+ event::ptr marker_ev;
+ ASSERT_NO_THROW(marker_ev = stream->enqueue_marker({ user_ev, base_ev }, false));
+ ASSERT_NE(marker_ev, nullptr);
+ ASSERT_NO_THROW(marker_ev->wait());
+}
+
+TEST_P(sycl_user_event_deps, enqueue_kernel_rejects_incomplete_user_event) {
+ auto ctx = create_sycl_test_context();
+ auto stream = create_stream_with_sync_method(*ctx.sycl_test_engine, GetParam());
+ auto kernel = build_noop_kernel(*ctx.sycl_test_engine);
+
+ kernel_arguments_desc args_desc;
+ kernel_arguments_data args;
+
+ auto user_ev = stream->create_user_event(false);
+ auto base_ev = stream->enqueue_marker({}, false);
+
+ ASSERT_THROW(stream->enqueue_kernel(*kernel, args_desc, args, { user_ev }, false), ov::Exception);
+ ASSERT_THROW(stream->enqueue_kernel(*kernel, args_desc, args, { user_ev, base_ev }, false), ov::Exception);
+ ASSERT_THROW(stream->enqueue_kernel(*kernel, args_desc, args, { base_ev, user_ev }, false), ov::Exception);
+
+ // An empty launch falls back to enqueue_marker(), which must reject it as well.
+ kernel_arguments_desc empty_args_desc;
+ empty_args_desc.workGroups.global = {0, 1, 1};
+ ASSERT_THROW(stream->enqueue_kernel(*kernel, empty_args_desc, args, { user_ev }, false), ov::Exception);
+
+ user_ev->set();
+ event::ptr kernel_ev;
+ ASSERT_NO_THROW(kernel_ev = stream->enqueue_kernel(*kernel, args_desc, args, { user_ev, base_ev }, false));
+ ASSERT_NE(kernel_ev, nullptr);
+ ASSERT_NO_THROW(kernel_ev->wait());
+}
+
+INSTANTIATE_TEST_SUITE_P(sycl_event,
+ sycl_user_event_deps,
+ ::testing::Values(SyncMethods::events),
+ sync_method_name);
#endif // OV_GPU_WITH_SYCL_RT