[llvm-branch-commits] [llvm] [libsycl] add sycl::event and wait functionality to event & queue (PR #188793)
Kseniya Tikhomirova via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Mar 30 06:49:37 PDT 2026
https://github.com/KseniyaTikhomirova updated https://github.com/llvm/llvm-project/pull/188793
>From 3683423bfa6e1de9fa2fba8bee44285d81b8587c Mon Sep 17 00:00:00 2001
From: "Tikhomirova, Kseniya" <kseniya.tikhomirova at intel.com>
Date: Wed, 25 Mar 2026 04:02:52 -0700
Subject: [PATCH 1/2] [libsycl] add sycl::event and wait functionality to event
& queue
Signed-off-by: Tikhomirova, Kseniya <kseniya.tikhomirova at intel.com>
---
libsycl/docs/index.rst | 11 +++-
libsycl/include/sycl/__impl/event.hpp | 90 +++++++++++++++++++++++++++
libsycl/include/sycl/__impl/queue.hpp | 7 +++
libsycl/include/sycl/sycl.hpp | 1 +
libsycl/src/CMakeLists.txt | 2 +
libsycl/src/detail/event_impl.cpp | 39 ++++++++++++
libsycl/src/detail/event_impl.hpp | 68 ++++++++++++++++++++
libsycl/src/detail/queue_impl.cpp | 14 ++++-
libsycl/src/detail/queue_impl.hpp | 9 ++-
libsycl/src/event.cpp | 25 ++++++++
libsycl/src/queue.cpp | 2 +
11 files changed, 264 insertions(+), 4 deletions(-)
create mode 100644 libsycl/include/sycl/__impl/event.hpp
create mode 100644 libsycl/src/detail/event_impl.cpp
create mode 100644 libsycl/src/detail/event_impl.hpp
create mode 100644 libsycl/src/event.cpp
diff --git a/libsycl/docs/index.rst b/libsycl/docs/index.rst
index 03f7fb7c0876e..9aa36b4a54c57 100644
--- a/libsycl/docs/index.rst
+++ b/libsycl/docs/index.rst
@@ -106,7 +106,14 @@ TODO for added SYCL classes
* device selection: to add compatibility with old SYCL 1.2.1 device selectors, still part of SYCL 2020 specification
* ``context``: to implement get_info, properties & public constructors once context support is added to liboffload
-* ``queue``: to implement USM methods, to implement synchronization methods, to implement submit & copy with accessors (low priority), get_info & properties, ctors that accepts context (blocked by lack of liboffload support)
+* ``queue``:
+
+ * to implement USM methods
+ * to implement synchronization methods
+ * to implement submit & copy with accessors (low priority)
+ * get_info & properties
+ * ctors that accepts context (blocked by lack of liboffload support)
+
* ``property_list``: to fully implement and integrate with existing SYCL runtime classes supporting it
* usm allocations:
@@ -114,7 +121,7 @@ TODO for added SYCL classes
* forward templated funcs to alignment methods (rewrite current impl)
* handle sub devices once they are implemented (blocked by liboffload support)
-
+* ``event``: get_wait_list, get_info, get_profiling_info, wait_and_throw & default ctor are not implemented
* general opens:
* define a way to report errors from object dtors.
\ No newline at end of file
diff --git a/libsycl/include/sycl/__impl/event.hpp b/libsycl/include/sycl/__impl/event.hpp
new file mode 100644
index 0000000000000..7df095c9a1fd1
--- /dev/null
+++ b/libsycl/include/sycl/__impl/event.hpp
@@ -0,0 +1,90 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the declaration of the SYCL event class (SYCL
+/// 2020 4.6.6.), that represents the status of an operation that is being
+/// executed by the SYCL runtime.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBSYCL___IMPL_EVENT_HPP
+#define _LIBSYCL___IMPL_EVENT_HPP
+
+#include <sycl/__impl/backend.hpp>
+#include <sycl/__impl/detail/config.hpp>
+#include <sycl/__impl/detail/obj_utils.hpp>
+#include <sycl/__impl/info/desc_base.hpp>
+
+#include <memory>
+#include <vector>
+
+_LIBSYCL_BEGIN_NAMESPACE_SYCL
+
+class event;
+
+namespace detail {
+class EventImpl;
+template <typename T>
+using is_event_info_desc_t = typename is_info_desc<T, event>::return_type;
+} // namespace detail
+
+/// SYCL 2020 4.6.6. Event class.
+class _LIBSYCL_EXPORT event {
+public:
+ event(const event &rhs) = default;
+
+ event(event &&rhs) = default;
+
+ event &operator=(const event &rhs) = default;
+
+ event &operator=(event &&rhs) = default;
+
+ friend bool operator==(const event &lhs, const event &rhs) {
+ return lhs.impl == rhs.impl;
+ }
+
+ friend bool operator!=(const event &lhs, const event &rhs) {
+ return !(lhs == rhs);
+ }
+
+ /// \return the backend associated with this platform.
+ backend get_backend() const noexcept;
+
+ /// Blocks until all commands associated with this event and any dependent
+ /// events have completed.
+ void wait();
+
+ /// Behaves as if calling event::wait on each event in eventList.
+ static void wait(const std::vector<event> &eventList);
+
+ /// Queries this SYCL event for information.
+ ///
+ /// \return depends on the information being requested.
+ template <typename Param>
+ detail::is_event_info_desc_t<Param> get_info() const;
+
+ /// Queries this SYCL event for SYCL backend-specific information.
+ ///
+ /// \return depends on information being queried.
+ template <typename Param>
+ typename Param::return_type get_backend_info() const;
+
+private:
+ event(std::shared_ptr<detail::EventImpl> Impl) : impl(Impl) {}
+ std::shared_ptr<detail::EventImpl> impl;
+
+ friend sycl::detail::ImplUtils;
+};
+
+_LIBSYCL_END_NAMESPACE_SYCL
+
+template <>
+struct std::hash<sycl::event> : public sycl::detail::HashBase<sycl::event> {};
+
+#endif // _LIBSYCL___IMPL_EVENT_HPP
diff --git a/libsycl/include/sycl/__impl/queue.hpp b/libsycl/include/sycl/__impl/queue.hpp
index a440959c6311f..587f56a8eb245 100644
--- a/libsycl/include/sycl/__impl/queue.hpp
+++ b/libsycl/include/sycl/__impl/queue.hpp
@@ -17,6 +17,7 @@
#include <sycl/__impl/async_handler.hpp>
#include <sycl/__impl/device.hpp>
+#include <sycl/__impl/event.hpp>
#include <sycl/__impl/property_list.hpp>
#include <sycl/__impl/detail/config.hpp>
@@ -29,6 +30,7 @@ class context;
namespace detail {
class QueueImpl;
+
} // namespace detail
// SYCL 2020 4.6.5. Queue class.
@@ -136,6 +138,11 @@ class _LIBSYCL_EXPORT queue {
template <typename Param>
typename Param::return_type get_backend_info() const;
+ /// Blocks the calling thread until all commands previously submitted to this
+ /// queue have completed. Synchronous errors are reported through SYCL
+ /// exceptions.
+ void wait();
+
private:
queue(const std::shared_ptr<detail::QueueImpl> &Impl) : impl(Impl) {}
std::shared_ptr<detail::QueueImpl> impl;
diff --git a/libsycl/include/sycl/sycl.hpp b/libsycl/include/sycl/sycl.hpp
index 3fcf088f45535..ce9fc8defd90b 100644
--- a/libsycl/include/sycl/sycl.hpp
+++ b/libsycl/include/sycl/sycl.hpp
@@ -17,6 +17,7 @@
#include <sycl/__impl/context.hpp>
#include <sycl/__impl/device.hpp>
#include <sycl/__impl/device_selector.hpp>
+#include <sycl/__impl/event.hpp>
#include <sycl/__impl/exception.hpp>
#include <sycl/__impl/platform.hpp>
#include <sycl/__impl/queue.hpp>
diff --git a/libsycl/src/CMakeLists.txt b/libsycl/src/CMakeLists.txt
index 4501005e433e3..7b9826fb8a3de 100644
--- a/libsycl/src/CMakeLists.txt
+++ b/libsycl/src/CMakeLists.txt
@@ -85,6 +85,7 @@ endfunction(add_sycl_rt_library)
set(LIBSYCL_SOURCES
"context.cpp"
+ "event.cpp"
"exception.cpp"
"exception_list.cpp"
"device.cpp"
@@ -93,6 +94,7 @@ set(LIBSYCL_SOURCES
"queue.cpp"
"usm_functions.cpp"
"detail/context_impl.cpp"
+ "detail/event_impl.cpp"
"detail/device_impl.cpp"
"detail/global_objects.cpp"
"detail/platform_impl.cpp"
diff --git a/libsycl/src/detail/event_impl.cpp b/libsycl/src/detail/event_impl.cpp
new file mode 100644
index 0000000000000..895f8029d4c35
--- /dev/null
+++ b/libsycl/src/detail/event_impl.cpp
@@ -0,0 +1,39 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <detail/event_impl.hpp>
+#include <detail/platform_impl.hpp>
+
+_LIBSYCL_BEGIN_NAMESPACE_SYCL
+
+namespace detail {
+
+EventImpl::~EventImpl() {
+ if (MOffloadEvent)
+ std::ignore = olDestroyEvent(MOffloadEvent);
+}
+
+backend EventImpl::getBackend() const noexcept {
+ // TODO: to handle default cosntructed
+ // The event is constructed as though it were created from a
+ // default-constructed queue. Therefore, its backend is the same as the
+ // backend of the device selected by default_selector_v.
+ return MPlatform.getBackend();
+}
+
+void EventImpl::wait() {
+ // MOffloadEvent == nullptr when event is default constructed. Default
+ // constructed event is immediately ready.
+ if (!MOffloadEvent)
+ return;
+
+ callAndThrow(olSyncEvent, MOffloadEvent);
+}
+
+} // namespace detail
+_LIBSYCL_END_NAMESPACE_SYCL
diff --git a/libsycl/src/detail/event_impl.hpp b/libsycl/src/detail/event_impl.hpp
new file mode 100644
index 0000000000000..f570538512def
--- /dev/null
+++ b/libsycl/src/detail/event_impl.hpp
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBSYCL_EVENT_IMPL
+#define _LIBSYCL_EVENT_IMPL
+
+#include <sycl/__impl/detail/config.hpp>
+#include <sycl/__impl/queue.hpp>
+
+#include <OffloadAPI.h>
+
+#include <memory>
+
+_LIBSYCL_BEGIN_NAMESPACE_SYCL
+namespace detail {
+
+class PlatformImpl;
+
+class EventImpl {
+ // Helper to limit EventImpl creation.
+ struct PrivateTag {
+ explicit PrivateTag() = default;
+ };
+
+public:
+ /// Constructs a SYCL event instance using the provided
+ /// offload event instance.
+ ///
+ /// \param Event is a raw offload library handle representing event.
+ /// \param Platform is a platform this event belongs to.
+ EventImpl(ol_event_handle_t Event, PlatformImpl &Platform, PrivateTag)
+ : MOffloadEvent(Event), MPlatform(Platform) {}
+
+ static std::shared_ptr<EventImpl>
+ createEventWithHandle(ol_event_handle_t Event, PlatformImpl &Queue) {
+ return std::make_shared<EventImpl>(Event, Queue, PrivateTag{});
+ }
+
+ /// Releases handle to the corresponding liboffload event.
+ ~EventImpl();
+
+ /// \return the sycl::backend associated with this event.
+ backend getBackend() const noexcept;
+
+ /// Waits for completion of the corresponding kernel and its dependencies.
+ void wait();
+
+ /// \return liboffload handle that this SYCL event represents.
+ ol_event_handle_t getHandle() { return MOffloadEvent; }
+
+ /// \return a platform implementation object this event belongs to.
+ const PlatformImpl &getPlatformImpl() const { return MPlatform; }
+
+private:
+ ol_event_handle_t MOffloadEvent{};
+ PlatformImpl &MPlatform;
+};
+
+} // namespace detail
+
+_LIBSYCL_END_NAMESPACE_SYCL
+
+#endif // _LIBSYCL_EVENT_IMPL
diff --git a/libsycl/src/detail/queue_impl.cpp b/libsycl/src/detail/queue_impl.cpp
index 9c93fe02de8a6..74ccc48877c09 100644
--- a/libsycl/src/detail/queue_impl.cpp
+++ b/libsycl/src/detail/queue_impl.cpp
@@ -9,6 +9,8 @@
#include <detail/queue_impl.hpp>
#include <detail/device_impl.hpp>
+#include <detail/event_impl.hpp>
+#include <detail/program_manager.hpp>
_LIBSYCL_BEGIN_NAMESPACE_SYCL
@@ -18,9 +20,19 @@ QueueImpl::QueueImpl(DeviceImpl &deviceImpl, const async_handler &asyncHandler,
const property_list &propList, PrivateTag)
: MIsInorder(false), MAsyncHandler(asyncHandler), MPropList(propList),
MDevice(deviceImpl),
- MContext(MDevice.getPlatformImpl().getDefaultContext()) {}
+ MContext(MDevice.getPlatformImpl().getDefaultContext()) {
+ callAndThrow(olCreateQueue, MDevice.getHandle(), &MOffloadQueue);
+}
+
+QueueImpl::~QueueImpl() {
+ // TODO: consider where to report errors
+ if (MOffloadQueue)
+ std::ignore = olDestroyQueue(MOffloadQueue);
+}
backend QueueImpl::getBackend() const noexcept { return MDevice.getBackend(); }
+void QueueImpl::wait() { callAndThrow(olSyncQueue, MOffloadQueue); }
+
} // namespace detail
_LIBSYCL_END_NAMESPACE_SYCL
diff --git a/libsycl/src/detail/queue_impl.hpp b/libsycl/src/detail/queue_impl.hpp
index 6403099a19060..cdb7595e852ec 100644
--- a/libsycl/src/detail/queue_impl.hpp
+++ b/libsycl/src/detail/queue_impl.hpp
@@ -21,6 +21,9 @@ namespace detail {
class ContextImpl;
class DeviceImpl;
+class EventImpl;
+
+using EventImplPtr = std::shared_ptr<EventImpl>;
class QueueImpl : public std::enable_shared_from_this<QueueImpl> {
struct PrivateTag {
@@ -28,7 +31,7 @@ class QueueImpl : public std::enable_shared_from_this<QueueImpl> {
};
public:
- ~QueueImpl() = default;
+ ~QueueImpl();
/// Constructs a SYCL queue from a device using an asyncHandler and
/// a propList.
@@ -59,7 +62,11 @@ class QueueImpl : public std::enable_shared_from_this<QueueImpl> {
/// \return true if and only if the queue is in order.
bool isInOrder() const { return MIsInorder; }
+ /// Waits for completion of all kernels submitted to this queue.
+ void wait();
+
private:
+ ol_queue_handle_t MOffloadQueue = {};
const bool MIsInorder;
const async_handler MAsyncHandler;
const property_list MPropList;
diff --git a/libsycl/src/event.cpp b/libsycl/src/event.cpp
new file mode 100644
index 0000000000000..68046211272f2
--- /dev/null
+++ b/libsycl/src/event.cpp
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <sycl/__impl/event.hpp>
+
+#include <detail/event_impl.hpp>
+
+_LIBSYCL_BEGIN_NAMESPACE_SYCL
+
+backend event::get_backend() const noexcept { return impl->getBackend(); }
+
+void event::wait(const std::vector<event> &EventList) {
+ for (auto Event : EventList) {
+ Event.wait();
+ }
+}
+
+void event::wait() { return impl->wait(); }
+
+_LIBSYCL_END_NAMESPACE_SYCL
diff --git a/libsycl/src/queue.cpp b/libsycl/src/queue.cpp
index faed274674447..9fe020eabf2cc 100644
--- a/libsycl/src/queue.cpp
+++ b/libsycl/src/queue.cpp
@@ -33,4 +33,6 @@ device queue::get_device() const {
bool queue::is_in_order() const { return impl->isInOrder(); }
+void queue::wait() { return impl->wait(); }
+
_LIBSYCL_END_NAMESPACE_SYCL
>From 468de5c542a16f81a27980e8f7cfca9d51925240 Mon Sep 17 00:00:00 2001
From: "Tikhomirova, Kseniya" <kseniya.tikhomirova at intel.com>
Date: Mon, 30 Mar 2026 06:49:08 -0700
Subject: [PATCH 2/2] apply comments
Signed-off-by: Tikhomirova, Kseniya <kseniya.tikhomirova at intel.com>
---
libsycl/include/sycl/__impl/event.hpp | 2 +-
libsycl/include/sycl/__impl/queue.hpp | 1 -
libsycl/src/detail/event_impl.cpp | 9 +++------
libsycl/src/detail/event_impl.hpp | 20 ++++++++++----------
libsycl/src/detail/queue_impl.hpp | 4 +---
libsycl/src/event.cpp | 2 +-
libsycl/src/queue.cpp | 2 +-
7 files changed, 17 insertions(+), 23 deletions(-)
diff --git a/libsycl/include/sycl/__impl/event.hpp b/libsycl/include/sycl/__impl/event.hpp
index 7df095c9a1fd1..d0b618313c386 100644
--- a/libsycl/include/sycl/__impl/event.hpp
+++ b/libsycl/include/sycl/__impl/event.hpp
@@ -53,7 +53,7 @@ class _LIBSYCL_EXPORT event {
return !(lhs == rhs);
}
- /// \return the backend associated with this platform.
+ /// \return the backend associated with this event.
backend get_backend() const noexcept;
/// Blocks until all commands associated with this event and any dependent
diff --git a/libsycl/include/sycl/__impl/queue.hpp b/libsycl/include/sycl/__impl/queue.hpp
index 587f56a8eb245..bdad13b091c8f 100644
--- a/libsycl/include/sycl/__impl/queue.hpp
+++ b/libsycl/include/sycl/__impl/queue.hpp
@@ -30,7 +30,6 @@ class context;
namespace detail {
class QueueImpl;
-
} // namespace detail
// SYCL 2020 4.6.5. Queue class.
diff --git a/libsycl/src/detail/event_impl.cpp b/libsycl/src/detail/event_impl.cpp
index 895f8029d4c35..7b76adbf8df96 100644
--- a/libsycl/src/detail/event_impl.cpp
+++ b/libsycl/src/detail/event_impl.cpp
@@ -19,16 +19,13 @@ EventImpl::~EventImpl() {
}
backend EventImpl::getBackend() const noexcept {
- // TODO: to handle default cosntructed
- // The event is constructed as though it were created from a
- // default-constructed queue. Therefore, its backend is the same as the
- // backend of the device selected by default_selector_v.
+ // TODO: to handle default constructed.
return MPlatform.getBackend();
}
void EventImpl::wait() {
- // MOffloadEvent == nullptr when event is default constructed. Default
- // constructed event is immediately ready.
+ // MOffloadEvent == nullptr when the event is default constructed. Default
+ // constructed event is immediately ready.
if (!MOffloadEvent)
return;
diff --git a/libsycl/src/detail/event_impl.hpp b/libsycl/src/detail/event_impl.hpp
index f570538512def..a321763f6c1f0 100644
--- a/libsycl/src/detail/event_impl.hpp
+++ b/libsycl/src/detail/event_impl.hpp
@@ -9,8 +9,8 @@
#ifndef _LIBSYCL_EVENT_IMPL
#define _LIBSYCL_EVENT_IMPL
+#include <sycl/__impl/backend.hpp>
#include <sycl/__impl/detail/config.hpp>
-#include <sycl/__impl/queue.hpp>
#include <OffloadAPI.h>
@@ -28,32 +28,32 @@ class EventImpl {
};
public:
- /// Constructs a SYCL event instance using the provided
+ /// Constructs a SYCL event instance using the provided
/// offload event instance.
///
- /// \param Event is a raw offload library handle representing event.
- /// \param Platform is a platform this event belongs to.
+ /// \param Event is the raw offload library handle representing the event.
+ /// \param Platform is the platform this event belongs to.
EventImpl(ol_event_handle_t Event, PlatformImpl &Platform, PrivateTag)
: MOffloadEvent(Event), MPlatform(Platform) {}
static std::shared_ptr<EventImpl>
- createEventWithHandle(ol_event_handle_t Event, PlatformImpl &Queue) {
- return std::make_shared<EventImpl>(Event, Queue, PrivateTag{});
+ createEventWithHandle(ol_event_handle_t Event, PlatformImpl &Platform) {
+ return std::make_shared<EventImpl>(Event, Platform, PrivateTag{});
}
- /// Releases handle to the corresponding liboffload event.
+ /// Releases the handle to the corresponding liboffload event.
~EventImpl();
/// \return the sycl::backend associated with this event.
backend getBackend() const noexcept;
- /// Waits for completion of the corresponding kernel and its dependencies.
+ /// Waits for completion of the corresponding command and its dependencies.
void wait();
- /// \return liboffload handle that this SYCL event represents.
+ /// \return the liboffload handle that this SYCL event represents.
ol_event_handle_t getHandle() { return MOffloadEvent; }
- /// \return a platform implementation object this event belongs to.
+ /// \return the platform implementation object this event belongs to.
const PlatformImpl &getPlatformImpl() const { return MPlatform; }
private:
diff --git a/libsycl/src/detail/queue_impl.hpp b/libsycl/src/detail/queue_impl.hpp
index cdb7595e852ec..c3bcd0fd87a58 100644
--- a/libsycl/src/detail/queue_impl.hpp
+++ b/libsycl/src/detail/queue_impl.hpp
@@ -23,8 +23,6 @@ class ContextImpl;
class DeviceImpl;
class EventImpl;
-using EventImplPtr = std::shared_ptr<EventImpl>;
-
class QueueImpl : public std::enable_shared_from_this<QueueImpl> {
struct PrivateTag {
explicit PrivateTag() = default;
@@ -62,7 +60,7 @@ class QueueImpl : public std::enable_shared_from_this<QueueImpl> {
/// \return true if and only if the queue is in order.
bool isInOrder() const { return MIsInorder; }
- /// Waits for completion of all kernels submitted to this queue.
+ /// Waits for completion of all commands submitted to this queue.
void wait();
private:
diff --git a/libsycl/src/event.cpp b/libsycl/src/event.cpp
index 68046211272f2..c0276b519f173 100644
--- a/libsycl/src/event.cpp
+++ b/libsycl/src/event.cpp
@@ -20,6 +20,6 @@ void event::wait(const std::vector<event> &EventList) {
}
}
-void event::wait() { return impl->wait(); }
+void event::wait() { impl->wait(); }
_LIBSYCL_END_NAMESPACE_SYCL
diff --git a/libsycl/src/queue.cpp b/libsycl/src/queue.cpp
index 9fe020eabf2cc..6584a6e080ec3 100644
--- a/libsycl/src/queue.cpp
+++ b/libsycl/src/queue.cpp
@@ -33,6 +33,6 @@ device queue::get_device() const {
bool queue::is_in_order() const { return impl->isInOrder(); }
-void queue::wait() { return impl->wait(); }
+void queue::wait() { impl->wait(); }
_LIBSYCL_END_NAMESPACE_SYCL
More information about the llvm-branch-commits
mailing list