45 #ifndef KOKKOS_GRAPH_HPP 46 #define KOKKOS_GRAPH_HPP 48 #include <Kokkos_Macros.hpp> 49 #include <impl/Kokkos_Error.hpp> 51 #include <Kokkos_Graph_fwd.hpp> 52 #include <impl/Kokkos_GraphImpl_fwd.hpp> 55 #include <impl/Kokkos_GraphImpl.hpp> 57 #include <impl/Kokkos_Utilities.hpp> 68 template <
class ExecutionSpace>
69 struct KOKKOS_ATTRIBUTE_NODISCARD Graph {
74 using execution_space = ExecutionSpace;
84 friend struct Kokkos::Impl::GraphAccess;
92 using impl_t = Kokkos::Impl::GraphImpl<ExecutionSpace>;
93 std::shared_ptr<impl_t> m_impl_ptr =
nullptr;
104 explicit Graph(std::shared_ptr<impl_t> arg_impl_ptr)
105 : m_impl_ptr(std::move(arg_impl_ptr)) {}
111 ExecutionSpace
const& get_execution_space()
const {
112 return m_impl_ptr->get_execution_space();
115 void submit()
const {
116 KOKKOS_EXPECTS(
bool(m_impl_ptr))
117 (*m_impl_ptr).submit();
127 template <
class... PredecessorRefs>
132 auto when_all(PredecessorRefs&&... arg_pred_refs) {
136 static_assert(
sizeof...(PredecessorRefs) > 0,
137 "when_all() needs at least one predecessor.");
138 auto graph_ptr_impl =
139 Kokkos::Impl::GraphAccess::get_graph_weak_ptr(
140 std::get<0>(std::forward_as_tuple(arg_pred_refs...)))
142 auto node_ptr_impl = graph_ptr_impl->create_aggregate_ptr(arg_pred_refs...);
143 graph_ptr_impl->add_node(node_ptr_impl);
144 KOKKOS_IMPL_FOLD_COMMA_OPERATOR(
145 graph_ptr_impl->add_predecessor(node_ptr_impl, arg_pred_refs) );
146 return Kokkos::Impl::GraphAccess::make_graph_node_ref(
147 std::move(graph_ptr_impl), std::move(node_ptr_impl));
156 template <
class ExecutionSpace,
class Closure>
157 Graph<ExecutionSpace> create_graph(ExecutionSpace ex, Closure&& arg_closure) {
163 auto rv = Kokkos::Impl::GraphAccess::construct_graph(std::move(ex));
165 ((Closure &&) arg_closure)(Kokkos::Impl::GraphAccess::create_root_ref(rv));
172 class ExecutionSpace = DefaultExecutionSpace,
173 class Closure = Kokkos::Impl::DoNotExplicitlySpecifyThisTemplateParameter>
174 Graph<ExecutionSpace> create_graph(Closure&& arg_closure) {
175 return create_graph(ExecutionSpace{}, (Closure &&) arg_closure);
186 #include <Kokkos_GraphNode.hpp> 188 #include <impl/Kokkos_GraphNodeImpl.hpp> 189 #include <impl/Kokkos_Default_Graph_Impl.hpp> 190 #include <Cuda/Kokkos_Cuda_Graph_Impl.hpp> 191 #endif // KOKKOS_GRAPH_HPP