1#ifndef KOKKOS_EXECUTION_GRAPH_OPERATION_STATE_HPP
2#define KOKKOS_EXECUTION_GRAPH_OPERATION_STATE_HPP
6#if defined(KOKKOS_EXECUTION_ENABLE_DEBUG_LOGGING)
10#include "Kokkos_Core.hpp"
11#include "Kokkos_Graph.hpp"
26template <
typename Clsr>
28 typename Clsr::execution_space;
29 requires std::same_as<typename Clsr::device_handle_t, Kokkos::Impl::DeviceHandle<typename Clsr::execution_space>>;
30 typename Clsr::node_props_t;
33template <
typename GraphCompositionPolicy, Kokkos::ExecutionSpace Exec>
37template <Kokkos::ExecutionSpace Exec>
41 explicit State(
const Kokkos::Impl::DeviceHandle<Exec>&) {
46template <Kokkos::ExecutionSpace Exec>
50 using graph_t = Kokkos::Experimental::Graph<Exec>;
54 explicit State(
const Kokkos::Impl::DeviceHandle<Exec>& device_handle)
59 return graph.get_device_handle();
68template <Kokkos::ExecutionSpace Exec, stdexec::receiver Rcvr>
75 constexpr explicit OpStateBase(Rcvr rcvr)
noexcept(std::is_nothrow_constructible_v<completion_signal_t, Rcvr&&>)
83 template <
typename Error>
84 void complete(stdexec::set_error_t, Error&& error)
noexcept {
88 void complete(stdexec::set_stopped_t)
noexcept {
94template <
typename Predecessor, Closure FirstClosure, Closure... RestOfClosures>
95requires NodeRef<std::remove_cvref_t<Predecessor>>
96static auto add_nodes(Predecessor&& predecessor, FirstClosure&& clsr, RestOfClosures&&... clsrs) {
97 auto node = std::forward<FirstClosure>(clsr).add_node(std::forward<Predecessor>(predecessor));
98 if constexpr (
sizeof...(RestOfClosures) == 0) {
101 return add_nodes(std::move(node), std::forward<RestOfClosures>(clsrs)...);
106template <stdexec::sender Sndr, stdexec::receiver Rcvr, Closure FirstClosure, Closure... RestOfClosures>
109 ,
public OpStateBase<typename FirstClosure::execution_space, Rcvr> {
116 static_assert((std::same_as<typename RestOfClosures::execution_space, execution_space> && ...));
124 static constexpr bool after_root = std::same_as<graph_composition_policy_t, GraphComposition::Create>;
127 std::declval<predecessor_t>(),
128 std::declval<FirstClosure>(),
129 std::declval<RestOfClosures>()...));
140 RestOfClosures... clsrs)
noexcept(
false)
145#if defined(KOKKOS_EXECUTION_ENABLE_DEBUG_LOGGING)
146 PLOG_INFO <<
"Operation state graph composition policy is "
147 << Kokkos::Impl::TypeInfo<graph_composition_policy_t>::name()
148 <<
" and the inner operation state is of type " << Kokkos::Impl::TypeInfo<inner_opstate_t>::name()
159#if defined(KOKKOS_EXECUTION_ENABLE_DEBUG_LOGGING)
163 return state.graph.root_node();
165#if defined(KOKKOS_EXECUTION_ENABLE_DEBUG_LOGGING)
175#if defined(KOKKOS_EXECUTION_ENABLE_DEBUG_LOGGING)
177 << Kokkos::Tools::Experimental::device_id(
state.get_device_handle().m_exec) <<
'.';
209template <
typename Sndr,
typename Rcvr,
typename... Clsrs>
212template <
typename Sndr,
typename Rcvr,
typename... Clsrs>
215#define KOKKOS_EXECUTION_GRAPH_OPERATION_STATE_CONNECT \
216 template <stdexec::receiver Rcvr> \
217 constexpr auto connect(Rcvr rcvr) && noexcept(noexcept(make_opstate_t<Sndr, Rcvr, closure_t>{}( \
218 std::declval<Sndr>(), std::declval<Rcvr>(), std::declval<closure_t>()))) -> opstate_t<Sndr, Rcvr, closure_t> { \
219 return make_opstate_t<Sndr, Rcvr, closure_t>{}(std::forward<Sndr>(sndr), std::move(rcvr), std::move(clsr)); \
222#if defined(KOKKOS_EXECUTION_ENABLE_DEBUG_LOGGING)
223# define KOKKOS_EXECUTION_IMPL_GRAPH_ADD_NODE_DEBUG_LOGGING(_type_, _node_, _predecessor_) \
224 PLOG_INFO << "Adding '" _type_ "' node " << get_node_ptr(_node_) << " to graph " << get_graph_impl_ptr(_node_) \
225 << " after " << get_node_ptr(_predecessor_) << " on device " \
226 << Kokkos::Tools::Experimental::device_id(get_node_ptr(_node_)->get_device_handle().m_exec) << '.';
228# define KOKKOS_EXECUTION_IMPL_GRAPH_ADD_NODE_DEBUG_LOGGING(_type_, _node_, _predecessor_)
typename make_opstate_t< Sndr, Rcvr, Clsrs... >::type opstate_t
auto * get_node_ptr(const NodeType &node) noexcept
Retrieve the raw node pointer.
constexpr get_node_t get_node
auto create_graph(const Kokkos::Impl::DeviceHandle< Exec > &device_handle, Args &&... args)
Create a graph and record the associated event with graph_create_event.
Impl::MakeOpState< Domain, OpState >::Huddle< Sndr, Rcvr, Clsrs... > make_opstate_t
constexpr get_graph_t get_graph
auto * get_graph_impl_ptr(const NodeType &node) noexcept
Retrieve the raw graph pointer from a node.
static auto add_nodes(Predecessor &&predecessor, FirstClosure &&clsr, RestOfClosures &&... clsrs)
Add all nodes as a sequence. Hence, only the first node may be added after the root node.
void submit_graph(const Kokkos::Experimental::Graph< Exec > &graph, const Exec &exec)
Submit a graph and record the associated event with graph_submit_event.
consteval std::string_view dispatch_label() noexcept
View the dispatch label as a std::string_view.
Attach to the existing graph of the predecessor.
Create a new graph and attach after the root node.
Inspired by https://github.com/NVIDIA/stdexec/blob/8c5eedd0fcf9a8ebcdb75d988f72f88efcf64a37/include/s...
typename node_helper_t< Exec, Queryable >::type node_t
std::conditional_t< stdexec::__queryable_with< Queryable, get_node_t >, Attach, Create > policy_t
Use the Attach policy if Queryable is queryable with get_node_t.
void complete(stdexec::set_error_t, Error &&error) noexcept
Impl::CompletionSignal< sync_policy_t, Exec, Rcvr > completion_signal_t
void complete(stdexec::set_stopped_t) noexcept
completion_signal_t completion_signal
Impl::SyncPolicy::PassThrough sync_policy_t
void complete(stdexec::set_value_t) noexcept
constexpr OpStateBase(Rcvr rcvr) noexcept(std::is_nothrow_constructible_v< completion_signal_t, Rcvr && >)
stdexec::connect_result_t< Sndr, rcvr_t > inner_opstate_t
static constexpr bool after_root
const auto & query(get_node_t) const &noexcept
stdexec::operation_state_tag operation_state_concept
constexpr OpState(Sndr &&sndr, Rcvr rcvr, FirstClosure clsr, RestOfClosures... clsrs) noexcept(false)
State< graph_composition_policy_t, execution_space > state_t
inner_opstate_t inner_opstate
typename FirstClosure::device_handle_t device_handle_t
GraphComposition::policy_t< inner_opstate_t > graph_composition_policy_t
GraphComposition::node_t< execution_space, inner_opstate_t > predecessor_t
constexpr auto get_env() const noexcept -> stdexec::env_of_t< Rcvr >
predecessor_t get_predecessor() const
Impl::Receiver< OpState, stdexec::env_of_t< Rcvr > > rcvr_t
Ensure that all closures are on the same execution space type.
typename FirstClosure::execution_space execution_space
const auto & query(get_graph_t) const &noexcept
decltype(add_nodes( std::declval< predecessor_t >(), std::declval< FirstClosure >(), std::declval< RestOfClosures >()...)) node_t
void complete(stdexec::set_value_t) noexcept
State(const Kokkos::Impl::DeviceHandle< Exec > &)
GraphComposition::Attach graph_composition_policy_t
State(const Kokkos::Impl::DeviceHandle< Exec > &device_handle)
Kokkos::Experimental::Graph< Exec > graph_t
const auto & get_device_handle() const
GraphComposition::Create graph_composition_policy_t
Receiver for an object parent_op that implements complete.