17#include <shared_mutex>
22# include <sycl/sycl.hpp>
28 template<
typename T_Device>
29 struct Event : std::enable_shared_from_this<Event<T_Device>>
32 friend struct alpaka::internal::GetApi;
35 Event(internal::concepts::DeviceHandle
auto device, uint32_t
const idx)
36 : m_device(std::move(
device))
42 Event(Event
const&) =
delete;
43 Event& operator=(Event
const&) =
delete;
45 Event(Event&&) =
delete;
46 Event& operator=(Event&&) =
delete;
53 getEvent().wait_and_throw();
55 catch(sycl::exception
const& err)
57 std::cerr <<
"Caught SYCL exception while destructing a SYCL event: " << err.what() <<
" ("
58 << err.code() <<
')' << std::endl;
60 catch(std::exception
const& err)
62 std::cerr <<
"The following runtime error(s) occurred while destructing a SYCL event:"
63 << err.what() << std::endl;
67 std::shared_ptr<Event> getSharedPtr()
69 return this->shared_from_this();
80 getEvent().wait_and_throw();
86 ss <<
"Queue<" <<
getApi(m_device).getName() <<
">";
87 ss <<
" id=" << m_idx;
92 friend struct alpaka::internal::GetDeviceType;
93 friend struct alpaka::onHost::internal::Enqueue;
97 return alpaka::internal::getDeviceKind(*m_device.get());
100 auto getDevice()
const
105 friend struct onHost::internal::GetDevice;
107 friend struct onHost::internal::IsEventComplete;
113 bool isEventComplete() noexcept
115 auto const status = getEvent().template get_info<sycl::info::event::command_execution_status>();
116 return (status == sycl::info::event_command_status::complete);
119 friend struct internal::WaitFor;
120 friend struct internal::Wait;
122 void setEvent(sycl::event
const& event)
124 std::unique_lock<std::shared_mutex> lock{m_eventGuard};
128 sycl::event getEvent()
const
130 std::shared_lock<std::shared_mutex> lock{m_eventGuard};
134 Handle<T_Device> m_device;
136 mutable std::shared_mutex m_eventGuard;
139 sycl::event m_event{};
147namespace alpaka::internal
150 template<
typename T_Device>
151 struct GetApi::Op<
alpaka::onHost::syclGeneric::Event<T_Device>>
153 inline constexpr auto operator()(
auto&& event)
const
#define ALPAKA_LOG_FUNCTION(logLvl)
Log the entry and exit of a scope.
Functionality which is usable on the host CPU controller thread.
auto getNativeHandle(auto const &handle)
Get the native handle of an handle.
Event(Handle< T_Event > &&) -> Event< Device< ALPAKA_TYPEOF(alpaka::internal::getApi(std::declval< T_Event >())), ALPAKA_TYPEOF(alpaka::internal::getDeviceKind(std::declval< T_Event >()))> >
std::convertible_to< std::string > auto getName(auto &&any)
Runtime name for a given object.
void wait(alpaka::concepts::HasGet auto &handle)
wait for all work to be finished
constexpr decltype(auto) getDeviceKind(auto &&any)
Get the device type of an object.
constexpr decltype(auto) getApi(auto &&any)
Get the API an object depends on.