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>
37 namespace Experimental {
42 template <
class ExecutionSpace>
43 struct [[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();
101 template <
class... PredecessorRefs>
106 auto 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));
129 template <
class ExecutionSpace,
class Closure>
130 Graph<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>
147 Graph<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 #if defined(KOKKOS_ENABLE_HIP)
166 #if !((HIP_VERSION_MAJOR == 5) && (HIP_VERSION_MINOR == 2))
167 #include <HIP/Kokkos_HIP_Graph_Impl.hpp>
170 #ifdef SYCL_EXT_ONEAPI_GRAPH
171 #include <SYCL/Kokkos_SYCL_Graph_Impl.hpp>
173 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_GRAPH
174 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
175 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_GRAPH
177 #endif // KOKKOS_GRAPH_HPP