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_opstate_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(
93 MATCHER_FOR_GRAPH_ADDNODE(recorded_events.at(0), device_handle, nullptr),
94 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
96}
97
99TEST_F(TEST_CATEGORY(RemainsOnGraphForTest), dependent_sender_partly_on_graph_domain) {
100 experimental::execution::single_thread_context stc{};
101 const context_t gctx{exec};
102
103 stdexec::sender auto sndr = stdexec::schedule(stc.get_scheduler()) | stdexec::then(noop_t{})
104 | stdexec::continues_on(gctx.get_scheduler()) | stdexec::then(noop_t{});
105
106 using sndr_t = decltype(sndr);
107 using opstate_t = stdexec::connect_result_t<sndr_t, sync_wait_rcvr_t>;
108
110 static_assert(stdexec::dependent_sender<sndr_t>);
111
113
115
116 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
117 std::move(sndr)); // NOLINT(performance-move-const-arg)
118
119 ASSERT_THAT(
120 recorded_events,
121 testing::ElementsAre(
123 MATCHER_FOR_GRAPH_ADDNODE(recorded_events.at(0), device_handle, nullptr),
124 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
126}
127
133TEST_F(TEST_CATEGORY(RemainsOnGraphForTest), non_dependent_sender_with_continues_on) {
134 const context_t gctx{exec};
135
136 stdexec::sender auto sndr = stdexec::schedule(gctx.get_scheduler()) | stdexec::then(noop_t{})
137 | stdexec::continues_on(gctx.get_scheduler()) | stdexec::then(noop_t{});
138
139 using sndr_t = decltype(sndr);
140 using opstate_t = stdexec::connect_result_t<sndr_t, sync_wait_rcvr_t>;
141
144
145 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
146 std::move(sndr)); // NOLINT(performance-move-const-arg)
147
148 ASSERT_THAT(
149 recorded_events,
150 testing::ElementsAre(
152 MATCHER_FOR_GRAPH_ADDNODE(recorded_events.at(0), device_handle, nullptr),
154 MATCHER_FOR_GRAPH_ADDNODE(recorded_events.at(2), device_handle, nullptr),
155 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
156 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(2)),
158}
159
161TEST_F(TEST_CATEGORY(RemainsOnGraphForTest), non_dependent_sender_in_when_all) {
162 const context_t gctx{exec};
163
164 stdexec::sender auto sndr = stdexec::when_all(
165 stdexec::schedule(gctx.get_scheduler()) | stdexec::then(noop_t{}),
166 stdexec::schedule(gctx.get_scheduler()) | stdexec::then(noop_t{}));
167
168 using sndr_t = decltype(sndr);
169 using opstate_t = stdexec::connect_result_t<sndr_t, sync_wait_rcvr_t>;
170
173
174 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
175 std::move(sndr)); // NOLINT(performance-move-const-arg)
176
177 ASSERT_THAT(
178 recorded_events,
179 testing::ElementsAre(
180 MATCHER_FOR_GRAPH_CREATE(Kokkos::Experimental::get_device_handle(TEST_EXECUTION_SPACE{})),
181 MATCHER_FOR_GRAPH_ADDNODE(recorded_events.at(0), device_handle, nullptr),
182 MATCHER_FOR_GRAPH_ADDNODE(recorded_events.at(0), device_handle, nullptr),
184 recorded_events.at(0),
185 MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(1)),
186 MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(2))),
187 MATCHER_FOR_GRAPH_SUBMIT(TEST_EXECUTION_SPACE{}, recorded_events.at(0)),
188 MATCHER_FOR_BEGIN_FENCE(TEST_EXECUTION_SPACE{}, dispatch_label(TEST_EXECUTION_SPACE{}, "after dispatch"))));
189}
190
200TEST_F(TEST_CATEGORY(RemainsOnGraphForTest), non_dependent_sender_in_when_all_mixed_branches) {
201 const view_s_t data(Kokkos::view_alloc("data - shared space"));
202
203 experimental::execution::single_thread_context stc{};
204 const context_t gctx{exec};
205
206 stdexec::sender auto sndr = stdexec::when_all(
207 stdexec::schedule(gctx.get_scheduler()) | THEN_INCREMENT_ATOMIC(System, data),
208 stdexec::schedule(stc.get_scheduler()) | THEN_INCREMENT_ATOMIC(System, data)
209 | stdexec::continues_on(gctx.get_scheduler()) | THEN_INCREMENT_ATOMIC(System, data),
210 stdexec::schedule(stc.get_scheduler()) | THEN_INCREMENT_ATOMIC(System, data)
211 | stdexec::continues_on(gctx.get_scheduler()) | THEN_INCREMENT_ATOMIC(System, data));
212
213 using sndr_t = decltype(sndr);
214 using opstate_t = stdexec::connect_result_t<sndr_t, sync_wait_rcvr_t>;
215
218
219 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
220
222
223 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
224 std::move(sndr)); // NOLINT(performance-move-const-arg)
225
226 ASSERT_THAT(
227 recorded_events,
228 testing::ElementsAre(
229 MATCHER_FOR_GRAPH_CREATE(Kokkos::Experimental::get_device_handle(TEST_EXECUTION_SPACE{})),
230 MATCHER_FOR_GRAPH_ADDNODE(recorded_events.at(0), device_handle, nullptr),
231 MATCHER_FOR_GRAPH_ADDNODE(recorded_events.at(0), device_handle, nullptr),
232 MATCHER_FOR_GRAPH_ADDNODE(recorded_events.at(0), device_handle, nullptr),
234 recorded_events.at(0),
235 MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(1)),
236 MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(2)),
237 MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(3))),
238 MATCHER_FOR_GRAPH_SUBMIT(TEST_EXECUTION_SPACE{}, recorded_events.at(0)),
239 MATCHER_FOR_BEGIN_FENCE(TEST_EXECUTION_SPACE{}, dispatch_label(TEST_EXECUTION_SPACE{}, "after dispatch"))));
240
241 ASSERT_EQ(data(), 5);
242}
243
244} // 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
Tests::Utils::Functors::NoOp< true, false, false > noop_t
Kokkos::Execution::Impl::SyncWait::Receiver< TEST_EXECUTION_SPACE, std::true_type > sync_wait_rcvr_t
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
#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:126
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph aggregate node is added.
Definition events.hpp:50
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph node is added.
Definition events.hpp:35
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:65
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is submitted.
Definition events.hpp:76
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:76
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:63
#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_NODE_OF(_graph_add_node_event_)
Definition events.hpp:47