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 
9 #include <CL/sycl/context.hpp>
11 #include <CL/sycl/detail/pi.hpp>
12 #include <CL/sycl/event.hpp>
14 #include <CL/sycl/stl.hpp>
15 #include <detail/backend_impl.hpp>
16 #include <detail/event_impl.hpp>
18 
19 #include <memory>
20 #include <unordered_set>
21 
23 namespace sycl {
24 
25 event::event() : impl(std::make_shared<detail::event_impl>()) {}
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 
31 bool event::operator==(const event &rhs) const { return rhs.impl == impl; }
32 
33 bool event::operator!=(const event &rhs) const { return !(*this == rhs); }
34 
35 cl_event event::get() const { return impl->get(); }
36 
37 bool event::is_host() const { return impl->is_host(); }
38 
39 void event::wait() { impl->wait(impl); }
40 
41 void event::wait(const std::vector<event> &EventList) {
42  for (auto E : EventList) {
43  E.wait();
44  }
45 }
46 
47 void event::wait_and_throw() { impl->wait_and_throw(impl); }
48 
49 void event::wait_and_throw(const std::vector<event> &EventList) {
50  for (auto E : EventList) {
51  E.wait_and_throw();
52  }
53 }
54 
55 std::vector<event> event::get_wait_list() {
56  std::vector<event> Result;
57 
58  for (auto &EventImpl : impl->getWaitList())
59  Result.push_back(detail::createSyclObjFromImpl<event>(EventImpl));
60 
61  return Result;
62 }
63 
64 event::event(std::shared_ptr<detail::event_impl> event_impl)
65  : impl(event_impl) {}
66 
67 #define __SYCL_PARAM_TRAITS_SPEC(param_type, param, ret_type) \
68  template <> \
69  __SYCL_EXPORT ret_type event::get_info<info::param_type::param>() const { \
70  return impl->get_info<info::param_type::param>(); \
71  }
72 
73 #include <CL/sycl/info/event_traits.def>
74 
75 #undef __SYCL_PARAM_TRAITS_SPEC
76 
77 #define __SYCL_PARAM_TRAITS_SPEC(param_type, param, ret_type) \
78  template <> \
79  __SYCL_EXPORT ret_type event::get_profiling_info<info::param_type::param>() \
80  const { \
81  impl->wait(impl); \
82  return impl->get_profiling_info<info::param_type::param>(); \
83  }
84 
85 #include <CL/sycl/info/event_profiling_traits.def>
86 
87 #undef __SYCL_PARAM_TRAITS_SPEC
88 
89 backend event::get_backend() const noexcept { return getImplBackend(impl); }
90 
91 pi_native_handle event::getNative() const { return impl->getNative(); }
92 
93 std::vector<pi_native_handle> event::getNativeVector() const {
94  std::vector<pi_native_handle> ReturnVector = {impl->getNative()};
95  return ReturnVector;
96 }
97 
98 } // namespace sycl
99 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::event::wait
void wait()
Wait for the event.
Definition: event.cpp:39
cl::sycl::backend
backend
Definition: backend_types.hpp:21
cl::sycl::event::operator!=
bool operator!=(const event &rhs) const
Definition: event.cpp:33
event_impl.hpp
cl::sycl::event::event
event()
Constructs a ready SYCL event.
Definition: event.cpp:25
cl::sycl::event
An event object can be used to synchronize memory transfers, enqueues of kernels and signaling barrie...
Definition: event.hpp:31
stl.hpp
context.hpp
event.hpp
sycl
Definition: invoke_simd.hpp:68
cl::sycl::event::get_backend
backend get_backend() const noexcept
Returns the backend associated with this platform.
Definition: event.cpp:89
cl::sycl::event::operator==
bool operator==(const event &rhs) const
Definition: event.cpp:31
pi.hpp
cast
To cast(From value)
Definition: pi_opencl.cpp:42
scheduler.hpp
cl::sycl::detail::getImplBackend
backend getImplBackend(const T &Impl)
Definition: backend_impl.hpp:16
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
cl::sycl::detail::pi::PiEvent
::pi_event PiEvent
Definition: pi.hpp:113
cl::sycl::event::is_host
bool is_host() const
Returns a valid OpenCL event interoperability handle.
Definition: event.cpp:37
cl::sycl::event::wait_and_throw
void wait_and_throw()
Wait for the event.
Definition: event.cpp:47
pi_native_handle
uintptr_t pi_native_handle
Definition: pi.h:76
cl::sycl::event::get_wait_list
std::vector< event > get_wait_list()
Return the list of events that this event waits for.
Definition: event.cpp:55
std::get
constexpr tuple_element< I, tuple< Types... > >::type & get(cl::sycl::detail::tuple< Types... > &Arg) noexcept
Definition: tuple.hpp:199
cl::sycl::info::event
event
Definition: info_desc.hpp:289
std
Definition: accessor.hpp:2616
cl::sycl::detail::pi
Definition: pi.hpp:51
cl::sycl::context
The context class represents a SYCL context on which kernel functions may be executed.
Definition: context.hpp:35
backend_impl.hpp
info_desc.hpp
common.hpp
cl::sycl::detail::event_impl
Definition: event_impl.hpp:33
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12