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_Macros.hpp"
7#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
8import kokkos.core;
9#else
10# include "Kokkos_Core.hpp"
11#endif
12
23
24namespace Kokkos::Execution {
25
26namespace GraphImpl {
27
29template <Kokkos::ExecutionSpace Exec>
30struct Scheduler {
32 using scheduler_concept = stdexec::scheduler_t;
33
34 using execution_space = Exec;
35
36 template <stdexec::receiver Rcvr>
37 struct OpState {
38 using operation_state_concept = stdexec::operation_state_tag;
39
41 Rcvr rcvr;
42
43 [[nodiscard]]
47
49 void start() & noexcept {
50 stdexec::set_value(std::move(rcvr));
51 }
52 };
53
54 struct Sender {
55 using sender_concept = stdexec::sender_tag;
56
57 using completion_signatures = stdexec::completion_signatures<stdexec::set_value_t()>;
58
60 struct Attributes {
61 template <typename... Env>
62 [[nodiscard]]
63 constexpr auto
64 query(stdexec::get_completion_scheduler_t<stdexec::set_value_t>, Env...) const noexcept -> Scheduler {
65 return {state};
66 }
67
68 template <typename... Env>
69 [[nodiscard]]
70 constexpr auto
71 query(stdexec::get_completion_domain_t<stdexec::set_value_t>, Env...) const noexcept -> Domain {
72 return {};
73 }
74
76 };
77
78 template <stdexec::receiver_of<completion_signatures> Rcvr>
79 [[nodiscard]]
80 OpState<Rcvr> connect(Rcvr rcvr) && noexcept(std::is_nothrow_move_constructible_v<Rcvr>) {
81 return {.state = env.state, .rcvr = std::move(rcvr)};
82 }
83
84 template <stdexec::receiver_of<completion_signatures> Rcvr>
85 [[nodiscard]]
86 OpState<Rcvr> connect(Rcvr rcvr) const & noexcept(std::is_nothrow_move_constructible_v<Rcvr>) {
87 return {.state = env.state, .rcvr = std::move(rcvr)};
88 }
89
90 [[nodiscard]]
91 constexpr auto get_env() const noexcept -> const Attributes& {
92 return env;
93 }
94
96 };
97
98 [[nodiscard]]
99 constexpr auto schedule() const noexcept -> Sender {
100 return {state};
101 }
102
103 [[nodiscard]]
104 constexpr auto query(stdexec::get_completion_domain_t<stdexec::set_value_t>) const noexcept -> Domain {
105 return {};
106 }
107
108 [[nodiscard]]
109 constexpr auto query(stdexec::get_completion_scheduler_t<stdexec::set_value_t>) const noexcept -> Scheduler {
110 return {state};
111 }
112
113 [[nodiscard]]
114 friend bool operator==(const Scheduler&, const Scheduler&) noexcept = default;
115
117};
118
119} // namespace GraphImpl
120
122template <Kokkos::ExecutionSpace Exec>
124 using execution_space = Exec;
125
127
129
130 explicit GraphContext(execution_space exec) // NOLINT(performance-unnecessary-value-param)
131 : m_state{std::move(exec)} {
132 }
133
134 auto get_scheduler() const noexcept -> GraphImpl::Scheduler<execution_space> {
135 return {const_cast<state_t*>(&m_state)};
136 }
137};
138
139} // namespace Kokkos::Execution
140
141#endif // KOKKOS_EXECUTION_GRAPH_HPP
Impl::State< execution_space > state_t
Definition graph.hpp:126
GraphContext(execution_space exec)
Definition graph.hpp:130
auto get_scheduler() const noexcept -> GraphImpl::Scheduler< execution_space >
Definition graph.hpp:134
constexpr auto query(Impl::get_exec_t) const noexcept -> Impl::ExecutionSpaceRef< execution_space >
Definition graph.hpp:44
Impl::State< execution_space > * state
Definition graph.hpp:40
stdexec::operation_state_tag operation_state_concept
Definition graph.hpp:38
See https://github.com/NVIDIA/stdexec/blob/5076be2b35de2e78330201b888d82c81b8cb428b/include/nvexec/st...
Definition graph.hpp:60
constexpr auto query(stdexec::get_completion_scheduler_t< stdexec::set_value_t >, Env...) const noexcept -> Scheduler
Definition graph.hpp:64
constexpr auto query(stdexec::get_completion_domain_t< stdexec::set_value_t >, Env...) const noexcept -> Domain
Definition graph.hpp:71
OpState< Rcvr > connect(Rcvr rcvr) &&noexcept(std::is_nothrow_move_constructible_v< Rcvr >)
Definition graph.hpp:80
constexpr auto get_env() const noexcept -> const Attributes &
Definition graph.hpp:91
OpState< Rcvr > connect(Rcvr rcvr) const &noexcept(std::is_nothrow_move_constructible_v< Rcvr >)
Definition graph.hpp:86
stdexec::completion_signatures< stdexec::set_value_t()> completion_signatures
Definition graph.hpp:57
Scheduler for a Kokkos::Experimental::Graph.
Definition graph.hpp:30
constexpr auto query(stdexec::get_completion_domain_t< stdexec::set_value_t >) const noexcept -> Domain
Definition graph.hpp:104
constexpr auto query(stdexec::get_completion_scheduler_t< stdexec::set_value_t >) const noexcept -> Scheduler
Definition graph.hpp:109
friend bool operator==(const Scheduler &, const Scheduler &) noexcept=default
constexpr auto schedule() const noexcept -> Sender
Definition graph.hpp:99
stdexec::scheduler_t scheduler_concept
As per https://eel.is/c++draft/exec.sched#1.
Definition graph.hpp:32
Wrap a Kokkos execution space to make it cheap to copy/move in new environments.
Definition get_exec.hpp:52