27#if ALPAKA_LANG_CUDA || ALPAKA_LANG_HIP
36 namespace unifiedCudaHip
38 template<
typename T_Device>
39 struct Event : std::enable_shared_from_this<Event<T_Device>>
41 using ApiInterface =
typename T_Device::ApiInterface;
44 Event(internal::concepts::DeviceHandle
auto device, uint32_t
const idx)
45 : m_device(std::move(
device))
50 ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK(
52 ApiInterface::setDevice(internal::getNativeHandle(*m_device.get())));
64 ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK(
66 ApiInterface::eventCreateWithFlags(
68 ApiInterface::eventDefault | ApiInterface::eventDisableTiming));
74 onHost::internal::wait(*
this);
75 ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK_NOEXCEPT(ApiInterface, ApiInterface::eventDestroy(
getNativeHandle()));
78 Event(Event
const&) =
delete;
79 Event& operator=(Event
const&) =
delete;
81 Event(Event&&) =
delete;
82 Event& operator=(Event&&) =
delete;
86 return m_idx == other.m_idx && m_device == other.m_device;
91 return !(*
this == other);
95 Handle<T_Device> m_device;
97 typename ApiInterface::Event_t m_nativeEvent;
99 friend struct alpaka::internal::GetName;
103 return std::string(
"unifiedCudaHip::Event id=") + std::to_string(m_idx);
106 friend struct onHost::internal::GetNativeHandle;
110 return m_nativeEvent;
113 friend struct onHost::internal::Enqueue;
115 friend struct onHost::internal::Wait;
120 ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK(ApiInterface, ApiInterface::eventSynchronize(
getNativeHandle()));
123 friend struct alpaka::internal::GetDeviceType;
127 return alpaka::internal::getDeviceKind(*m_device.get());
130 auto getDevice()
const
135 std::shared_ptr<Event> getSharedPtr()
137 return this->shared_from_this();
140 friend struct onHost::internal::IsEventComplete;
142 bool isEventComplete() noexcept
144 typename ApiInterface::Error_t ret = ApiInterface::success;
145 ALPAKA_UNIFORM_CUDA_HIP_RT_CHECK_IGNORE(
147 ret = ApiInterface::eventQuery(m_nativeEvent),
148 ApiInterface::errorNotReady);
149 return (ret == ApiInterface::success);
152 friend struct onHost::internal::GetDevice;
154 friend struct alpaka::internal::GetApi;
160namespace alpaka::internal
162 template<
typename T_Device>
163 struct GetApi::Op<onHost::unifiedCudaHip::Event<T_Device>>
165 inline constexpr auto operator()(
auto&& queue)
const
#define ALPAKA_LOG_FUNCTION(logLvl)
Log the entry and exit of a scope.
constexpr bool operator!=(alpaka::concepts::Api auto lhs, alpaka::concepts::Api auto rhs)
constexpr bool operator==(alpaka::concepts::Api auto lhs, alpaka::concepts::Api auto rhs)
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.