kokkos-execution 0.0.1
Loading...
Searching...
No Matches
event.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_IMPL_CUDA_EVENT_HPP
2#define KOKKOS_EXECUTION_IMPL_CUDA_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::Cuda> : std::true_type { };
22
23template <>
24struct Event<Kokkos::Cuda> {
25 cudaEvent_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_CUDA_SAFE_CALL(cudaEventDestroy(m_event));
37 }
38
39 void record(const Kokkos::Cuda& exec) {
40 if (m_event == nullptr) {
41 KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventCreateWithFlags(&m_event, cudaEventDisableTiming));
42 }
43 KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventRecord(m_event, exec.cuda_stream()));
44 }
45
46 void wait() const {
47 if (cudaEventQuery(m_event) != cudaSuccess) {
48 KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventSynchronize(m_event));
49 }
50 }
51
52 [[nodiscard]]
53 constexpr cudaEvent_t cuda_event() const noexcept {
54 return m_event;
55 }
56};
57
58template <Kokkos::ExecutionSpace... ExecFrom>
59requires(std::same_as<ExecFrom, Kokkos::Cuda> && ...)
60void impl_wait(const Kokkos::Cuda& exec, const Event<ExecFrom>&... events) {
61 const auto do_impl_wait = [&exec](const auto& event) {
62 KOKKOS_EXPECTS(bool(event.cuda_event()));
63 KOKKOS_IMPL_CUDA_SAFE_CALL(cudaStreamWaitEvent(exec.cuda_stream(), event.cuda_event()));
64 };
65 (do_impl_wait(events), ...);
66}
67
68} // namespace Kokkos::Execution::Impl
69
70#endif // KOKKOS_EXECUTION_IMPL_CUDA_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
constexpr cudaEvent_t cuda_event() const noexcept
Definition event.hpp:53
Event & operator=(const Event &)=delete
void record(const Kokkos::Cuda &exec)
Definition event.hpp:39
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