1#ifndef KOKKOS_EXECUTION_GRAPH_EVENTS_HPP
2#define KOKKOS_EXECUTION_GRAPH_EVENTS_HPP
4#include "Kokkos_Core.hpp"
5#include "Kokkos_Graph.hpp"
7#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
24 return out <<
"GraphCreateEvent: {graph = " <<
event.graph <<
", dev_id = " <<
event.dev_id
25 <<
", event_id = " <<
event.event_id <<
'}';
44 return out <<
"GraphAddNodeEvent: {graph = " <<
event.graph <<
", predecessor = " <<
event.predecessor
45 <<
", node = " <<
event.node <<
", dev_id = " <<
event.dev_id <<
'}';
58 using Kokkos::Execution::Utils::operator<<;
59 return out <<
"GraphAddAggregateNodeEvent: {graph = " <<
event.graph
60 <<
", predecessors = " <<
event.predecessors <<
", node = " <<
event.node <<
'}';
71 return out <<
"GraphInstantiateEvent: {graph = " <<
event.graph <<
'}';
83 return out <<
"GraphSubmitEvent: {graph = " <<
event.graph <<
", dev_id = " <<
event.dev_id <<
'}';
89concept NodeRef = Kokkos::Impl::is_specialization_of_v<T, Kokkos::Experimental::GraphNodeRef>;
92template <NodeRef NodeType>
94 return Kokkos::Impl::GraphAccess::get_graph_weak_ptr(node).lock().get();
98template <NodeRef NodeType>
100 return Kokkos::Impl::GraphAccess::get_node_ptr(node).get();
104template <Kokkos::ExecutionSpace Exec>
106#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
110 .dev_id = Kokkos::Tools::Experimental::device_id(graph.get_device_handle().m_exec),
116template <Kokkos::ExecutionSpace Exec,
typename... Args>
117auto create_graph(
const Kokkos::Impl::DeviceHandle<Exec>& device_handle, Args&&... args) {
118 Kokkos::Experimental::Graph<Exec> graph{device_handle, std::forward<Args>(args)...};
128template <NodeRef Predecessor, NodeRef NodeType, Kokkos::ExecutionSpace Exec>
130 const Predecessor& predecessor,
131 const NodeType& node,
132 const Kokkos::Impl::DeviceHandle<Exec>& device_handle) {
133#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
134 const bool is_predecessor_root = predecessor.get_node_kind() == Kokkos::Experimental::GraphNodeKind::Root;
139 .predecessor = is_predecessor_root ? nullptr :
get_node_ptr(predecessor),
141 .dev_id = Kokkos::Tools::Experimental::device_id(device_handle.m_exec)});
146template <NodeRef NodeType, NodeRef... Predecessors>
148#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
158template <Kokkos::ExecutionSpace Exec>
160#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
167template <Kokkos::ExecutionSpace Exec>
169#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
172 .graph =
get_graph_impl_ptr(graph.root_node()), .dev_id = Kokkos::Tools::Experimental::device_id(exec)});
177template <Kokkos::ExecutionSpace Exec>
178void 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(const Predecessor &predecessor, const NodeType &node, const Kokkos::Impl::DeviceHandle< Exec > &device_handle)
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.
auto get_next_event_id() noexcept
void dispatch(const EventType &event)
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph aggregate node is added.
friend std::ostream & operator<<(std::ostream &out, const GraphAddAggregateNodeEvent &event)
constexpr auto operator<=>(const GraphAddAggregateNodeEvent &) const =default
std::vector< void * > predecessors
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)