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)
22 return out <<
"GraphCreateEvent: {graph = " <<
event.graph <<
", dev_id = " <<
event.dev_id
23 <<
", event_id = " <<
event.event_id <<
'}';
42 return out <<
"GraphAddNodeEvent: {graph = " <<
event.graph <<
", predecessor = " <<
event.predecessor
43 <<
", node = " <<
event.node <<
", dev_id = " <<
event.dev_id <<
'}';
54 return out <<
"GraphInstantiateEvent: {graph = " <<
event.graph <<
'}';
66 return out <<
"GraphSubmitEvent: {graph = " <<
event.graph <<
", dev_id = " <<
event.dev_id <<
'}';
72concept NodeRef = Kokkos::Impl::is_specialization_of_v<T, Kokkos::Experimental::GraphNodeRef>;
75template <NodeRef NodeType>
77 return Kokkos::Impl::GraphAccess::get_graph_weak_ptr(node).lock().get();
81template <NodeRef NodeType>
83 return Kokkos::Impl::GraphAccess::get_node_ptr(node).get();
87template <Kokkos::ExecutionSpace Exec>
89#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
93 .dev_id = Kokkos::Tools::Experimental::device_id(graph.get_device_handle().m_exec),
99template <Kokkos::ExecutionSpace Exec,
typename... Args>
100auto create_graph(
const Kokkos::Impl::DeviceHandle<Exec>& device_handle, Args&&... args) {
101 Kokkos::Experimental::Graph<Exec> graph{device_handle, std::forward<Args>(args)...};
111template <NodeRef Predecessor, NodeRef NodeType>
113#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
119 constexpr bool is_root = []() {
120 using aggregate_t =
decltype(graph_ptr->create_aggregate_ptr());
122 if constexpr (
requires {
typename std::remove_cvref_t<
decltype(*pred_ptr)>::kernel_type; }) {
123 using kernel_t =
typename std::remove_cvref_t<
decltype(*pred_ptr)>::kernel_type;
124 if constexpr (Kokkos::Impl::is_graph_kernel_v<kernel_t>) {
126 }
else if constexpr (Kokkos::Impl::is_graph_capture_v<kernel_t>) {
128 }
else if constexpr (Kokkos::Impl::is_graph_then_host_v<kernel_t>) {
131 }
else if constexpr (std::same_as<Predecessor, aggregate_t>) {
141 .predecessor = is_root ? nullptr : pred_ptr,
143 .dev_id = Kokkos::Tools::Experimental::device_id(node_ptr->get_device_handle().m_exec)});
148template <Kokkos::ExecutionSpace Exec>
150#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
157template <Kokkos::ExecutionSpace Exec>
159#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
162 .graph =
get_graph_impl_ptr(graph.root_node()), .dev_id = Kokkos::Tools::Experimental::device_id(exec)});
167template <Kokkos::ExecutionSpace Exec>
168void submit_graph(
const Kokkos::Experimental::Graph<Exec>& graph,
const Exec& exec) {
Constrain a type that is a specialization of Kokkos::Experimental::GraphNodeRef.
void graph_create_event(const Kokkos::Experimental::Graph< Exec > &graph)
Record a GraphCreateEvent event.
void graph_add_node_event(const Predecessor &predecessor, const NodeType &node)
Record an event for a node added after predecessor.
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 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)