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
86 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
87 std::move(sndr)); // NOLINT(performance-move-const-arg)
88
89 ASSERT_THAT(
90 recorded_events,
91 testing::ElementsAre(
94 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
95 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
97}
98
100TEST_F(TEST_CATEGORY(RemainsOnGraphForTest), dependent_sender_partly_on_graph_domain) {
101 experimental::execution::single_thread_context stc{};
102 const context_t gctx{exec};
103
104 stdexec::sender auto sndr = stdexec::schedule(stc.get_scheduler()) | stdexec::then(noop_t{})
105 | stdexec::continues_on(gctx.get_scheduler()) | stdexec::then(noop_t{});
106
107 using sndr_t = decltype(sndr);
108 using op_state_t = stdexec::connect_result_t<sndr_t, sync_wait_rcvr_t>;
109
111 static_assert(stdexec::dependent_sender<sndr_t>);
112
114
116
117 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
118 std::move(sndr)); // NOLINT(performance-move-const-arg)
119
120 ASSERT_THAT(
121 recorded_events,
122 testing::ElementsAre(
125 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
126 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
128}
129
135TEST_F(TEST_CATEGORY(RemainsOnGraphForTest), non_dependent_sender_with_continues_on) {
136 const context_t gctx{exec};
137
138 stdexec::sender auto sndr = stdexec::schedule(gctx.get_scheduler()) | stdexec::then(noop_t{})
139 | stdexec::continues_on(gctx.get_scheduler()) | stdexec::then(noop_t{});
140
141 using sndr_t = decltype(sndr);
142 using op_state_t = stdexec::connect_result_t<sndr_t, sync_wait_rcvr_t>;
143
146
147 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
148 std::move(sndr)); // NOLINT(performance-move-const-arg)
149
150 ASSERT_THAT(
151 recorded_events,
152 testing::ElementsAre(
155 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
158 recorded_events.at(2), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(2))),
159 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
160 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(2)),
162}
163
165TEST_F(TEST_CATEGORY(RemainsOnGraphForTest), non_dependent_sender_in_when_all) {
166 const context_t gctx{exec};
167
168 stdexec::sender auto sndr = stdexec::when_all(
169 stdexec::schedule(gctx.get_scheduler()) | stdexec::then(noop_t{}),
170 stdexec::schedule(gctx.get_scheduler()) | stdexec::then(noop_t{}));
171
172 using sndr_t = decltype(sndr);
173 using op_state_t = stdexec::connect_result_t<sndr_t, sync_wait_rcvr_t>;
174
177
178 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
179 std::move(sndr)); // NOLINT(performance-move-const-arg)
180
181 ASSERT_THAT(
182 recorded_events,
183 testing::ElementsAre(
184 MATCHER_FOR_GRAPH_CREATE(Kokkos::Experimental::get_device_handle(TEST_EXECUTION_SPACE{})),
186 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
188 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
190 recorded_events.at(0),
191 MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(1)),
192 MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(2))),
193 MATCHER_FOR_GRAPH_SUBMIT(TEST_EXECUTION_SPACE{}, recorded_events.at(0)),
194 MATCHER_FOR_BEGIN_FENCE(TEST_EXECUTION_SPACE{}, dispatch_label(TEST_EXECUTION_SPACE{}, "after dispatch"))));
195}
196
206TEST_F(TEST_CATEGORY(RemainsOnGraphForTest), non_dependent_sender_in_when_all_mixed_branches) {
207 const view_s_t data(Kokkos::view_alloc("data - shared space"));
208
209 experimental::execution::single_thread_context stc{};
210 const context_t gctx{exec};
211
212 stdexec::sender auto sndr = stdexec::when_all(
213 stdexec::schedule(gctx.get_scheduler()) | THEN_INCREMENT_ATOMIC(System, data),
214 stdexec::schedule(stc.get_scheduler()) | THEN_INCREMENT_ATOMIC(System, data)
215 | stdexec::continues_on(gctx.get_scheduler()) | THEN_INCREMENT_ATOMIC(System, data),
216 stdexec::schedule(stc.get_scheduler()) | THEN_INCREMENT_ATOMIC(System, data)
217 | stdexec::continues_on(gctx.get_scheduler()) | THEN_INCREMENT_ATOMIC(System, data));
218
219 using sndr_t = decltype(sndr);
220 using op_state_t = stdexec::connect_result_t<sndr_t, sync_wait_rcvr_t>;
221
224
225 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
226
228
229 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
230 std::move(sndr)); // NOLINT(performance-move-const-arg)
231
232 ASSERT_THAT(
233 recorded_events,
234 testing::ElementsAre(
235 MATCHER_FOR_GRAPH_CREATE(Kokkos::Experimental::get_device_handle(TEST_EXECUTION_SPACE{})),
237 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
239 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
241 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
243 recorded_events.at(0),
244 MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(1)),
245 MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(2)),
246 MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(3))),
247 MATCHER_FOR_GRAPH_SUBMIT(TEST_EXECUTION_SPACE{}, recorded_events.at(0)),
248 MATCHER_FOR_BEGIN_FENCE(TEST_EXECUTION_SPACE{}, dispatch_label(TEST_EXECUTION_SPACE{}, "after dispatch"))));
249
250 ASSERT_EQ(data(), 5);
251}
252
253} // 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_)
#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:69
#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:63
auto record_sync_wait(Sndr &&sndr)
Definition sync_wait.hpp:14
auto get_scheduler() const noexcept -> GraphImpl::Scheduler< Exec >
Definition graph.hpp:134
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph aggregate node is added.
Definition events.hpp:51
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph node is added.
Definition events.hpp:36
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is created.
Definition events.hpp:16
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is instantiated.
Definition events.hpp:66
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is submitted.
Definition events.hpp:77
Event to be sent to Kokkos::utils::callbacks::dispatch when calling record.
Definition event.hpp:54
Receiver for stdexec::sync_wait.
Definition sync_wait.hpp:46
Event to be sent to Kokkos::utils::callbacks::dispatch when calling wait.
Definition event.hpp:75
Similar to EventDiscardMatcher, for graph-related events.
Definition events.hpp:80
Kokkos::View< value_t, Kokkos::SharedSpace > view_s_t
Definition context.hpp:32
#define MATCHER_FOR_GRAPH_CREATE(_device_handle_)
Definition events.hpp:17
#define MATCHER_FOR_GRAPH_SUBMIT(_exec_, _graph_create_event_variant_)
Definition events.hpp:67
#define MATCHER_FOR_GRAPH_ADDNODE(_graph_create_event_variant_, _device_handle_, _predecessor_)
Definition events.hpp:24
#define MATCHER_FOR_GRAPH_ADD_AGGREGATE_NODE(_graph_create_event_variant_,...)
Definition events.hpp:36
#define MATCHER_FOR_GRAPH_ROOT_NODE_OF(_graph_create_event_)
Definition events.hpp:47
#define MATCHER_FOR_GRAPH_NODE_OF(_graph_add_node_event_)
Definition events.hpp:51