kokkos-execution 0.0.1
Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_IMPL_HIP_EVENT_HPP
2#define KOKKOS_EXECUTION_IMPL_HIP_EVENT_HPP
3
4#include "Kokkos_Macros.hpp"
5#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
6import kokkos.core;
7# include "Kokkos_Assert.hpp"
8#else
9# include "Kokkos_Core.hpp"
10#endif
11
17
19
20template <>
21struct HasNonBlockingDispatch<Kokkos::HIP> : std::true_type { };
22
23template <>
24struct Event<Kokkos::HIP> {
25 hipEvent_t m_event = nullptr;
26 uint64_t m_event_id = invalid_event_id;
27
28 Event() = default;
29 Event(const Event&) = delete;
30 Event& operator=(const Event&) = delete;
31 Event(Event&&) noexcept = delete;
32 Event& operator=(Event&&) noexcept = delete;
33
34 ~Event() {
35 if (m_event != nullptr)
36 KOKKOS_IMPL_HIP_SAFE_CALL(hipEventDestroy(m_event));
37 }
38
39 void record(const Kokkos::HIP& exec) {
40 if (m_event == nullptr) {
41 KOKKOS_IMPL_HIP_SAFE_CALL(hipEventCreateWithFlags(&m_event, hipEventDisableTiming));
42 }
43 KOKKOS_IMPL_HIP_SAFE_CALL(hipEventRecord(m_event, exec.hip_stream()));
44 }
45
46 void wait() const {
47 if (hipEventQuery(m_event) != hipSuccess) {
48 KOKKOS_IMPL_HIP_SAFE_CALL(hipEventSynchronize(m_event));
49 }
50 }
51
52 [[nodiscard]]
53 constexpr hipEvent_t hip_event() const noexcept {
54 return m_event;
55 }
56};
57
58template <Kokkos::ExecutionSpace... ExecFrom>
59requires(std::same_as<ExecFrom, Kokkos::HIP> && ...)
60void impl_wait(const Kokkos::HIP& exec, const Event<ExecFrom>&... events) {
61 auto do_impl_wait = [&exec](const auto& event) {
62 KOKKOS_EXPECTS(bool(event.hip_event()));
63 KOKKOS_IMPL_HIP_SAFE_CALL(hipStreamWaitEvent(exec.hip_stream(), event.hip_event()));
64 };
65 (do_impl_wait(events), ...);
66}
67
68} // namespace Kokkos::Execution::Impl
69
70#endif // KOKKOS_EXECUTION_IMPL_HIP_EVENT_HPP
Constrain an EventType type to be a valid event type for Exec execution space type.
Definition event.hpp:31
void impl_wait(const Kokkos::Cuda &exec, const Event< ExecFrom > &... events)
Definition event.hpp:60
void record(const Kokkos::HIP &exec)
Definition event.hpp:39
Event & operator=(const Event &)=delete
constexpr hipEvent_t hip_event() const noexcept
Definition event.hpp:53
An event that can be recorded on an execution space instance.
Definition event.hpp:115
Determine if the Kokkos backend has non-blocking dispatch.
Definition event.hpp:50