kokkos-execution 0.0.1
Loading...
Searching...
No Matches
events.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_GRAPH_EVENTS_HPP
2#define KOKKOS_EXECUTION_GRAPH_EVENTS_HPP
3
4#include "Kokkos_Core.hpp"
5#include "Kokkos_Graph.hpp"
6
7#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
9#endif
10
12
14
17 void* graph = nullptr;
18 uint32_t dev_id = 0;
19 uint64_t event_id = 0;
20
21 constexpr auto operator<=>(const GraphCreateEvent&) const = default;
22
23 friend std::ostream& operator<<(std::ostream& out, const GraphCreateEvent& event) {
24 return out << "GraphCreateEvent: {graph = " << event.graph << ", dev_id = " << event.dev_id
25 << ", event_id = " << event.event_id << '}';
26 }
27};
28
36 void* graph = nullptr;
37 void* predecessor = nullptr;
38 void* node = nullptr;
39 uint32_t dev_id = 0;
40
41 constexpr auto operator<=>(const GraphAddNodeEvent&) const = default;
42
43 friend std::ostream& operator<<(std::ostream& out, const GraphAddNodeEvent& event) {
44 return out << "GraphAddNodeEvent: {graph = " << event.graph << ", predecessor = " << event.predecessor
45 << ", node = " << event.node << ", dev_id = " << event.dev_id << '}';
46 }
47};
48
51 void* graph = nullptr;
52 std::vector<void*> predecessors{};
53 void* node = nullptr;
54
55 constexpr auto operator<=>(const GraphAddAggregateNodeEvent&) const = default;
56
57 friend std::ostream& operator<<(std::ostream& out, const GraphAddAggregateNodeEvent& event) {
58 using Kokkos::Execution::Utils::operator<<;
59 return out << "GraphAddAggregateNodeEvent: {graph = " << event.graph
60 << ", predecessors = " << event.predecessors << ", node = " << event.node << '}';
61 }
62};
63
66 void* graph = nullptr;
67
68 constexpr auto operator<=>(const GraphInstantiateEvent&) const = default;
69
70 friend std::ostream& operator<<(std::ostream& out, const GraphInstantiateEvent& event) {
71 return out << "GraphInstantiateEvent: {graph = " << event.graph << '}';
72 }
73};
74
77 void* graph = nullptr;
78 uint32_t dev_id = 0;
79
80 constexpr auto operator<=>(const GraphSubmitEvent&) const = default;
81
82 friend std::ostream& operator<<(std::ostream& out, const GraphSubmitEvent& event) {
83 return out << "GraphSubmitEvent: {graph = " << event.graph << ", dev_id = " << event.dev_id << '}';
84 }
85};
86
88template <typename T>
89concept NodeRef = Kokkos::Impl::is_specialization_of_v<T, Kokkos::Experimental::GraphNodeRef>;
90
92template <NodeRef NodeType>
93auto* get_graph_impl_ptr(const NodeType& node) noexcept {
94 return Kokkos::Impl::GraphAccess::get_graph_weak_ptr(node).lock().get();
95}
96
98template <NodeRef NodeType>
99auto* get_node_ptr(const NodeType& node) noexcept {
100 return Kokkos::Impl::GraphAccess::get_node_ptr(node).get();
101}
102
104template <Kokkos::ExecutionSpace Exec>
105void graph_create_event(const Kokkos::Experimental::Graph<Exec>& graph) {
106#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
109 .graph = get_graph_impl_ptr(graph.root_node()),
110 .dev_id = Kokkos::Tools::Experimental::device_id(graph.get_device_handle().m_exec),
112#endif
113}
114
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)...};
119 graph_create_event(graph);
120 return graph;
121}
122
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;
135
138 .graph = get_graph_impl_ptr(predecessor),
139 .predecessor = is_predecessor_root ? nullptr : get_node_ptr(predecessor),
140 .node = get_node_ptr(node),
141 .dev_id = Kokkos::Tools::Experimental::device_id(device_handle.m_exec)});
142#endif
143}
144
146template <NodeRef NodeType, NodeRef... Predecessors>
147void graph_add_aggregate_node_event(const NodeType& aggregate, const Predecessors&... predecessors) {
148#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
151 .graph = get_graph_impl_ptr(aggregate),
152 .predecessors = {get_node_ptr(predecessors)...},
153 .node = get_node_ptr(aggregate)});
154#endif
155}
156
158template <Kokkos::ExecutionSpace Exec>
159void graph_instantiate_event(const Kokkos::Experimental::Graph<Exec>& graph) {
160#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
162#endif
163}
164
165
167template <Kokkos::ExecutionSpace Exec>
168void graph_submit_event(const Kokkos::Experimental::Graph<Exec>& graph, const Exec& 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)});
173#endif
174}
175
177template <Kokkos::ExecutionSpace Exec>
178void submit_graph(const Kokkos::Experimental::Graph<Exec>& graph, const Exec& exec) {
179 graph_submit_event(graph, exec);
180 graph.submit(exec);
181}
182
183} // namespace Kokkos::Execution::GraphImpl
184
185#endif // KOKKOS_EXECUTION_GRAPH_EVENTS_HPP
Constrain a type that is a specialization of Kokkos::Experimental::GraphNodeRef.
Definition events.hpp:89
void graph_add_aggregate_node_event(const NodeType &aggregate, const Predecessors &... predecessors)
Record an event for an aggregate node added after predecessors.
Definition events.hpp:147
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.
Definition events.hpp:129
void graph_create_event(const Kokkos::Experimental::Graph< Exec > &graph)
Record a GraphCreateEvent event.
Definition events.hpp:105
auto * get_node_ptr(const NodeType &node) noexcept
Retrieve the raw node pointer.
Definition events.hpp:99
auto create_graph(const Kokkos::Impl::DeviceHandle< Exec > &device_handle, Args &&... args)
Create a graph and record the associated event with graph_create_event.
Definition events.hpp:117
void graph_instantiate_event(const Kokkos::Experimental::Graph< Exec > &graph)
Record a GraphInstantiateEvent event.
Definition events.hpp:159
void graph_submit_event(const Kokkos::Experimental::Graph< Exec > &graph, const Exec &exec)
Record a GraphSubmitEvent event.
Definition events.hpp:168
auto * get_graph_impl_ptr(const NodeType &node) noexcept
Retrieve the raw graph pointer from a node.
Definition events.hpp:93
void submit_graph(const Kokkos::Experimental::Graph< Exec > &graph, const Exec &exec)
Submit a graph and record the associated event with graph_submit_event.
Definition events.hpp:178
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.
Definition events.hpp:50
friend std::ostream & operator<<(std::ostream &out, const GraphAddAggregateNodeEvent &event)
Definition events.hpp:57
constexpr auto operator<=>(const GraphAddAggregateNodeEvent &) const =default
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph node is added.
Definition events.hpp:35
constexpr auto operator<=>(const GraphAddNodeEvent &) const =default
friend std::ostream & operator<<(std::ostream &out, const GraphAddNodeEvent &event)
Definition events.hpp:43
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is created.
Definition events.hpp:16
constexpr auto operator<=>(const GraphCreateEvent &) const =default
friend std::ostream & operator<<(std::ostream &out, const GraphCreateEvent &event)
Definition events.hpp:23
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is instantiated.
Definition events.hpp:65
friend std::ostream & operator<<(std::ostream &out, const GraphInstantiateEvent &event)
Definition events.hpp:70
constexpr auto operator<=>(const GraphInstantiateEvent &) const =default
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is submitted.
Definition events.hpp:76
constexpr auto operator<=>(const GraphSubmitEvent &) const =default
friend std::ostream & operator<<(std::ostream &out, const GraphSubmitEvent &event)
Definition events.hpp:82