17#ifndef KOKKOS_GRAPH_HPP
18#define KOKKOS_GRAPH_HPP
19#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
20#define KOKKOS_IMPL_PUBLIC_INCLUDE
21#define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_GRAPH
24#include <Kokkos_Macros.hpp>
25#include <impl/Kokkos_Error.hpp>
27#include <Kokkos_Graph_fwd.hpp>
28#include <impl/Kokkos_GraphImpl_fwd.hpp>
31#include <impl/Kokkos_GraphImpl.hpp>
42template <
class ExecutionSpace>
43struct [[nodiscard]] Graph {
48 using execution_space = ExecutionSpace;
58 friend struct Kokkos::Impl::GraphAccess;
66 using impl_t = Kokkos::Impl::GraphImpl<ExecutionSpace>;
67 std::shared_ptr<impl_t> m_impl_ptr =
nullptr;
78 explicit Graph(std::shared_ptr<impl_t> arg_impl_ptr)
79 : m_impl_ptr(std::move(arg_impl_ptr)) {}
85 ExecutionSpace
const& get_execution_space()
const {
86 return m_impl_ptr->get_execution_space();
90 KOKKOS_EXPECTS(
bool(m_impl_ptr))
91 (*m_impl_ptr).submit();
101template <
class... PredecessorRefs>
106auto when_all(PredecessorRefs&&... arg_pred_refs) {
110 static_assert(
sizeof...(PredecessorRefs) > 0,
111 "when_all() needs at least one predecessor.");
112 auto graph_ptr_impl =
113 Kokkos::Impl::GraphAccess::get_graph_weak_ptr(
114 std::get<0>(std::forward_as_tuple(arg_pred_refs...)))
116 auto node_ptr_impl = graph_ptr_impl->create_aggregate_ptr(arg_pred_refs...);
117 graph_ptr_impl->add_node(node_ptr_impl);
118 (graph_ptr_impl->add_predecessor(node_ptr_impl, arg_pred_refs), ...);
119 return Kokkos::Impl::GraphAccess::make_graph_node_ref(
120 std::move(graph_ptr_impl), std::move(node_ptr_impl));
129template <
class ExecutionSpace,
class Closure>
130Graph<ExecutionSpace> create_graph(ExecutionSpace ex, Closure&& arg_closure) {
136 auto rv = Kokkos::Impl::GraphAccess::construct_graph(std::move(ex));
138 ((Closure &&) arg_closure)(Kokkos::Impl::GraphAccess::create_root_ref(rv));
145 class ExecutionSpace = DefaultExecutionSpace,
146 class Closure = Kokkos::Impl::DoNotExplicitlySpecifyThisTemplateParameter>
147Graph<ExecutionSpace> create_graph(Closure&& arg_closure) {
148 return create_graph(ExecutionSpace{}, (Closure &&) arg_closure);
159#include <Kokkos_GraphNode.hpp>
161#include <impl/Kokkos_GraphNodeImpl.hpp>
162#include <impl/Kokkos_Default_Graph_Impl.hpp>
163#include <Cuda/Kokkos_Cuda_Graph_Impl.hpp>
164#ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_GRAPH
165#undef KOKKOS_IMPL_PUBLIC_INCLUDE
166#undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_GRAPH