DPC++ Runtime
Runtime libraries for oneAPI DPC++
event.cpp
Go to the documentation of this file.
1 //==---------------- event.cpp --- 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 
10 #include <detail/context_impl.hpp>
11 #include <detail/event_impl.hpp>
13 #include <sycl/context.hpp>
14 #include <sycl/detail/common.hpp>
15 #include <sycl/detail/pi.hpp>
16 #include <sycl/event.hpp>
17 #include <sycl/info/info_desc.hpp>
18 
19 #include <memory>
20 #include <unordered_set>
21 
22 namespace sycl {
23 inline namespace _V1 {
24 
25 event::event() : impl(std::make_shared<detail::event_impl>(std::nullopt)) {}
26 
27 event::event(cl_event ClEvent, const context &SyclContext)
28  : impl(std::make_shared<detail::event_impl>(
29  detail::pi::cast<sycl::detail::pi::PiEvent>(ClEvent), SyclContext)) {
30  // This is a special interop constructor for OpenCL, so the event must be
31  // retained.
32  impl->getPlugin()->call<detail::PiApiKind::piEventRetain>(
33  detail::pi::cast<sycl::detail::pi::PiEvent>(ClEvent));
34 }
35 
36 bool event::operator==(const event &rhs) const { return rhs.impl == impl; }
37 
38 bool event::operator!=(const event &rhs) const { return !(*this == rhs); }
39 
40 bool event::is_host() const {
41  bool IsHost = impl->is_host();
42  assert(!IsHost && "event::is_host should not be called in implementation.");
43  return IsHost;
44 }
45 
46 void event::wait() { impl->wait(impl); }
47 
48 void event::wait(const std::vector<event> &EventList) {
49  for (auto E : EventList) {
50  E.wait();
51  }
52 }
53 
54 void event::wait_and_throw() { impl->wait_and_throw(impl); }
55 
56 void event::wait_and_throw(const std::vector<event> &EventList) {
57  for (auto E : EventList) {
58  E.wait_and_throw();
59  }
60 }
61 
62 std::vector<event> event::get_wait_list() {
63  std::vector<event> Result;
64 
65  for (auto &EventImpl : impl->getWaitList())
66  Result.push_back(detail::createSyclObjFromImpl<event>(EventImpl));
67 
68  return Result;
69 }
70 
71 event::event(std::shared_ptr<detail::event_impl> event_impl)
72  : impl(event_impl) {}
73 
74 template <typename Param>
75 typename detail::is_event_info_desc<Param>::return_type
76 event::get_info() const {
77  return impl->template get_info<Param>();
78 }
79 
80 template <typename Param>
83  return impl->get_backend_info<Param>();
84 }
85 
86 template <typename Param>
89  if (impl->getCommandGraph()) {
91  "Profiling information is unavailable for events "
92  "returned from a submission to a queue in the "
93  "recording state.");
94  }
95 
96  if constexpr (!std::is_same_v<Param, info::event_profiling::command_submit>) {
97  impl->wait(impl);
98  }
99  return impl->template get_profiling_info<Param>();
100 }
101 
102 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
103  template __SYCL_EXPORT ReturnT event::get_info<info::event::Desc>() const;
104 
105 #include <sycl/info/event_traits.def>
106 
107 #undef __SYCL_PARAM_TRAITS_SPEC
108 
109 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, Picode) \
110  template __SYCL_EXPORT ReturnT \
111  event::get_backend_info<info::DescType::Desc>() const;
112 
113 #include <sycl/info/sycl_backend_traits.def>
114 
115 #undef __SYCL_PARAM_TRAITS_SPEC
116 
117 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
118  template __SYCL_EXPORT ReturnT \
119  event::get_profiling_info<info::DescType::Desc>() const;
120 
121 #include <sycl/info/event_profiling_traits.def>
122 
123 #undef __SYCL_PARAM_TRAITS_SPEC
124 
126 
127 pi_native_handle event::getNative() const { return impl->getNative(); }
128 
129 std::vector<pi_native_handle> event::getNativeVector() const {
130  std::vector<pi_native_handle> ReturnVector = {impl->getNative()};
131  return ReturnVector;
132 }
133 
134 } // namespace _V1
135 } // namespace sycl
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:51
An event object can be used to synchronize memory transfers, enqueues of kernels and signaling barrie...
Definition: event.hpp:44
std::vector< event > get_wait_list()
Return the list of events that this event waits for.
Definition: event.cpp:62
void wait()
Wait for the event.
Definition: event.cpp:46
event()
Constructs a ready SYCL event.
Definition: event.cpp:25
bool operator!=(const event &rhs) const
Definition: event.cpp:38
backend get_backend() const noexcept
Returns the backend associated with this platform.
Definition: event.cpp:125
bool operator==(const event &rhs) const
Definition: event.cpp:36
void wait_and_throw()
Wait for the event.
Definition: event.cpp:54
detail::is_event_profiling_info_desc< Param >::return_type get_profiling_info() const
Queries this SYCL event for profiling information.
Definition: event.cpp:88
detail::is_event_info_desc< Param >::return_type get_info() const
Queries this SYCL event for information.
Definition: event.cpp:76
detail::is_backend_info_desc< Param >::return_type get_backend_info() const
Queries this SYCL event for SYCL backend-specific information.
Definition: event.cpp:82
::pi_event PiEvent
Definition: pi.hpp:143
PiProgram cast(cl_program)=delete
backend getImplBackend(const T &Impl)
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
Definition: exception.cpp:87
Definition: access.hpp:18
uintptr_t pi_native_handle
Definition: pi.h:217
pi_result piEventRetain(pi_event event)
Definition: pi_cuda.cpp:615
C++ wrapper of extern "C" PI interfaces.
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324