kokkos-execution 0.0.1
Loading...
Searching...
No Matches
operation_state.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_EXECUTION_SPACE_OPERATION_STATE_HPP
2#define KOKKOS_EXECUTION_EXECUTION_SPACE_OPERATION_STATE_HPP
3
5
16
18
19template <typename Clsr>
20concept Closure = requires(const Clsr& clsr) {
21 typename Clsr::execution_space;
22
23 { clsr.submit() } -> std::same_as<void>;
24
25 { clsr.get_policy() };
26 requires Kokkos::ExecutionPolicy<std::remove_cvref_t<decltype(clsr.get_policy())>>;
27
28 requires std::same_as<std::remove_cvref_t<decltype(clsr.get_policy().space())>, typename Clsr::execution_space>;
29};
30
31template <typename Exec, typename Rcvr>
37 } else if constexpr (
39 && stdexec::__queryable_with<stdexec::env_of_t<Rcvr>, stdexec::get_delegation_scheduler_t>) {
41 } else {
43 }
44}
45
46template <stdexec::receiver Rcvr, Closure Clsr, Closure... Clsrs>
47requires(std::same_as<typename Clsr::execution_space, typename Clsrs::execution_space> && ...)
49 using execution_space = typename Clsr::execution_space;
50
53 using closures_t = stdexec::__tuple<Clsr, Clsrs...>;
54
57
58 constexpr explicit OpStateBase(Rcvr rcvr, Clsr clsr_, Clsrs... clsrs_) noexcept(
59 std::is_nothrow_constructible_v<completion_signal_t, Rcvr&&> && std::is_nothrow_move_constructible_v<Clsr>
60 && (std::is_nothrow_move_constructible_v<Clsrs> && ...))
61 : completion_signal(std::move(rcvr))
62 , clsrs(std::move(clsr_), std::move(clsrs_)...) {
63 }
64
65 void complete(stdexec::set_value_t) noexcept {
66 this->submit();
67 }
68
69 template <typename Error>
70 void complete(stdexec::set_error_t, Error&& error) noexcept {
71 stdexec::set_error(std::move(completion_signal.rcvr), std::forward<Error>(error));
72 }
73
74 void complete(stdexec::set_stopped_t) noexcept {
75 stdexec::set_stopped(std::move(completion_signal.rcvr));
76 }
77
78 void submit() noexcept {
79 try {
80 stdexec::__apply([](auto&... clsr) { (clsr.submit(), ...); }, clsrs);
81 } catch (...) {
82 this->complete(stdexec::set_error, std::current_exception());
83 return;
84 }
85 completion_signal.propagate(this->query(Impl::get_exec).get());
86 }
87
89 [[nodiscard]]
91 return Impl::ExecutionSpaceRef<execution_space>{stdexec::__get<0>(clsrs).get_policy().space()};
92 }
93
94 KOKKOS_EXECUTION_GET_ENV(Rcvr, this->completion_signal.rcvr)
95};
96
97template <stdexec::sender Sndr, stdexec::receiver Rcvr, Closure... Clsrs>
99struct OpState
100 : public Impl::Immovable
101 , public OpStateBase<Rcvr, Clsrs...> {
103
104 using base_t = OpStateBase<Rcvr, Clsrs...>;
106
107 using inner_opstate_t = stdexec::connect_result_t<Sndr, rcvr_t>;
108
110 std::is_nothrow_constructible_v<base_t, Rcvr&&, Clsrs&&...>;
111
112 static constexpr bool inner_opstate_is_nothrow_constructible = stdexec::__nothrow_connectable<Sndr&&, rcvr_t>;
113
115
117#if defined(KOKKOS_EXECUTION_IMPL_OPSTATE_IMMOVABLE_FIX)
118 STDEXEC_IMMOVABLE(OpState);
119#endif
120
121 constexpr explicit OpState(
122 Sndr&& sndr, // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
123 Rcvr rcvr_,
125 : base_t(std::move(rcvr_), std::move(clsrs_)...)
126 , inner_opstate(stdexec::connect(std::forward<Sndr>(sndr), rcvr_t{this})) {
127 }
128
129 void start() & noexcept {
130 stdexec::start(inner_opstate);
131 }
132};
133
134template <typename Sndr, typename Rcvr, typename... Clsrs>
136
137template <typename Sndr, typename Rcvr, typename... Clsrs>
138using opstate_t = typename make_opstate_t<Sndr, Rcvr, Clsrs...>::type;
139
140} // namespace Kokkos::Execution::ExecutionSpaceImpl
141
142#endif // KOKKOS_EXECUTION_EXECUTION_SPACE_OPERATION_STATE_HPP
Concept that constrains the type of a sender that dispatches a functor for execution.
#define KOKKOS_EXECUTION_GET_ENV(_type_, _obj_)
Retrieve the environment of _obj_. // NOLINTNEXTLINE(cppcoreguidelines-macro-usage).
Definition env.hpp:14
typename make_opstate_t< Sndr, Rcvr, Clsrs... >::type opstate_t
Impl::MakeOpState< Domain, OpState >::Huddle< Sndr, Rcvr, Clsrs... > make_opstate_t
constexpr get_exec_t get_exec
Definition get_exec.hpp:19
Impl::CompletionSignal< completion_signal_policy_t, execution_space, Rcvr > completion_signal_t
constexpr auto query(Impl::get_exec_t) const noexcept -> Impl::ExecutionSpaceRef< execution_space >
void complete(stdexec::set_stopped_t) noexcept
stdexec::__tuple< Clsr, Clsrs... > closures_t
decltype(select_completion_signal_policy< execution_space, Rcvr >()) completion_signal_policy_t
constexpr OpStateBase(Rcvr rcvr, Clsr clsr_, Clsrs... clsrs_) noexcept(std::is_nothrow_constructible_v< completion_signal_t, Rcvr && > &&std::is_nothrow_move_constructible_v< Clsr > &&(std::is_nothrow_move_constructible_v< Clsrs > &&...))
void complete(stdexec::set_error_t, Error &&error) noexcept
void complete(stdexec::set_value_t) noexcept
Impl::SubmittedOperationStateTag operation_state_concept
constexpr OpState(Sndr &&sndr, Rcvr rcvr_, Clsrs... clsrs_) noexcept(opstate_base_is_nothrow_constructible &&inner_opstate_is_nothrow_constructible)
stdexec::connect_result_t< Sndr, rcvr_t > inner_opstate_t
Wrap a Kokkos execution space to make it cheap to copy/move in new environments.
Definition get_exec.hpp:47
Receiver for an object parent_op that implements complete.
Definition receiver.hpp:13