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 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
81  template __SYCL_EXPORT ReturnT event::get_info<info::event::Desc>() const;
82 
83 #include <sycl/info/event_traits.def>
84 
85 #undef __SYCL_PARAM_TRAITS_SPEC
86 
87 #define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
88  template <> \
89  __SYCL_EXPORT ReturnT event::get_profiling_info<info::DescType::Desc>() \
90  const { \
91  impl->wait(impl); \
92  return impl->get_profiling_info<info::DescType::Desc>(); \
93  }
94 
95 #include <sycl/info/event_profiling_traits.def>
96 
97 #undef __SYCL_PARAM_TRAITS_SPEC
98 
99 backend event::get_backend() const noexcept { return getImplBackend(impl); }
100 
101 pi_native_handle event::getNative() const { return impl->getNative(); }
102 
103 std::vector<pi_native_handle> event::getNativeVector() const {
104  std::vector<pi_native_handle> ReturnVector = {impl->getNative()};
105  return ReturnVector;
106 }
107 
108 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
109 } // 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:13
context.hpp
event.hpp
sycl
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:13
sycl::_V1::event
An event object can be used to synchronize memory transfers, enqueues of kernels and signaling barrie...
Definition: event.hpp:38
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:99
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:103
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:1424
std
Definition: accessor.hpp:3071
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::event::operator!=
bool operator!=(const event &rhs) const
Definition: event.cpp:38
sycl::_V1::detail::pi::PiEvent
::pi_event PiEvent
Definition: pi.hpp:121
sycl::_V1::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:39