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/event_impl.hpp>
12 #include <sycl/context.hpp>
13 #include <sycl/detail/common.hpp>
14 #include <sycl/detail/pi.hpp>
15 #include <sycl/event.hpp>
16 #include <sycl/info/info_desc.hpp>
17 #include <sycl/stl.hpp>
18 
19 #include <memory>
20 #include <unordered_set>
21 
22 namespace sycl {
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<RT::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<RT::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  if constexpr (!std::is_same_v<Param, info::event_profiling::command_submit>) {
84  impl->wait(impl);
85  }
86  return impl->template get_profiling_info<Param>();
87 }
88 
89 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
90  template __SYCL_EXPORT ReturnT event::get_info<info::event::Desc>() const;
91 
92 #include <sycl/info/event_traits.def>
93 
94 #undef __SYCL_PARAM_TRAITS_SPEC
95 
96 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
97  template __SYCL_EXPORT ReturnT \
98  event::get_profiling_info<info::DescType::Desc>() const;
99 
100 #include <sycl/info/event_profiling_traits.def>
101 
102 #undef __SYCL_PARAM_TRAITS_SPEC
103 
104 backend event::get_backend() const noexcept { return getImplBackend(impl); }
105 
106 pi_native_handle event::getNative() const { return impl->getNative(); }
107 
108 std::vector<pi_native_handle> event::getNativeVector() const {
109  std::vector<pi_native_handle> ReturnVector = {impl->getNative()};
110  return ReturnVector;
111 }
112 
113 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
114 } // namespace sycl
event_impl.hpp
sycl::_V1::backend
backend
Definition: backend_types.hpp:21
stl.hpp
__SYCL_INLINE_VER_NAMESPACE
#define __SYCL_INLINE_VER_NAMESPACE(X)
Definition: defines_elementary.hpp:11
context.hpp
event.hpp
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
sycl::_V1::event
An event object can be used to synchronize memory transfers, enqueues of kernels and signaling barrie...
Definition: event.hpp:40
pi.hpp
cast
To cast(From value)
Definition: pi_opencl.cpp:42
scheduler.hpp
sycl::_V1::detail::getImplBackend
backend getImplBackend(const T &Impl)
Definition: backend_impl.hpp:17
sycl::_V1::event::wait
void wait()
Wait for the event.
Definition: event.cpp:46
sycl::_V1::event::wait_and_throw
void wait_and_throw()
Wait for the event.
Definition: event.cpp:54
sycl::_V1::event::get_backend
backend get_backend() const noexcept
Returns the backend associated with this platform.
Definition: event.cpp:104
sycl::_V1::event::event
event()
Constructs a ready SYCL event.
Definition: event.cpp:25
common.hpp
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:133
sycl::_V1::event::get_info
detail::is_event_info_desc< Param >::return_type get_info() const
Queries this SYCL event for information.
Definition: event.cpp:76
piEventRetain
pi_result piEventRetain(pi_event event)
Definition: pi_esimd_emulator.cpp:1478
std
Definition: accessor.hpp:3230
sycl::_V1::event::operator==
bool operator==(const event &rhs) const
Definition: event.cpp:36
backend_impl.hpp
info_desc.hpp
sycl::_V1::event::get_wait_list
std::vector< event > get_wait_list()
Return the list of events that this event waits for.
Definition: event.cpp:62
sycl::_V1::detail::is_event_profiling_info_desc
Definition: info_desc_helpers.hpp:27
sycl::_V1::event::operator!=
bool operator!=(const event &rhs) const
Definition: event.cpp:38
sycl::_V1::detail::pi::PiEvent
::pi_event PiEvent
Definition: pi.hpp:136
sycl::_V1::event::get_profiling_info
detail::is_event_profiling_info_desc< Param >::return_type get_profiling_info() const
Queries this SYCL event for profiling information.
Definition: event.cpp:82
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:41