1#ifndef KOKKOS_EXECUTION_IMPL_EVENT_HPP
2#define KOKKOS_EXECUTION_IMPL_EVENT_HPP
7#include "Kokkos_Macros.hpp"
8#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
11# include "Kokkos_Core.hpp"
14#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
30template <
typename EventType,
typename Exec>
31concept event = Kokkos::ExecutionSpace<Exec> && std::default_initializable<EventType> && !std::copyable<EventType>
32 && !std::movable<EventType> &&
requires(EventType& obj,
const Exec& exec) {
33 { obj.record(exec) } -> std::same_as<void>;
34 } &&
requires(
const EventType& obj) {
35 { obj.wait() } -> std::same_as<void>;
36 { obj.m_event_id } -> std::same_as<const uint64_t&>;
40template <Kokkos::ExecutionSpace Exec>
49template <Kokkos::ExecutionSpace Exec>
52template <
typename Exec>
55static constexpr auto invalid_dev_id = Kokkos::Experimental::finite_max_v<uint32_t>;
66 return out <<
"RecordEvent: {dev_id = " <<
event.dev_id <<
", event_id = " <<
event.event_id <<
'}';
70template <Kokkos::ExecutionSpace Exec>
72#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
75 RecordEvent{.dev_id = Kokkos::Tools::Experimental::device_id(exec), .event_id = event_id});
87 return out <<
"WaitEvent: {dev_id = " <<
event.dev_id <<
", event_id = " <<
event.event_id <<
'}';
91template <Kokkos::ExecutionSpace Exec>
93#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
98template <Kokkos::ExecutionSpace ExecTo, Kokkos::ExecutionSpace ExecFrom>
100#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
102 WaitEvent{.dev_id = Kokkos::Tools::Experimental::device_id(exec), .event_id =
event.m_event_id});
114template <Kokkos::ExecutionSpace Exec>
130 m_recorded.store(
true, std::memory_order_release);
138 while (!
m_recorded.load(std::memory_order_acquire)) {
144template <Kokkos::ExecutionSpace Exec>
150template <Kokkos::ExecutionSpace... Exec>
152 (events.
wait(), ...);
156template <Kokkos::ExecutionSpace... Exec>
162template <Kokkos::ExecutionSpace ExecTo, Kokkos::ExecutionSpace... ExecFrom>
164 (events.
wait(), ...);
172template <Kokkos::ExecutionSpace ExecTo, Kokkos::ExecutionSpace... ExecFrom>
178template <Kokkos::ExecutionSpace Exec>
182template <Kokkos::ExecutionSpace Exec>
187#if defined(KOKKOS_ENABLE_CUDA)
190#if defined(KOKKOS_ENABLE_HIP)
193#if defined(KOKKOS_ENABLE_HPX)
196#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
OptionalRef< const Event< Exec > > OptionalConstEventRef
Optionally stores a reference to a const Impl::Event.
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 wait(const Event< Exec > &... events)
Wait for events to complete.
void wait_event(const Event< Exec > &event)
void impl_wait(const Kokkos::Cuda &exec, const Event< ExecFrom > &... events)
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.
A non-owning, nullable reference to a T.
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