DPC++ Runtime
Runtime libraries for oneAPI DPC++
event.hpp
Go to the documentation of this file.
1 //==---------------- event.hpp --- SYCL event ------------------------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <sycl/backend_types.hpp> // for backend, backend_return_t
12 #include <sycl/detail/defines_elementary.hpp> // for __SYCL2020_DEPRECATED
13 #include <sycl/detail/export.hpp> // for __SYCL_EXPORT
14 #include <sycl/detail/info_desc_helpers.hpp> // for is_event_info_desc, is_...
15 #include <sycl/detail/owner_less_base.hpp> // for OwnerLessBase
16 #include <sycl/detail/pi.h> // for pi_native_handle
17 
18 #ifdef __SYCL_INTERNAL_API
19 #include <sycl/detail/cl.h>
20 #endif
21 
22 #include <cstddef> // for size_t
23 #include <memory> // for shared_ptr, hash
24 #include <variant> // for hash
25 #include <vector> // for vector
26 
27 namespace sycl {
28 inline namespace _V1 {
29 // Forward declaration
30 class context;
31 
32 template <backend BackendName, class SyclObjectT>
33 auto get_native(const SyclObjectT &Obj)
34  -> backend_return_t<BackendName, SyclObjectT>;
35 
36 namespace detail {
37 class event_impl;
38 }
39 
44 class __SYCL_EXPORT event : public detail::OwnerLessBase<event> {
45 public:
49  event();
50 
57 #ifdef __SYCL_INTERNAL_API
58  event(cl_event ClEvent, const context &SyclContext);
59 #endif
60 
61  event(const event &rhs) = default;
62 
63  event(event &&rhs) = default;
64 
65  event &operator=(const event &rhs) = default;
66 
67  event &operator=(event &&rhs) = default;
68 
69  bool operator==(const event &rhs) const;
70 
71  bool operator!=(const event &rhs) const;
72 
77  "is_host() is deprecated as the host device is no longer supported.")
78  bool is_host() const;
79 
86  std::vector<event> get_wait_list();
87 
89  void wait();
90 
94  static void wait(const std::vector<event> &EventList);
95 
101  void wait_and_throw();
102 
110  static void wait_and_throw(const std::vector<event> &EventList);
111 
115  template <typename Param>
116  typename detail::is_event_info_desc<Param>::return_type get_info() const;
117 
121  template <typename Param>
122  typename detail::is_backend_info_desc<Param>::return_type
123  get_backend_info() const;
124 
136  template <typename Param>
137  typename detail::is_event_profiling_info_desc<Param>::return_type
138  get_profiling_info() const;
139 
143  backend get_backend() const noexcept;
144 
145 private:
146  event(std::shared_ptr<detail::event_impl> EventImpl);
147 
148  pi_native_handle getNative() const;
149 
150  std::vector<pi_native_handle> getNativeVector() const;
151 
152  std::shared_ptr<detail::event_impl> impl;
153 
154  template <class Obj>
155  friend decltype(Obj::impl) detail::getSyclObjImpl(const Obj &SyclObject);
156 
157  template <class T>
158  friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
159 
160  template <backend BackendName, class SyclObjectT>
161  friend auto get_native(const SyclObjectT &Obj)
162  -> backend_return_t<BackendName, SyclObjectT>;
163 };
164 
165 } // namespace _V1
166 } // namespace sycl
167 
168 namespace std {
169 template <> struct hash<sycl::event> {
170  size_t operator()(const sycl::event &e) const {
171  return hash<std::shared_ptr<sycl::detail::event_impl>>()(
173  }
174 };
175 } // namespace std
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:50
An event object can be used to synchronize memory transfers, enqueues of kernels and signaling barrie...
Definition: event.hpp:44
event & operator=(event &&rhs)=default
__SYCL2020_DEPRECATED("is_host() is deprecated as the host device is no longer supported.") bool is_host() const
Checks if this event is a SYCL host event.
event(const event &rhs)=default
Constructs a SYCL event instance from an OpenCL cl_event.
event(event &&rhs)=default
event & operator=(const event &rhs)=default
decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject)
Definition: impl_utils.hpp:30
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: impl_utils.hpp:48
auto get_native(const SyclObjectT &Obj) -> backend_return_t< BackendName, SyclObjectT >
Definition: backend.hpp:136
typename backend_traits< Backend >::template return_type< SyclType > backend_return_t
Definition: backend.hpp:87
Definition: access.hpp:18
static void wait_and_throw(sycl::queue q=get_default_queue())
Definition: device.hpp:761
uintptr_t pi_native_handle
Definition: pi.h:226
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324
size_t operator()(const sycl::event &e) const
Definition: event.hpp:170