1#ifndef KOKKOS_EXECUTION_IMPL_EVENT_HPP
2#define KOKKOS_EXECUTION_IMPL_EVENT_HPP
7#include "Kokkos_Core.hpp"
9#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
23template <
typename EventType,
typename Exec>
24concept event = Kokkos::ExecutionSpace<Exec> && std::default_initializable<EventType> && !std::copyable<EventType>
25 && !std::movable<EventType> &&
requires(EventType& obj,
const Exec& exec) {
26 { obj.record(exec) } -> std::same_as<void>;
27 } &&
requires(
const EventType& obj) {
28 { obj.wait() } -> std::same_as<void>;
29 { obj.m_event_id } -> std::same_as<const uint64_t&>;
33template <Kokkos::ExecutionSpace Exec>
42template <Kokkos::ExecutionSpace Exec>
45template <
typename Exec>
48static constexpr auto invalid_dev_id = Kokkos::Experimental::finite_max_v<uint32_t>;
59 return out <<
"RecordEvent: {dev_id = " <<
event.dev_id <<
", event_id = " <<
event.event_id <<
'}';
63template <Kokkos::ExecutionSpace Exec>
65#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
68 RecordEvent{.dev_id = Kokkos::Tools::Experimental::device_id(exec), .event_id = event_id});
80 return out <<
"WaitEvent: {dev_id = " <<
event.dev_id <<
", event_id = " <<
event.event_id <<
'}';
84template <Kokkos::ExecutionSpace Exec>
86#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
91template <Kokkos::ExecutionSpace ExecTo, Kokkos::ExecutionSpace ExecFrom>
93#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
95 WaitEvent{.dev_id = Kokkos::Tools::Experimental::device_id(exec), .event_id =
event.m_event_id});
107template <Kokkos::ExecutionSpace Exec>
123 m_recorded.store(
true, std::memory_order_release);
131 while (!
m_recorded.load(std::memory_order_acquire)) {
137template <Kokkos::ExecutionSpace Exec>
144template <Kokkos::ExecutionSpace Exec>
150template <Kokkos::ExecutionSpace ExecFrom, Kokkos::ExecutionSpace ExecTo>
160template <Kokkos::ExecutionSpace ExecFrom, Kokkos::ExecutionSpace ExecTo>
166template <Kokkos::ExecutionSpace Exec>
171#if defined(KOKKOS_ENABLE_CUDA)
174#if defined(KOKKOS_ENABLE_HIP)
177#if defined(KOKKOS_ENABLE_HPX)
180#if defined(KOKKOS_ENABLE_SYCL)
Constrain an EventType type to be a valid event type for Exec execution space type.
static constexpr auto invalid_event_id
std::optional< Event< Exec > > event_storage_t
static constexpr auto invalid_dev_id
void record_event(const Exec &exec, uint64_t &event_id)
void record(Event< Exec > &event, const Exec &exec)
Record event on exec.
void impl_wait(const Kokkos::Cuda &exec, const Event< Kokkos::Cuda > &event)
void wait_event(const Event< Exec > &event)
void wait(const Event< Exec > &event)
Wait for event to complete.
auto get_next_event_id() noexcept
void dispatch(const EventType &event)
An event that can be recorded on an execution space instance.
std::atomic< bool > m_recorded
Event & operator=(const Event &)=delete
Event(Event &&) noexcept=delete
void record(const Exec &)
Event(const Event &)=delete
Determine if the Kokkos backend has non-blocking dispatch.
Event to be sent to Kokkos::utils::callbacks::dispatch when calling record.
friend std::ostream & operator<<(std::ostream &out, const RecordEvent &event)
constexpr auto operator<=>(const RecordEvent &) const =default
Event to be sent to Kokkos::utils::callbacks::dispatch when calling wait.
friend std::ostream & operator<<(std::ostream &out, const WaitEvent &event)
constexpr auto operator<=>(const WaitEvent &) const =default