kokkos-execution 0.0.1
Loading...
Searching...
No Matches
schedule_from.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_EXECUTION_SPACE_SCHEDULE_FROM_HPP
2#define KOKKOS_EXECUTION_EXECUTION_SPACE_SCHEDULE_FROM_HPP
3
4#include "stdexec/execution.hpp"
5
7
12
14
16template <stdexec::scheduler Schd, stdexec::receiver Rcvr>
18 using receiver_concept = stdexec::receiver_t;
19
20 Schd schd;
21 Rcvr rcvr;
22
23 void set_value() && noexcept {
25 const bool skip = [&]() {
26 if constexpr (stdexec::__is_instance_of<Rcvr, ContinuesOnReceiver>) {
27 if constexpr (stdexec::__queryable_with<stdexec::env_of_t<Rcvr>, get_exec_t>) {
28 if constexpr (
29 std::same_as<
30 std::remove_cvref_t<decltype(get_exec(stdexec::get_env(rcvr)).get())>,
31 typename Schd::execution_space
32 >) {
33 return schd.state->exec == get_exec(stdexec::get_env(rcvr)).get();
34 }
35 }
36 }
37 return false;
38 }();
39 if (!skip)
40 schd.state->exec.fence(
41 std::format("{}: schedule_from", Kokkos::Impl::TypeInfo<typename Schd::execution_space>::name()));
42 stdexec::set_value(std::move(rcvr));
43 }
44
45 template <typename Error>
46 void set_error(Error&& err) && noexcept {
47 stdexec::set_error(std::move(rcvr), std::forward<Error>(err));
48 }
49
50 void set_stopped() && noexcept {
51 stdexec::set_stopped(std::move(rcvr));
52 }
53
55 KOKKOS_EXECUTION_UPSERT_EXEC(typename Schd::execution_space, schd.state->exec, Rcvr, rcvr)
56};
57
59template <stdexec::scheduler Schd, stdexec::sender Sndr>
61 using sender_concept = stdexec::sender_t;
62
64
65 template <typename Rcvr>
67
68 template <stdexec::receiver Rcvr>
69 stdexec::operation_state auto connect(Rcvr rcvr) && noexcept(
70 std::is_nothrow_constructible_v<rcvr_t<Rcvr>, Schd&&, Rcvr&&>
71 && stdexec::__nothrow_connectable<Sndr&&, rcvr_t<Rcvr>>) {
72 return stdexec::connect(
73 std::forward<Sndr>(sndr), rcvr_t<Rcvr>{.schd = std::move(schd), .rcvr = std::move(rcvr)});
74 }
75
77
78 Schd schd;
79 Sndr sndr; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
80};
81
82template <>
83struct TransformSenderFor<stdexec::schedule_from_t> {
84 template <typename Sndr, typename Env>
85 using schd_t = stdexec::__completion_scheduler_of_t<stdexec::set_value_t, Sndr, Env>;
86
87 template <typename Sndr, typename Env>
89
90 template <typename Env, execution_space_completing_sender<Env> Sndr>
91 auto operator()(const Env& env, stdexec::schedule_from_t, stdexec::__ignore, Sndr&& sndr) const
92 noexcept(std::is_nothrow_constructible_v<sndr_t<Sndr, Env>, schd_t<Sndr, Env>&&, Sndr&&>) {
93
94 return sndr_t<Sndr, Env>{
95 .schd = stdexec::get_completion_scheduler<stdexec::set_value_t>(stdexec::get_env(sndr), env),
96 .sndr = std::forward<Sndr>(sndr)};
97 }
98};
99
100} // namespace Kokkos::Execution::ExecutionSpaceImpl
101
102#endif // KOKKOS_EXECUTION_EXECUTION_SPACE_SCHEDULE_FROM_HPP
#define KOKKOS_EXECUTION_IMPL_FORWARDING_ATTRIBUTES_GET_ENV(_type_, _obj_)
#define KOKKOS_EXECUTION_COMPL_SIGS_KEEP(_sndr_type_)
#define KOKKOS_EXECUTION_UPSERT_EXEC(_exec_type_, _exec_, _rcvr_type_, _rcvr_)
Definition get_exec.hpp:66
stdexec::operation_state auto connect(Rcvr rcvr) &&noexcept(std::is_nothrow_constructible_v< rcvr_t< Rcvr >, Schd &&, Rcvr && > &&stdexec::__nothrow_connectable< Sndr &&, rcvr_t< Rcvr > >)
auto operator()(const Env &env, stdexec::schedule_from_t, stdexec::__ignore, Sndr &&sndr) const noexcept(std::is_nothrow_constructible_v< sndr_t< Sndr, Env >, schd_t< Sndr, Env > &&, Sndr && >)
stdexec::__completion_scheduler_of_t< stdexec::set_value_t, Sndr, Env > schd_t