kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_then.cpp
Go to the documentation of this file.
4
7
19
31
32namespace Tests::GraphImpl {
33
34using namespace Kokkos::utils::callbacks;
35
54
56consteval bool test_sndr_traits() {
58 using schd_sndr_t = typename ThenTest::schedule_sender_t;
59
62 using then_sndr_t = stdexec::transform_sender_result_t<
63 decltype(stdexec::then(std::declval<schd_sndr_t>(), std::declval<functor_t>())),
64 stdexec::env<>
65 >;
66
69 static_assert(std::same_as<Kokkos::Execution::Impl::exec_of_t<then_sndr_t>, TEST_EXECUTION_SPACE>);
70
73
74 return true;
75}
76static_assert(test_sndr_traits());
77
80 typename ThenTest::scheduler_t,
81 stdexec::then_t,
83>());
84
86consteval bool test_sndr_nothrow_transformable() {
87 using sndr_then_t =
88 decltype(stdexec::schedule(std::declval<typename ThenTest::scheduler_t>()) | stdexec::then(Tests::Utils::Functors::NoOp<false, false, false>{}));
89
90 static_assert(std::same_as<
91 stdexec::__demangle_t<sndr_then_t>,
93 stdexec::then_t,
96 >
97 >);
98
99 static_assert(stdexec::__detail::__has_nothrow_transform_sender<
101 stdexec::set_value_t,
102 sndr_then_t&&,
103 stdexec::env<>
104 >);
105
106 using sndr_then_maythrow_on_move_t =
107 decltype(stdexec::schedule(std::declval<typename ThenTest::scheduler_t>()) | stdexec::then(Tests::Utils::Functors::NoOp<false, false, true>{}));
108
109 static_assert(!stdexec::__detail::__has_nothrow_transform_sender<
110 Kokkos::Execution::GraphImpl::Domain,
111 stdexec::set_value_t,
112 sndr_then_maythrow_on_move_t&&,
113 stdexec::env<>
114 >);
115
116 return true;
117}
118static_assert(test_sndr_nothrow_transformable());
119
121consteval bool test_sndr_nothrow_connectable() {
123 static_assert(!std::is_nothrow_constructible_v<Kokkos::Experimental::Graph<TEST_EXECUTION_SPACE>>);
124
125 using sndr_then_t =
126 decltype(stdexec::schedule(std::declval<typename ThenTest::scheduler_t>()) | stdexec::then(Tests::Utils::Functors::NoOp<false, false, false>{}));
127
128 static_assert(!stdexec::__nothrow_connectable<sndr_then_t, Tests::Utils::SinkReceiver>);
129
130 return true;
131}
132static_assert(test_sndr_nothrow_connectable());
133
135consteval bool test_then_opstate_traits() {
137
138 using sndr_t =
139 decltype(stdexec::schedule(std::declval<typename ThenTest::scheduler_t>()) | stdexec::then(functor_t{}) | stdexec::then(functor_t{}));
140 using connect_result_t = stdexec::connect_result_t<sndr_t, Tests::Utils::SinkReceiver>;
141
142 static_assert(stdexec::__is_instance_of<connect_result_t, Kokkos::Execution::GraphImpl::OpState>);
143
144 using root_t = typename ThenTest::graph_t::root_t;
145 using then_A_t = Kokkos::Experimental::GraphNodeRef<
146 TEST_EXECUTION_SPACE,
147 Kokkos::Impl::GraphNodeThenImpl<TEST_EXECUTION_SPACE, Kokkos::Experimental::ThenPolicy<>, functor_t>,
148 root_t
149 >;
150 using then_B_t = Kokkos::Experimental::GraphNodeRef<
151 TEST_EXECUTION_SPACE,
152 Kokkos::Impl::GraphNodeThenImpl<TEST_EXECUTION_SPACE, Kokkos::Experimental::ThenPolicy<>, functor_t>,
153 then_A_t
154 >;
155
156 static_assert(std::same_as<typename connect_result_t::predecessor_t, root_t>);
157 static_assert(std::same_as<typename connect_result_t::node_t, then_B_t>);
158
159 return true;
160}
161static_assert(test_then_opstate_traits());
162
167TEST_F(ThenTest, then_schedule) {
168 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
169
170 const context_t gctx{exec};
171
173
174 auto sndr = stdexec::schedule(gctx.get_scheduler())
175 | stdexec::then(functor_t{.prev = 0, .value = 4, .data = data.data()})
176 | stdexec::then(functor_t{.prev = 4, .value = 3, .data = data.data()});
177
178 using sndr_t = decltype(sndr);
179
180 static_assert(std::same_as<
181 stdexec::__demangle_t<stdexec::transform_sender_result_t<sndr_t, stdexec::env<>>>,
183 TEST_EXECUTION_SPACE,
185 functor_t
186 >
187 >);
188
190 static_assert(std::same_as<stdexec::__domain_of_t<stdexec::env_of_t<sndr_t>>, stdexec::default_domain>);
191 static_assert(std::same_as<
192 stdexec::__detail::__completing_domain_t<stdexec::set_value_t, sndr_t>,
194 >);
195
197 static_assert(std::same_as<
199 typename ThenTest::scheduler_t
200 >);
201
202 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
203
204 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
205 std::move(sndr)); // NOLINT(performance-move-const-arg)
206
207 ASSERT_THAT(
208 recorded_events,
209 testing::ElementsAre(
211 MATCHER_FOR_GRAPH_ADDNODE(recorded_events.at(0), device_handle, nullptr),
213 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(1))),
214 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
216
217 ASSERT_EQ(data(), 7);
218}
219
224TEST_F(ThenTest, then_starts_on) {
225 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
226
227 const context_t gctx{exec};
228
230 auto work = stdexec::just() | THEN_INCREMENT(data);
231
234 using work_t = decltype(work);
235
238 work_t,
239 stdexec::__mset<stdexec::set_error_t(std::exception_ptr), stdexec::set_value_t()>
240 >);
241 static_assert(
242 std::same_as<stdexec::__completion_domain_of_t<stdexec::set_value_t, work_t>, stdexec::indeterminate_domain<>>);
243
245 auto sndr = stdexec::starts_on(gctx.get_scheduler(), std::move(work));
246
247 using sndr_t = decltype(sndr);
248
250 static_assert(stdexec::dependent_sender<sndr_t>);
252 static_assert(std::same_as<
254 typename ThenTest::scheduler_t
255 >);
257 sndr_t,
258 stdexec::__mset<stdexec::set_value_t(), stdexec::set_error_t(std::exception_ptr)>,
259 stdexec::env<>
260 >);
261
263 static_assert(std::same_as<
264 stdexec::__completion_domain_of_t<stdexec::set_value_t, sndr_t, stdexec::env<>>,
266 >);
267
268 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
269
270 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(std::move(sndr));
271
272 ASSERT_THAT(
273 recorded_events,
274 testing::ElementsAre(
276 MATCHER_FOR_GRAPH_ADDNODE(recorded_events.at(0), device_handle, nullptr),
277 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
279
280 ASSERT_EQ(data(), 1);
281}
282
283} // namespace Tests::GraphImpl
constexpr std::string dispatch_label(const Exec &, Label &&label)
Get the dispatch label from Exec and label.
#define MATCHER_FOR_BEGIN_FENCE(_exec_, _label_)
RecorderListener< ConjunctionMatcher< EventDiscardMatcher< TEST_EXECUTION_SPACE >, GraphEventDiscardMatcher< TEST_EXECUTION_SPACE > >, BeginFenceEvent, BeginParallelForEvent, AllocateDataEvent, DeallocateDataEvent, Kokkos::Execution::Impl::RecordEvent, Kokkos::Execution::Impl::WaitEvent, Kokkos::Execution::GraphImpl::GraphAddNodeEvent, Kokkos::Execution::GraphImpl::GraphCreateEvent, Kokkos::Execution::GraphImpl::GraphInstantiateEvent, Kokkos::Execution::GraphImpl::GraphSubmitEvent > recorder_listener_t
Definition test_then.cpp:40
Concept for a sender whose completion scheduler is Kokkos::Execution::GraphImpl::Scheduler.
Concept that constrains the type of a sender that dispatches a functor for execution.
#define THEN_INCREMENT(_data_)
Add a then using Tests::Utils::Functors::Increment that may throw. // NOLINTNEXTLINE(cppcoreguideline...
Definition increment.hpp:35
std::invoke_result_t< stdexec::get_completion_scheduler_t< Tag >, stdexec::env_of_t< Sndr >, Env... > completion_scheduler_of_t
Retrieve the completion scheduler for a given completion tag.
consteval bool test_sndr_nothrow_transformable()
Definition test_bulk.cpp:89
consteval bool test_then_opstate_traits()
consteval bool test_sndr_traits()
Definition test_bulk.cpp:57
consteval bool test_sndr_nothrow_connectable()
typename stdexec::__basic_sender< Args... >::type basic_sender_t
See https://github.com/NVIDIA/stdexec/pull/1873#discussion_r2834863237.
Definition stdexec.hpp:12
auto record_sync_wait(Sndr &&sndr)
Definition sync_wait.hpp:14
consteval bool check_continues_on_after_just_stopped()
auto get_scheduler() const noexcept -> GraphImpl::Scheduler< Exec >
Definition graph.hpp:117
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph node is added.
Definition events.hpp:33
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is created.
Definition events.hpp:14
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is instantiated.
Definition events.hpp:48
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is submitted.
Definition events.hpp:59
Sender for stdexec::then.
Definition then.hpp:50
Event to be sent to Kokkos::utils::callbacks::dispatch when calling record.
Definition event.hpp:52
Event to be sent to Kokkos::utils::callbacks::dispatch when calling wait.
Definition event.hpp:73
Similar to EventDiscardMatcher, for graph-related events.
Definition events.hpp:60
decltype(std::declval< const context_t >().get_scheduler()) scheduler_t
Definition context.hpp:28
decltype(stdexec::schedule(std::declval< scheduler_t >())) schedule_sender_t
Definition context.hpp:29
Kokkos::View< value_t, Kokkos::SharedSpace > view_s_t
Definition context.hpp:32
Load the value at data and check it is equal to prev. Then, add value to it.
#define MATCHER_FOR_GRAPH_CREATE(_device_handle_)
Definition events.hpp:16
#define MATCHER_FOR_GRAPH_SUBMIT(_exec_, _graph_create_event_variant_)
Definition events.hpp:47
#define MATCHER_FOR_GRAPH_ADDNODE(_graph_create_event_variant_, _device_handle_, _predecessor_)
Definition events.hpp:23
#define MATCHER_FOR_GRAPH_NODE_OF(_graph_add_node_event_)
Definition events.hpp:35