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)
25template <
typename EventType,
typename Exec>
26concept event = Kokkos::ExecutionSpace<Exec> && std::default_initializable<EventType> && !std::copyable<EventType>
27 && !std::movable<EventType> &&
requires(EventType& obj,
const Exec& exec) {
28 { obj.record(exec) } -> std::same_as<void>;
29 } &&
requires(
const EventType& obj) {
30 { obj.wait() } -> std::same_as<void>;
31 { obj.m_event_id } -> std::same_as<const uint64_t&>;
35template <Kokkos::ExecutionSpace Exec>
44template <Kokkos::ExecutionSpace Exec>
47template <
typename Exec>
50static constexpr auto invalid_dev_id = Kokkos::Experimental::finite_max_v<uint32_t>;
61 return out <<
"RecordEvent: {dev_id = " <<
event.dev_id <<
", event_id = " <<
event.event_id <<
'}';
65template <Kokkos::ExecutionSpace Exec>
67#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
70 RecordEvent{.dev_id = Kokkos::Tools::Experimental::device_id(exec), .event_id = event_id});
82 return out <<
"WaitEvent: {dev_id = " <<
event.dev_id <<
", event_id = " <<
event.event_id <<
'}';
86template <Kokkos::ExecutionSpace Exec>
88#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
93template <Kokkos::ExecutionSpace ExecTo, Kokkos::ExecutionSpace ExecFrom>
95#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
97 WaitEvent{.dev_id = Kokkos::Tools::Experimental::device_id(exec), .event_id =
event.m_event_id});
109template <Kokkos::ExecutionSpace Exec>
125 m_recorded.store(
true, std::memory_order_release);
133 while (!
m_recorded.load(std::memory_order_acquire)) {
139template <Kokkos::ExecutionSpace Exec>
145template <Kokkos::ExecutionSpace... Exec>
147 (events.
wait(), ...);
151template <Kokkos::ExecutionSpace... Exec>
157template <Kokkos::ExecutionSpace ExecTo, Kokkos::ExecutionSpace... ExecFrom>
159 (events.
wait(), ...);
167template <Kokkos::ExecutionSpace ExecTo, Kokkos::ExecutionSpace... ExecFrom>
173template <Kokkos::ExecutionSpace Exec>
177template <Kokkos::ExecutionSpace Exec>
182#if defined(KOKKOS_ENABLE_CUDA)
185#if defined(KOKKOS_ENABLE_HIP)
188#if defined(KOKKOS_ENABLE_HPX)
191#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