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_Macros.hpp"
11#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
14import kokkos.graph_impl;
16# include "Kokkos_Core.hpp"
17# include "Kokkos_Graph.hpp"
38template <
typename Clsr>
40 typename Clsr::execution_space;
41 requires std::same_as<typename Clsr::device_handle_t, Kokkos::Impl::DeviceHandle<typename Clsr::execution_space>>;
42 typename Clsr::node_props_t;
46template <stdexec::operation_state OpState, Kokkos::ExecutionSpace Exec>
49 requires(
const OpState& op_state) {
54 std::same_as<typename OpState::execution_space, Exec>
59template <stdexec::operation_state OpState, Kokkos::ExecutionSpace Exec>
60requires(stdexec::__is_instance_of<OpState, Kokkos::Execution::GraphImpl::Scheduler<Exec>::template
OpState>)
64template <stdexec::operation_state OpState, Kokkos::ExecutionSpace Exec>
67 && stdexec::__is_instance_of<OpState, Kokkos::Execution::GraphImpl::Scheduler<Exec>::template
OpState>)
71template <stdexec::operation_state OpState, Kokkos::ExecutionSpace Exec>
78 if constexpr (base_t::value) {
79 return stdexec::__msuccess{};
81 return stdexec::__mexception<
82 stdexec::_WHAT_(OPERATION_STATE_DOES_NOT_REMAIN_ON_GRAPH),
83 stdexec::_WHY_(BECAUSE_THE_INNER_OPERATION_STATE_DOES_NOT_REMAIN_ON_GRAPH),
92template <
typename GraphCompositionPolicy, Kokkos::ExecutionSpace Exec>
96template <Kokkos::ExecutionSpace Exec>
100 using graph_t = Kokkos::Experimental::Graph<Exec>;
102 explicit State(
const Kokkos::Impl::DeviceHandle<Exec>&) {
107template <Kokkos::ExecutionSpace Exec>
113 using graph_t = Kokkos::Experimental::Graph<Exec>;
125 return graph.get_device_handle();
129 if (Kokkos::Impl::GraphAccess::get_node_ptr(
m_root) ==
nullptr) {
141template <Kokkos::ExecutionSpace Exec, stdexec::receiver Rcvr>
156 constexpr explicit OpStateBase(Rcvr rcvr)
noexcept(std::is_nothrow_constructible_v<completion_signal_t, Rcvr&&>)
160 template <
typename Error>
161 void complete(stdexec::set_error_t, Error&& error)
noexcept {
162 stdexec::set_error(std::move(
completion_signal.rcvr), std::forward<Error>(error));
171template <
typename Predecessor, Closure FirstClosure>
172requires NodeRef<std::remove_cvref_t<Predecessor>>
173static auto add_nodes(Predecessor&& predecessor, FirstClosure&& clsr) {
174 return std::forward<FirstClosure>(clsr).add_node(std::forward<Predecessor>(predecessor));
177template <
typename Predecessor, Closure FirstClosure, Closure... RestOfClosures>
178requires NodeRef<std::remove_cvref_t<Predecessor>> && (
sizeof...(RestOfClosures) > 0)
179static auto add_nodes(Predecessor&& predecessor, FirstClosure&& clsr, RestOfClosures&&... clsrs) {
181 std::forward<FirstClosure>(clsr).add_node(std::forward<Predecessor>(predecessor)),
182 std::forward<RestOfClosures>(clsrs)...);
186template <stdexec::sender Sndr, stdexec::receiver Rcvr, Closure FirstClosure, Closure... RestOfClosures>
189 ,
public OpStateBase<typename FirstClosure::execution_space, Rcvr> {
196 static_assert((std::same_as<typename RestOfClosures::execution_space, execution_space> && ...));
204 static constexpr bool is_graph_create = std::same_as<graph_composition_policy_t, GraphComposition::Create>;
207 std::declval<predecessor_t>(),
208 std::declval<FirstClosure>(),
209 std::declval<RestOfClosures>()...));
212 [[no_unique_address]]
221 RestOfClosures... clsrs)
noexcept(
false)
226#if defined(KOKKOS_EXECUTION_ENABLE_DEBUG_LOGGING)
227 PLOG_INFO <<
"Operation state graph composition policy is "
241#if defined(KOKKOS_EXECUTION_ENABLE_DEBUG_LOGGING)
245 return state.get_root_node();
246 }
else if constexpr (stdexec::__queryable_with<inner_op_state_t, get_node_t>) {
257 template <
typename Error>
258 void complete(stdexec::set_error_t, Error&& error)
noexcept {
259 stdexec::set_error(std::move(this->
completion_signal.rcvr), std::forward<Error>(error));
268#if defined(KOKKOS_EXECUTION_ENABLE_DEBUG_LOGGING)
270 << Kokkos::Tools::Experimental::device_id(
state.get_device_handle().m_exec) <<
'.';
275 this->
complete(stdexec::set_error, std::current_exception());
316template <
typename Sndr,
typename Rcvr,
typename... Clsrs>
319template <
typename Sndr,
typename Rcvr,
typename... Clsrs>
322#define KOKKOS_EXECUTION_GRAPH_OPERATION_STATE_CONNECT \
323 template <stdexec::receiver Rcvr> \
324 constexpr auto connect(Rcvr rcvr) && noexcept(noexcept(make_op_state_t<Sndr, Rcvr, closure_t>{}( \
325 std::declval<Sndr>(), std::declval<Rcvr>(), std::declval<closure_t>()))) \
326 -> op_state_t<Sndr, Rcvr, closure_t> { \
327 return make_op_state_t<Sndr, Rcvr, closure_t>{}(std::forward<Sndr>(sndr), std::move(rcvr), std::move(clsr)); \
330#if defined(KOKKOS_EXECUTION_ENABLE_DEBUG_LOGGING)
331# define KOKKOS_EXECUTION_IMPL_GRAPH_ADD_NODE_DEBUG_LOGGING(_type_, _node_, _predecessor_) \
332 PLOG_INFO << "Adding '" << _type_ << "' node " << get_node_ptr(_node_) << " to graph " \
333 << get_graph_impl_ptr(_node_) << " after " << get_node_ptr(_predecessor_) << " on device " \
334 << Kokkos::Tools::Experimental::device_id(get_node_ptr(_node_)->get_device_handle().m_exec) << '.';
336# define KOKKOS_EXECUTION_IMPL_GRAPH_ADD_NODE_DEBUG_LOGGING(_type_, _node_, _predecessor_)
#define KOKKOS_EXECUTION_GET_ENV(_type_, _obj_)
Retrieve the environment of _obj_. // NOLINTNEXTLINE(cppcoreguidelines-macro-usage).
static auto add_nodes(Predecessor &&predecessor, FirstClosure &&clsr)
Add all nodes as a sequence. Hence, only the first node may be added after the root node.
Impl::MakeOpState< Domain, OpState >::Huddle< Sndr, Rcvr, Clsrs... > make_op_state_t
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.
constexpr get_graph_t get_graph
auto * get_graph_impl_ptr(const NodeType &node) noexcept
Retrieve the raw graph pointer from a 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.
typename make_op_state_t< Sndr, Rcvr, Clsrs... >::type op_state_t
constexpr get_exec_t get_exec
typename Diagnose< Ts... >::type diagnose_t
constexpr auto display_string_of() noexcept -> 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, Queryables... >::type node_t
std::conditional_t<(stdexec::__queryable_with< Queryables, get_node_t >||...), Attach, Create > policy_t
Use the Attach policy if any Queryables is queryable with get_node_t.
decltype(select_completion_signal_policy()) completion_signal_policy_t
Impl::CompletionSignal< completion_signal_policy_t, Exec, Rcvr > completion_signal_t
void complete(stdexec::set_error_t, Error &&error) noexcept
static consteval auto select_completion_signal_policy() noexcept
void complete(stdexec::set_stopped_t) noexcept
completion_signal_t completion_signal
constexpr OpStateBase(Rcvr rcvr) noexcept(std::is_nothrow_constructible_v< completion_signal_t, Rcvr && >)
Operation state that adds all closures as a sequence of nodes.
stdexec::connect_result_t< Sndr, rcvr_t > inner_op_state_t
void complete(stdexec::set_error_t, Error &&error) noexcept
inner_op_state_t inner_op_state
Impl::SubmittedOperationStateTag operation_state_concept
GraphComposition::node_t< execution_space, inner_op_state_t, Rcvr > predecessor_t
constexpr OpState(Sndr &&sndr, Rcvr rcvr, FirstClosure clsr, RestOfClosures... clsrs) noexcept(false)
auto get_predecessor() const noexcept -> const predecessor_t &
State< graph_composition_policy_t, execution_space > state_t
decltype(add_nodes( std::declval< predecessor_t >(), std::declval< FirstClosure >(), std::declval< RestOfClosures >()...)) node_t
typename FirstClosure::device_handle_t device_handle_t
static constexpr bool is_graph_create
auto query(get_graph_t) const &noexcept -> const typename state_t::graph_t &
void complete(stdexec::set_stopped_t) noexcept
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
void complete(stdexec::set_value_t) noexcept
auto query(get_node_t) const &noexcept -> const node_t &
GraphComposition::policy_t< inner_op_state_t, Rcvr > graph_composition_policy_t
constexpr auto query(Impl::get_exec_t) const noexcept -> Impl::ExecutionSpaceRef< execution_space >
constexpr auto query(Impl::get_exec_t) const noexcept -> decltype(auto) requires(!is_graph_create)
static constexpr auto diagnose() noexcept
RemainsOnGraphFor< typename OpState::inner_op_state_t, Exec > base_t
State(const Kokkos::Impl::DeviceHandle< Exec > &)
Kokkos::Experimental::Graph< Exec > graph_t
GraphComposition::Attach graph_composition_policy_t
typename graph_t::root_t root_t
const device_handle_t & get_device_handle() const
State(const device_handle_t &device_handle)
Kokkos::Impl::DeviceHandle< Exec > device_handle_t
const root_t & get_root_node() const
Kokkos::Experimental::Graph< Exec > graph_t
GraphComposition::Create graph_composition_policy_t
Wrap a Kokkos execution space to make it cheap to copy/move in new environments.
Receiver for an object parent_op that implements complete.
Tag to be used to signal an execution space.