kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_operation_state.cpp
Go to the documentation of this file.
2PRAGMA_DIAGNOSTIC_PUSH
4#include "exec/single_thread_context.hpp"
5PRAGMA_DIAGNOSTIC_POP
6
7#include "gtest/gtest.h"
8
12
14
23
35
36namespace Tests::GraphImpl {
37
38using namespace Kokkos::utils::callbacks;
39
63
65TEST_F(TEST_CATEGORY(RemainsOnGraphForTest), non_dependent_sender) {
66 const context_t gctx{exec};
67
68 stdexec::sender auto sndr = stdexec::schedule(gctx.get_scheduler()) | stdexec::then(noop_t{});
69
70 using sndr_t = decltype(sndr);
71
72 static_assert(!stdexec::dependent_sender<sndr_t>);
73
74 using outer_t = stdexec::connect_result_t<sndr_t, sync_wait_rcvr_t>;
75 using inner_t = typename outer_t::inner_op_state_t;
76
77 static_assert(stdexec::__is_instance_of<outer_t, Kokkos::Execution::GraphImpl::OpState>);
78 static_assert(
79 stdexec::__is_instance_of<inner_t, Kokkos::Execution::GraphImpl::Scheduler<TEST_EXECUTION_SPACE>::OpState>);
80
83
85 TEST_EXECUTION_SPACE,
86 sndr_t,
88 >);
89
90 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
91 std::move(sndr)); // NOLINT(performance-move-const-arg)
92
93 ASSERT_THAT(
94 recorded_events,
95 testing::ElementsAre(
98 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
99 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
101}
102
104TEST_F(TEST_CATEGORY(RemainsOnGraphForTest), dependent_sender_partly_on_graph_domain) {
105 experimental::execution::single_thread_context stc{};
106 const context_t gctx{exec};
107
108 stdexec::sender auto sndr = stdexec::schedule(stc.get_scheduler()) | stdexec::then(noop_t{})
109 | stdexec::continues_on(gctx.get_scheduler()) | stdexec::then(noop_t{});
110
111 using sndr_t = decltype(sndr);
112 using op_state_t = stdexec::connect_result_t<sndr_t, sync_wait_rcvr_t>;
113
115 static_assert(stdexec::dependent_sender<sndr_t>);
116
118 TEST_EXECUTION_SPACE,
119 sndr_t,
121 >);
122
124
125 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
126 std::move(sndr)); // NOLINT(performance-move-const-arg)
127
128 ASSERT_THAT(
129 recorded_events,
130 testing::ElementsAre(
133 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
134 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
136}
137
143TEST_F(TEST_CATEGORY(RemainsOnGraphForTest), non_dependent_sender_with_continues_on) {
144 const context_t gctx{exec};
145
146 stdexec::sender auto sndr = stdexec::schedule(gctx.get_scheduler()) | stdexec::then(noop_t{})
147 | stdexec::continues_on(gctx.get_scheduler()) | stdexec::then(noop_t{});
148
149 using sndr_t = decltype(sndr);
150 using op_state_t = stdexec::connect_result_t<sndr_t, sync_wait_rcvr_t>;
151
154 TEST_EXECUTION_SPACE,
155 sndr_t,
157 >);
158
159 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
160 std::move(sndr)); // NOLINT(performance-move-const-arg)
161
162 ASSERT_THAT(
163 recorded_events,
164 testing::ElementsAre(
167 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
170 recorded_events.at(2), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(2))),
171 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
172 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(2)),
174}
175
177TEST_F(TEST_CATEGORY(RemainsOnGraphForTest), non_dependent_sender_in_when_all) {
178 const context_t gctx{exec};
179
180 stdexec::sender auto sndr = stdexec::when_all(
181 stdexec::schedule(gctx.get_scheduler()) | stdexec::then(noop_t{}),
182 stdexec::schedule(gctx.get_scheduler()) | stdexec::then(noop_t{}));
183
184 using sndr_t = decltype(sndr);
185 using op_state_t = stdexec::connect_result_t<sndr_t, sync_wait_rcvr_t>;
186
189 TEST_EXECUTION_SPACE,
190 sndr_t,
192 >);
193
194 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
195 std::move(sndr)); // NOLINT(performance-move-const-arg)
196
197 ASSERT_THAT(
198 recorded_events,
199 testing::ElementsAre(
200 MATCHER_FOR_GRAPH_CREATE(Kokkos::Experimental::get_device_handle(TEST_EXECUTION_SPACE{})),
202 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
204 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
206 recorded_events.at(0),
207 MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(1)),
208 MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(2))),
209 MATCHER_FOR_GRAPH_SUBMIT(TEST_EXECUTION_SPACE{}, recorded_events.at(0)),
210 MATCHER_FOR_BEGIN_FENCE(TEST_EXECUTION_SPACE{}, dispatch_label(TEST_EXECUTION_SPACE{}, "after dispatch"))));
211}
212
222TEST_F(TEST_CATEGORY(RemainsOnGraphForTest), non_dependent_sender_in_when_all_mixed_branches) {
223 const view_s_t data(Kokkos::view_alloc("data - shared space"));
224
225 experimental::execution::single_thread_context stc{};
226 const context_t gctx{exec};
227
228 stdexec::sender auto sndr = stdexec::when_all(
229 stdexec::schedule(gctx.get_scheduler()) | THEN_INCREMENT_ATOMIC(System, data),
230 stdexec::schedule(stc.get_scheduler()) | THEN_INCREMENT_ATOMIC(System, data)
231 | stdexec::continues_on(gctx.get_scheduler()) | THEN_INCREMENT_ATOMIC(System, data),
232 stdexec::schedule(stc.get_scheduler()) | THEN_INCREMENT_ATOMIC(System, data)
233 | stdexec::continues_on(gctx.get_scheduler()) | THEN_INCREMENT_ATOMIC(System, data));
234
235 using sndr_t = decltype(sndr);
236 using op_state_t = stdexec::connect_result_t<sndr_t, sync_wait_rcvr_t>;
237
240 TEST_EXECUTION_SPACE,
241 sndr_t,
243 >);
244
245 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
246
248
249 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
250 std::move(sndr)); // NOLINT(performance-move-const-arg)
251
252 ASSERT_THAT(
253 recorded_events,
254 testing::ElementsAre(
255 MATCHER_FOR_GRAPH_CREATE(Kokkos::Experimental::get_device_handle(TEST_EXECUTION_SPACE{})),
257 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
259 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
261 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
263 recorded_events.at(0),
264 MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(1)),
265 MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(2)),
266 MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(3))),
267 MATCHER_FOR_GRAPH_SUBMIT(TEST_EXECUTION_SPACE{}, recorded_events.at(0)),
268 MATCHER_FOR_BEGIN_FENCE(TEST_EXECUTION_SPACE{}, dispatch_label(TEST_EXECUTION_SPACE{}, "after dispatch"))));
269
270 ASSERT_EQ(data(), 5);
271}
272
273} // namespace Tests::GraphImpl
constexpr std::string dispatch_label(const Exec &, const std::string_view label)
Get the dispatch label from Exec and label.
#define MATCHER_FOR_BEGIN_FENCE(_exec_, _label_)
#define TEST_CATEGORY(_name_)
Definition category.hpp:10
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::GraphAddAggregateNodeEvent, Kokkos::Execution::GraphImpl::GraphAddNodeEvent, Kokkos::Execution::GraphImpl::GraphCreateEvent, Kokkos::Execution::GraphImpl::GraphInstantiateEvent, Kokkos::Execution::GraphImpl::GraphSubmitEvent > recorder_listener_t
Tests::Utils::Functors::NoOp< true, false, false > noop_t
Kokkos::Execution::Impl::SyncWait::Receiver< TEST_EXECUTION_SPACE, std::true_type > sync_wait_rcvr_t
#define KOKKOS_EXECUTION_THREADS_THROWS_ON_SYNC_WAIT_ASSERT_AND_SKIP(_sndr_)
Definition context.hpp:76
#define KOKKOS_EXECUTION_STDEXEC_PRAGMA_DIAGNOSTIC_IGNORED
Basic list of ignored diagnostics when including anything from stdexec.
#define THEN_INCREMENT_ATOMIC(_scope_, _data_)
Same as THEN_INCREMENT, using Tests::Utils::atomic_fetch_add. // NOLINTNEXTLINE(cppcoreguidelines-mac...
Definition increment.hpp:68
auto record_sync_wait(Sndr &&sndr)
Definition sync_wait.hpp:14
auto get_scheduler() const noexcept -> GraphImpl::Scheduler< execution_space >
Definition graph.hpp:134
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph aggregate node is added.
Definition events.hpp:68
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph node is added.
Definition events.hpp:49
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is created.
Definition events.hpp:28
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is instantiated.
Definition events.hpp:85
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is submitted.
Definition events.hpp:98
Event to be sent to Kokkos::utils::callbacks::dispatch when calling record.
Definition event.hpp:59
Receiver for stdexec::sync_wait.
Definition sync_wait.hpp:45
Event to be sent to Kokkos::utils::callbacks::dispatch when calling wait.
Definition event.hpp:80
Similar to EventDiscardMatcher, for graph-related events.
Definition events.hpp:83
Kokkos::View< value_t, Kokkos::SharedSpace > view_s_t
Definition context.hpp:38
#define MATCHER_FOR_GRAPH_CREATE(_device_handle_)
Definition events.hpp:17
#define MATCHER_FOR_GRAPH_ADDNODE(_graph_create_event_variant_, _device_handle_, _predecessor_,...)
Definition events.hpp:24
#define MATCHER_FOR_GRAPH_SUBMIT(_exec_, _graph_create_event_variant_)
Definition events.hpp:71
#define MATCHER_FOR_GRAPH_ADD_AGGREGATE_NODE(_graph_create_event_variant_,...)
Definition events.hpp:40
#define MATCHER_FOR_GRAPH_ROOT_NODE_OF(_graph_create_event_)
Definition events.hpp:51
#define MATCHER_FOR_GRAPH_NODE_OF(_graph_add_node_event_)
Definition events.hpp:55