1#ifndef KOKKOS_EXECUTION_GRAPH_EVENTS_HPP
2#define KOKKOS_EXECUTION_GRAPH_EVENTS_HPP
4#include "Kokkos_Macros.hpp"
5#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
8import kokkos.graph_impl;
10# include "Kokkos_Core.hpp"
11# include "Kokkos_Graph.hpp"
14#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
23#if defined(__cpp_impl_reflection)
24using Utils::operator<<;
36#if !defined(__cpp_impl_reflection)
38 return out <<
"GraphCreateEvent: {graph = " <<
event.graph <<
", root_node = " <<
event.root_node
39 <<
", dev_id = " <<
event.dev_id <<
", event_id = " <<
event.event_id <<
'}';
53 const void*
node =
nullptr;
58#if !defined(__cpp_impl_reflection)
60 return out <<
"GraphAddNodeEvent: {name = " <<
event.name <<
", graph = " <<
event.graph
61 <<
", predecessor = " <<
event.predecessor <<
", node = " <<
event.node
62 <<
", dev_id = " <<
event.dev_id <<
'}';
71 const void*
node =
nullptr;
75#if !defined(__cpp_impl_reflection)
77 using Kokkos::Execution::Utils::operator<<;
78 return out <<
"GraphAddAggregateNodeEvent: {graph = " <<
event.graph
79 <<
", predecessors = " <<
event.predecessors <<
", node = " <<
event.node <<
'}';
90#if !defined(__cpp_impl_reflection)
92 return out <<
"GraphInstantiateEvent: {graph = " <<
event.graph <<
'}';
104#if !defined(__cpp_impl_reflection)
106 return out <<
"GraphSubmitEvent: {graph = " <<
event.graph <<
", dev_id = " <<
event.dev_id <<
'}';
113concept NodeRef = Kokkos::Impl::is_specialization_of_v<T, Kokkos::Experimental::GraphNodeRef>;
116template <NodeRef NodeType>
118 return Kokkos::Impl::GraphAccess::get_graph_weak_ptr(node).lock().get();
122template <NodeRef NodeType>
124 return Kokkos::Impl::GraphAccess::get_node_ptr(node).get();
128template <Kokkos::ExecutionSpace Exec>
130#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
131 const auto root = graph.root_node();
136 .dev_id = Kokkos::Tools::Experimental::device_id(graph.get_device_handle().m_exec),
142template <Kokkos::ExecutionSpace Exec,
typename... Args>
143auto create_graph(
const Kokkos::Impl::DeviceHandle<Exec>& device_handle, Args&&... args) {
144 Kokkos::Experimental::Graph<Exec> graph{device_handle, std::forward<Args>(args)...};
150template <
typename Label, NodeRef Predecessor, NodeRef NodeType>
152#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
160 .dev_id = Kokkos::Tools::Experimental::device_id(node_ptr->get_device_handle().m_exec)});
165template <NodeRef NodeType, NodeRef... Predecessors>
167#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
177template <Kokkos::ExecutionSpace Exec>
179#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
185template <Kokkos::ExecutionSpace Exec>
187#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
190 .graph =
get_graph_impl_ptr(graph.root_node()), .dev_id = Kokkos::Tools::Experimental::device_id(exec)});
195template <Kokkos::ExecutionSpace Exec>
196void submit_graph(
const Kokkos::Experimental::Graph<Exec>& graph,
const Exec& exec) {
Constrain a type that is a specialization of Kokkos::Experimental::GraphNodeRef.
void graph_add_aggregate_node_event(const NodeType &aggregate, const Predecessors &... predecessors)
Record an event for an aggregate node added after predecessors.
void graph_add_node_event(Label &&label, const Predecessor &predecessor, const NodeType &node)
Record an event for a node added after predecessor.
void graph_create_event(const Kokkos::Experimental::Graph< Exec > &graph)
Record a GraphCreateEvent event.
auto * get_node_ptr(const NodeType &node) noexcept
Retrieve the raw node pointer.
auto create_graph(const Kokkos::Impl::DeviceHandle< Exec > &device_handle, Args &&... args)
Create a graph and record the associated event with graph_create_event.
void graph_instantiate_event(const Kokkos::Experimental::Graph< Exec > &graph)
Record a GraphInstantiateEvent event.
void graph_submit_event(const Kokkos::Experimental::Graph< Exec > &graph, const Exec &exec)
Record a GraphSubmitEvent event.
auto * get_graph_impl_ptr(const NodeType &node) noexcept
Retrieve the raw graph pointer from a node.
void submit_graph(const Kokkos::Experimental::Graph< Exec > &graph, const Exec &exec)
Submit a graph and record the associated event with graph_submit_event.
constexpr auto as_convertible_to_string(T &&value) noexcept(noexcept(std::forward< T >(value))) -> decltype(std::forward< T >(value))
Convert to a value usable as a std::string.
consteval Impl::Label< std::string_view > label(std::string_view str) noexcept
auto get_next_event_id() noexcept
void dispatch(const EventType &event)
#define KOKKOS_EXECUTION_UTILS_STREAMABLE
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph aggregate node is added.
std::vector< const void * > predecessors
friend std::ostream & operator<<(std::ostream &out, const GraphAddAggregateNodeEvent &event)
constexpr auto operator<=>(const GraphAddAggregateNodeEvent &) const =default
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph node is added.
constexpr auto operator<=>(const GraphAddNodeEvent &) const =default
friend std::ostream & operator<<(std::ostream &out, const GraphAddNodeEvent &event)
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is created.
constexpr auto operator<=>(const GraphCreateEvent &) const =default
friend std::ostream & operator<<(std::ostream &out, const GraphCreateEvent &event)
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is instantiated.
friend std::ostream & operator<<(std::ostream &out, const GraphInstantiateEvent &event)
constexpr auto operator<=>(const GraphInstantiateEvent &) const =default
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is submitted.
constexpr auto operator<=>(const GraphSubmitEvent &) const =default
friend std::ostream & operator<<(std::ostream &out, const GraphSubmitEvent &event)