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 <ur_api.h> // for ur_native_handle_t
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 
79  std::vector<event> get_wait_list();
80 
82  void wait();
83 
87  static void wait(const std::vector<event> &EventList);
88 
94  void wait_and_throw();
95 
103  static void wait_and_throw(const std::vector<event> &EventList);
104 
108  template <typename Param>
109  typename detail::is_event_info_desc<Param>::return_type get_info() const;
110 
114  template <typename Param>
116  get_backend_info() const;
117 
129  template <typename Param>
131  get_profiling_info() const;
132 
136  backend get_backend() const noexcept;
137 
138 private:
139  event(std::shared_ptr<detail::event_impl> EventImpl);
140 
141  ur_native_handle_t getNative() const;
142 
143  std::vector<ur_native_handle_t> getNativeVector() const;
144 
145  std::shared_ptr<detail::event_impl> impl;
146 
147  template <class Obj>
148  friend const decltype(Obj::impl) &
149  detail::getSyclObjImpl(const Obj &SyclObject);
150 
151  template <class T>
152  friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
153 
154  template <backend BackendName, class SyclObjectT>
155  friend auto get_native(const SyclObjectT &Obj)
156  -> backend_return_t<BackendName, SyclObjectT>;
157 };
158 
159 } // namespace _V1
160 } // namespace sycl
161 
162 namespace std {
163 template <> struct hash<sycl::event> {
164  size_t operator()(const sycl::event &e) const {
165  return hash<std::shared_ptr<sycl::detail::event_impl>>()(
167  }
168 };
169 } // 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
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) const & getSyclObjImpl(const Obj &SyclObject)
Definition: impl_utils.hpp:31
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: impl_utils.hpp:40
auto get_native(const SyclObjectT &Obj) -> backend_return_t< BackendName, SyclObjectT >
Definition: backend.hpp:138
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:889
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324
size_t operator()(const sycl::event &e) const
Definition: event.hpp:164