kokkos-execution 0.0.1
Loading...
Searching...
No Matches
graph.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_GRAPH_HPP
2#define KOKKOS_EXECUTION_GRAPH_HPP
3
5
6#include "Kokkos_Core.hpp"
7
17
18namespace Kokkos::Execution {
19
20namespace GraphImpl {
21
23template <Kokkos::ExecutionSpace Exec>
24struct Scheduler {
26 using scheduler_concept = stdexec::scheduler_t;
27
28 using execution_space = Exec;
29
30 template <stdexec::receiver Rcvr>
31 struct OpState {
32 using operation_state_concept = stdexec::operation_state_tag;
33
35 Rcvr rcvr;
36
37 [[nodiscard]]
41
43 void start() & noexcept {
44 stdexec::set_value(std::move(rcvr));
45 }
46
47 template <typename R = Rcvr>
48 [[nodiscard]]
49 auto query(get_node_t) const & noexcept -> stdexec::__query_result_t<R, get_node_t>
50 requires std::same_as<GraphComposition::policy_t<R>, GraphComposition::Attach>
51 {
52 return this->rcvr.query(get_node);
53 }
54 };
55
56 struct Sender {
57 using sender_concept = stdexec::sender_tag;
58
59 using completion_signatures = stdexec::completion_signatures<stdexec::set_value_t()>;
60
62 struct Attributes {
63 template <typename... Env>
64 [[nodiscard]]
65 constexpr auto
66 query(stdexec::get_completion_scheduler_t<stdexec::set_value_t>, Env...) const noexcept -> Scheduler {
67 return {state};
68 }
69
70 template <typename... Env>
71 [[nodiscard]]
72 constexpr auto
73 query(stdexec::get_completion_domain_t<stdexec::set_value_t>, Env...) const noexcept -> Domain {
74 return {};
75 }
76
78 };
79
80 template <stdexec::receiver_of<completion_signatures> Rcvr>
81 [[nodiscard]]
82 OpState<Rcvr> connect(Rcvr rcvr) && noexcept(std::is_nothrow_move_constructible_v<Rcvr>) {
83 return {.state = env.state, .rcvr = std::move(rcvr)};
84 }
85
86 template <stdexec::receiver_of<completion_signatures> Rcvr>
87 [[nodiscard]]
88 OpState<Rcvr> connect(Rcvr rcvr) const & noexcept(std::is_nothrow_move_constructible_v<Rcvr>) {
89 return {.state = env.state, .rcvr = std::move(rcvr)};
90 }
91
92 [[nodiscard]]
93 constexpr auto get_env() const noexcept -> const Attributes& {
94 return env;
95 }
96
98 };
99
100 [[nodiscard]]
101 constexpr auto schedule() const noexcept -> Sender {
102 return {state};
103 }
104
105 [[nodiscard]]
106 constexpr auto query(stdexec::get_completion_domain_t<stdexec::set_value_t>) const noexcept -> Domain {
107 return {};
108 }
109
110 [[nodiscard]]
111 constexpr auto query(stdexec::get_completion_scheduler_t<stdexec::set_value_t>) const noexcept -> Scheduler {
112 return {state};
113 }
114
115 [[nodiscard]]
116 friend bool operator==(const Scheduler&, const Scheduler&) noexcept = default;
117
119};
120
121} // namespace GraphImpl
122
124template <Kokkos::ExecutionSpace Exec>
127
129
130 explicit GraphContext(Exec exec) // NOLINT(performance-unnecessary-value-param)
131 : m_state{std::move(exec)} {
132 }
133
134 auto get_scheduler() const noexcept -> GraphImpl::Scheduler<Exec> {
135 return {const_cast<state_t*>(&m_state)};
136 }
137};
138
139} // namespace Kokkos::Execution
140
141#endif // KOKKOS_EXECUTION_GRAPH_HPP
constexpr get_node_t get_node
Definition get_node.hpp:15
auto get_scheduler() const noexcept -> GraphImpl::Scheduler< Exec >
Definition graph.hpp:134
Impl::State< Exec > state_t
Definition graph.hpp:126
Attach to the existing graph of the predecessor.
Definition get_graph.hpp:33
auto query(get_node_t) const &noexcept -> stdexec::__query_result_t< R, get_node_t >
Definition graph.hpp:49
constexpr auto query(Impl::get_exec_t) const noexcept -> Impl::ExecutionSpaceRef< execution_space >
Definition graph.hpp:38
Impl::State< execution_space > * state
Definition graph.hpp:34
stdexec::operation_state_tag operation_state_concept
Definition graph.hpp:32
See https://github.com/NVIDIA/stdexec/blob/5076be2b35de2e78330201b888d82c81b8cb428b/include/nvexec/st...
Definition graph.hpp:62
constexpr auto query(stdexec::get_completion_scheduler_t< stdexec::set_value_t >, Env...) const noexcept -> Scheduler
Definition graph.hpp:66
constexpr auto query(stdexec::get_completion_domain_t< stdexec::set_value_t >, Env...) const noexcept -> Domain
Definition graph.hpp:73
OpState< Rcvr > connect(Rcvr rcvr) &&noexcept(std::is_nothrow_move_constructible_v< Rcvr >)
Definition graph.hpp:82
constexpr auto get_env() const noexcept -> const Attributes &
Definition graph.hpp:93
OpState< Rcvr > connect(Rcvr rcvr) const &noexcept(std::is_nothrow_move_constructible_v< Rcvr >)
Definition graph.hpp:88
stdexec::completion_signatures< stdexec::set_value_t()> completion_signatures
Definition graph.hpp:59
Scheduler for a Kokkos::Experimental::Graph.
Definition graph.hpp:24
constexpr auto query(stdexec::get_completion_domain_t< stdexec::set_value_t >) const noexcept -> Domain
Definition graph.hpp:106
constexpr auto query(stdexec::get_completion_scheduler_t< stdexec::set_value_t >) const noexcept -> Scheduler
Definition graph.hpp:111
friend bool operator==(const Scheduler &, const Scheduler &) noexcept=default
constexpr auto schedule() const noexcept -> Sender
Definition graph.hpp:101
stdexec::scheduler_t scheduler_concept
As per https://eel.is/c++draft/exec.sched#1.
Definition graph.hpp:26
Wrap a Kokkos execution space to make it cheap to copy/move in new environments.
Definition get_exec.hpp:47