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 void* root_node = nullptr;
19 uint32_t dev_id = 0;
20 uint64_t event_id = 0;
21
22 constexpr auto operator<=>(const GraphCreateEvent&) const = default;
23
24 friend std::ostream& operator<<(std::ostream& out, const GraphCreateEvent& event) {
25 return out << "GraphCreateEvent: {graph = " << event.graph << ", root_node = " << event.root_node
26 << ", dev_id = " << event.dev_id << ", event_id = " << event.event_id << '}';
27 }
28};
29
37 void* graph = nullptr;
38 void* predecessor = nullptr;
39 void* node = nullptr;
40 uint32_t dev_id = 0;
41
42 constexpr auto operator<=>(const GraphAddNodeEvent&) const = default;
43
44 friend std::ostream& operator<<(std::ostream& out, const GraphAddNodeEvent& event) {
45 return out << "GraphAddNodeEvent: {graph = " << event.graph << ", predecessor = " << event.predecessor
46 << ", node = " << event.node << ", dev_id = " << event.dev_id << '}';
47 }
48};
49
52 void* graph = nullptr;
53 std::vector<void*> predecessors{};
54 void* node = nullptr;
55
56 constexpr auto operator<=>(const GraphAddAggregateNodeEvent&) const = default;
57
58 friend std::ostream& operator<<(std::ostream& out, const GraphAddAggregateNodeEvent& event) {
59 using Kokkos::Execution::Utils::operator<<;
60 return out << "GraphAddAggregateNodeEvent: {graph = " << event.graph
61 << ", predecessors = " << event.predecessors << ", node = " << event.node << '}';
62 }
63};
64
67 void* graph = nullptr;
68
69 constexpr auto operator<=>(const GraphInstantiateEvent&) const = default;
70
71 friend std::ostream& operator<<(std::ostream& out, const GraphInstantiateEvent& event) {
72 return out << "GraphInstantiateEvent: {graph = " << event.graph << '}';
73 }
74};
75
78 void* graph = nullptr;
79 uint32_t dev_id = 0;
80
81 constexpr auto operator<=>(const GraphSubmitEvent&) const = default;
82
83 friend std::ostream& operator<<(std::ostream& out, const GraphSubmitEvent& event) {
84 return out << "GraphSubmitEvent: {graph = " << event.graph << ", dev_id = " << event.dev_id << '}';
85 }
86};
87
89template <typename T>
90concept NodeRef = Kokkos::Impl::is_specialization_of_v<T, Kokkos::Experimental::GraphNodeRef>;
91
93template <NodeRef NodeType>
94auto* get_graph_impl_ptr(const NodeType& node) noexcept {
95 return Kokkos::Impl::GraphAccess::get_graph_weak_ptr(node).lock().get();
96}
97
99template <NodeRef NodeType>
100auto* get_node_ptr(const NodeType& node) noexcept {
101 return Kokkos::Impl::GraphAccess::get_node_ptr(node).get();
102}
103
105template <Kokkos::ExecutionSpace Exec>
106void graph_create_event(const Kokkos::Experimental::Graph<Exec>& graph) {
107#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
108 const auto root = graph.root_node();
111 .graph = get_graph_impl_ptr(root),
112 .root_node = get_node_ptr(root),
113 .dev_id = Kokkos::Tools::Experimental::device_id(graph.get_device_handle().m_exec),
115#endif
116}
117
119template <Kokkos::ExecutionSpace Exec, typename... Args>
120auto create_graph(const Kokkos::Impl::DeviceHandle<Exec>& device_handle, Args&&... args) {
121 Kokkos::Experimental::Graph<Exec> graph{device_handle, std::forward<Args>(args)...};
122 graph_create_event(graph);
123 return graph;
124}
125
131template <NodeRef Predecessor, NodeRef NodeType, Kokkos::ExecutionSpace Exec>
133 const Predecessor& predecessor,
134 const NodeType& node,
135 const Kokkos::Impl::DeviceHandle<Exec>& device_handle) {
136#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
139 .graph = get_graph_impl_ptr(predecessor),
140 .predecessor = get_node_ptr(predecessor),
141 .node = get_node_ptr(node),
142 .dev_id = Kokkos::Tools::Experimental::device_id(device_handle.m_exec)});
143#endif
144}
145
147template <NodeRef NodeType, NodeRef... Predecessors>
148void graph_add_aggregate_node_event(const NodeType& aggregate, const Predecessors&... predecessors) {
149#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
152 .graph = get_graph_impl_ptr(aggregate),
153 .predecessors = {get_node_ptr(predecessors)...},
154 .node = get_node_ptr(aggregate)});
155#endif
156}
157
159template <Kokkos::ExecutionSpace Exec>
160void graph_instantiate_event(const Kokkos::Experimental::Graph<Exec>& graph) {
161#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
163#endif
164}
165
166
168template <Kokkos::ExecutionSpace Exec>
169void graph_submit_event(const Kokkos::Experimental::Graph<Exec>& graph, const Exec& exec) {
170#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
173 .graph = get_graph_impl_ptr(graph.root_node()), .dev_id = Kokkos::Tools::Experimental::device_id(exec)});
174#endif
175}
176
178template <Kokkos::ExecutionSpace Exec>
179void submit_graph(const Kokkos::Experimental::Graph<Exec>& graph, const Exec& exec) {
180 graph_submit_event(graph, exec);
181 graph.submit(exec);
182}
183
184} // namespace Kokkos::Execution::GraphImpl
185
186#endif // KOKKOS_EXECUTION_GRAPH_EVENTS_HPP
Constrain a type that is a specialization of Kokkos::Experimental::GraphNodeRef.
Definition events.hpp:90
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:148
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:132
void graph_create_event(const Kokkos::Experimental::Graph< Exec > &graph)
Record a GraphCreateEvent event.
Definition events.hpp:106
auto * get_node_ptr(const NodeType &node) noexcept
Retrieve the raw node pointer.
Definition events.hpp:100
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:120
void graph_instantiate_event(const Kokkos::Experimental::Graph< Exec > &graph)
Record a GraphInstantiateEvent event.
Definition events.hpp:160
void graph_submit_event(const Kokkos::Experimental::Graph< Exec > &graph, const Exec &exec)
Record a GraphSubmitEvent event.
Definition events.hpp:169
auto * get_graph_impl_ptr(const NodeType &node) noexcept
Retrieve the raw graph pointer from a node.
Definition events.hpp:94
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:179
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:51
friend std::ostream & operator<<(std::ostream &out, const GraphAddAggregateNodeEvent &event)
Definition events.hpp:58
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:36
constexpr auto operator<=>(const GraphAddNodeEvent &) const =default
friend std::ostream & operator<<(std::ostream &out, const GraphAddNodeEvent &event)
Definition events.hpp:44
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:24
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is instantiated.
Definition events.hpp:66
friend std::ostream & operator<<(std::ostream &out, const GraphInstantiateEvent &event)
Definition events.hpp:71
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:77
constexpr auto operator<=>(const GraphSubmitEvent &) const =default
friend std::ostream & operator<<(std::ostream &out, const GraphSubmitEvent &event)
Definition events.hpp:83