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_Core.hpp"
5
11
13
14template <>
15struct SupportEvents<Kokkos::Cuda> : std::true_type { };
16
17template <>
18struct Event<Kokkos::Cuda> {
19 cudaEvent_t m_event = nullptr;
21
22 Event() = default;
23
24 explicit Event(const Kokkos::Cuda& exec) {
25 record(exec);
26 }
27
28 Event(const Event&) = delete;
29 Event& operator=(const Event&) = delete;
30 Event(Event&& other) noexcept
31 : m_event(std::exchange(other.m_event, nullptr))
32 , m_event_id(std::exchange(other.m_event_id, invalid_event_id)) {
33 }
34 Event& operator=(Event&& other) noexcept {
35 if (this != &other) {
36 if (m_event != nullptr) {
37 KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventDestroy(m_event));
38 }
39 m_event = std::exchange(other.m_event, nullptr);
40 m_event_id = std::exchange(other.m_event_id, invalid_event_id);
41 }
42 return *this;
43 }
44
46 if (m_event != nullptr)
47 KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventDestroy(m_event));
48 }
49
50 void record(const Kokkos::Cuda& exec) {
51 if (m_event == nullptr) {
52 KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventCreateWithFlags(&m_event, cudaEventDisableTiming));
53 }
54 KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventRecord(m_event, exec.cuda_stream()));
56 }
57
58 void wait() const {
60 if (cudaEventQuery(m_event) != cudaSuccess) {
61 KOKKOS_IMPL_CUDA_SAFE_CALL(cudaEventSynchronize(m_event));
62 }
63 }
64};
65
66Event(const Kokkos::Cuda&) -> Event<Kokkos::Cuda>;
67
68} // namespace Kokkos::Execution::Impl
69
70#endif // KOKKOS_EXECUTION_IMPL_CUDA_EVENT_HPP
static constexpr auto invalid_event_id
Definition event.hpp:43
void record_event(const Exec &exec, uint64_t &event_id)
Definition event.hpp:54
Event(const Kokkos::Cuda &) -> Event< Kokkos::Cuda >
void wait_event(const uint64_t event_id)
Definition event.hpp:69
Event & operator=(const Event &)=delete
Event & operator=(Event &&other) noexcept
Definition event.hpp:34
void record(const Kokkos::Cuda &exec)
Definition event.hpp:50
An event that can be recorded on an execution space instance.
Definition event.hpp:34
Determine if events are supported.
Definition event.hpp:38