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_Macros.hpp"
5#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
6import kokkos.core;
7import kokkos.graph;
8import kokkos.graph_impl;
9#else
10# include "Kokkos_Core.hpp"
11# include "Kokkos_Graph.hpp"
12#endif
13
14#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
16#endif
17
20
22
23#if defined(__cpp_impl_reflection)
24using Utils::operator<<;
25#endif
26
29 const void* graph = nullptr;
30 const void* root_node = nullptr;
31 uint32_t dev_id = 0;
32 uint64_t event_id = 0;
33
34 constexpr auto operator<=>(const GraphCreateEvent&) const = default;
35
36#if !defined(__cpp_impl_reflection)
37 friend std::ostream& operator<<(std::ostream& out, const GraphCreateEvent& event) {
38 return out << "GraphCreateEvent: {graph = " << event.graph << ", root_node = " << event.root_node
39 << ", dev_id = " << event.dev_id << ", event_id = " << event.event_id << '}';
40 }
41#endif
42};
43
50 std::string name{};
51 const void* graph = nullptr;
52 const void* predecessor = nullptr;
53 const void* node = nullptr;
54 uint32_t dev_id = 0;
55
56 constexpr auto operator<=>(const GraphAddNodeEvent&) const = default;
57
58#if !defined(__cpp_impl_reflection)
59 friend std::ostream& operator<<(std::ostream& out, const GraphAddNodeEvent& event) {
60 return out << "GraphAddNodeEvent: {name = " << event.name << ", graph = " << event.graph
61 << ", predecessor = " << event.predecessor << ", node = " << event.node
62 << ", dev_id = " << event.dev_id << '}';
63 }
64#endif
65};
66
69 const void* graph = nullptr;
70 std::vector<const void*> predecessors{};
71 const void* node = nullptr;
72
73 constexpr auto operator<=>(const GraphAddAggregateNodeEvent&) const = default;
74
75#if !defined(__cpp_impl_reflection)
76 friend std::ostream& operator<<(std::ostream& out, const GraphAddAggregateNodeEvent& event) {
77 using Kokkos::Execution::Utils::operator<<;
78 return out << "GraphAddAggregateNodeEvent: {graph = " << event.graph
79 << ", predecessors = " << event.predecessors << ", node = " << event.node << '}';
80 }
81#endif
82};
83
86 const void* graph = nullptr;
87
88 constexpr auto operator<=>(const GraphInstantiateEvent&) const = default;
89
90#if !defined(__cpp_impl_reflection)
91 friend std::ostream& operator<<(std::ostream& out, const GraphInstantiateEvent& event) {
92 return out << "GraphInstantiateEvent: {graph = " << event.graph << '}';
93 }
94#endif
95};
96
99 const void* graph = nullptr;
100 uint32_t dev_id = 0;
101
102 constexpr auto operator<=>(const GraphSubmitEvent&) const = default;
103
104#if !defined(__cpp_impl_reflection)
105 friend std::ostream& operator<<(std::ostream& out, const GraphSubmitEvent& event) {
106 return out << "GraphSubmitEvent: {graph = " << event.graph << ", dev_id = " << event.dev_id << '}';
107 }
108#endif
109};
110
112template <typename T>
113concept NodeRef = Kokkos::Impl::is_specialization_of_v<T, Kokkos::Experimental::GraphNodeRef>;
114
116template <NodeRef NodeType>
117auto* get_graph_impl_ptr(const NodeType& node) noexcept {
118 return Kokkos::Impl::GraphAccess::get_graph_weak_ptr(node).lock().get();
119}
120
122template <NodeRef NodeType>
123auto* get_node_ptr(const NodeType& node) noexcept {
124 return Kokkos::Impl::GraphAccess::get_node_ptr(node).get();
125}
126
128template <Kokkos::ExecutionSpace Exec>
129void graph_create_event(const Kokkos::Experimental::Graph<Exec>& graph) {
130#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
131 const auto root = graph.root_node();
134 .graph = get_graph_impl_ptr(root),
135 .root_node = get_node_ptr(root),
136 .dev_id = Kokkos::Tools::Experimental::device_id(graph.get_device_handle().m_exec),
138#endif
139}
140
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)...};
145 graph_create_event(graph);
146 return graph;
147}
148
150template <typename Label, NodeRef Predecessor, NodeRef NodeType>
151void graph_add_node_event(Label&& label, const Predecessor& predecessor, const NodeType& node) {
152#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
153 const auto* node_ptr = get_node_ptr(node);
156 .name = Impl::as_convertible_to_string(std::forward<Label>(label)),
157 .graph = get_graph_impl_ptr(predecessor),
158 .predecessor = get_node_ptr(predecessor),
159 .node = node_ptr,
160 .dev_id = Kokkos::Tools::Experimental::device_id(node_ptr->get_device_handle().m_exec)});
161#endif
162}
163
165template <NodeRef NodeType, NodeRef... Predecessors>
166void graph_add_aggregate_node_event(const NodeType& aggregate, const Predecessors&... predecessors) {
167#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
170 .graph = get_graph_impl_ptr(aggregate),
171 .predecessors = {get_node_ptr(predecessors)...},
172 .node = get_node_ptr(aggregate)});
173#endif
174}
175
177template <Kokkos::ExecutionSpace Exec>
178void graph_instantiate_event(const Kokkos::Experimental::Graph<Exec>& graph) {
179#if defined(KOKKOS_EXECUTION_ENABLE_EVENT_DISPATCH)
181#endif
182}
183
185template <Kokkos::ExecutionSpace Exec>
186void graph_submit_event(const Kokkos::Experimental::Graph<Exec>& graph, const Exec& 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)});
191#endif
192}
193
195template <Kokkos::ExecutionSpace Exec>
196void submit_graph(const Kokkos::Experimental::Graph<Exec>& graph, const Exec& exec) {
197 graph_submit_event(graph, exec);
198 graph.submit(exec);
199}
200
201} // namespace Kokkos::Execution::GraphImpl
202
203#endif // KOKKOS_EXECUTION_GRAPH_EVENTS_HPP
Constrain a type that is a specialization of Kokkos::Experimental::GraphNodeRef.
Definition events.hpp:113
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:166
void graph_add_node_event(Label &&label, const Predecessor &predecessor, const NodeType &node)
Record an event for a node added after predecessor.
Definition events.hpp:151
void graph_create_event(const Kokkos::Experimental::Graph< Exec > &graph)
Record a GraphCreateEvent event.
Definition events.hpp:129
auto * get_node_ptr(const NodeType &node) noexcept
Retrieve the raw node pointer.
Definition events.hpp:123
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:143
void graph_instantiate_event(const Kokkos::Experimental::Graph< Exec > &graph)
Record a GraphInstantiateEvent event.
Definition events.hpp:178
void graph_submit_event(const Kokkos::Experimental::Graph< Exec > &graph, const Exec &exec)
Record a GraphSubmitEvent event.
Definition events.hpp:186
auto * get_graph_impl_ptr(const NodeType &node) noexcept
Retrieve the raw graph pointer from a node.
Definition events.hpp:117
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:196
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.
Definition label.hpp:75
consteval Impl::Label< std::string_view > label(std::string_view str) noexcept
Definition label.hpp:91
auto get_next_event_id() noexcept
void dispatch(const EventType &event)
#define KOKKOS_EXECUTION_UTILS_STREAMABLE
Definition streamers.hpp:87
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph aggregate node is added.
Definition events.hpp:68
friend std::ostream & operator<<(std::ostream &out, const GraphAddAggregateNodeEvent &event)
Definition events.hpp:76
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:49
constexpr auto operator<=>(const GraphAddNodeEvent &) const =default
friend std::ostream & operator<<(std::ostream &out, const GraphAddNodeEvent &event)
Definition events.hpp:59
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is created.
Definition events.hpp:28
constexpr auto operator<=>(const GraphCreateEvent &) const =default
friend std::ostream & operator<<(std::ostream &out, const GraphCreateEvent &event)
Definition events.hpp:37
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is instantiated.
Definition events.hpp:85
friend std::ostream & operator<<(std::ostream &out, const GraphInstantiateEvent &event)
Definition events.hpp:91
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:98
constexpr auto operator<=>(const GraphSubmitEvent &) const =default
friend std::ostream & operator<<(std::ostream &out, const GraphSubmitEvent &event)
Definition events.hpp:105