kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_on.cpp
Go to the documentation of this file.
3
5
12
24
25using host_execution_space = Kokkos::DefaultHostExecutionSpace;
26
28
29using namespace Kokkos::utils::callbacks;
30
43
49TEST_F(OnTest, on_same_execution_space_instance) {
50 const view_s_t data(Kokkos::view_alloc("data", exec));
51
52 const context_t esc{exec};
53
54 auto chain = stdexec::schedule(esc.get_scheduler())
56 | stdexec::on(
57 esc.get_scheduler(),
60
61 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
62
63 ASSERT_THAT(
65 testing::ElementsAre(
70
71 ASSERT_EQ(data(), 3);
72}
73
80TEST_F(OnTest, on_another_execution_space_instance_same_type) {
81 const view_s_t data(Kokkos::view_alloc("data", exec));
82
83 const auto [exec_A, exec_B] = Kokkos::Experimental::partition_space(exec, 1, 1);
84
85 const context_t esc_A{exec_A};
86 Tests::Utils::show_exec_space_id(exec_A, "exec_A");
87 const context_t esc_B{exec_B};
88 Tests::Utils::show_exec_space_id(exec_B, "exec_B");
89
90 auto chain = stdexec::schedule(esc_A.get_scheduler()) | THEN_INCREMENT(data)
91 | stdexec::on(esc_B.get_scheduler(), THEN_INCREMENT(data)) | THEN_INCREMENT(data);
92
93 static_assert(!Tests::Utils::has_completion_scheduler_for<decltype(chain), stdexec::set_value_t>);
94 static_assert(stdexec::dependent_sender<decltype(chain)>);
95 static_assert(Tests::Utils::has_completion_scheduler_for<decltype(chain), stdexec::set_value_t, stdexec::env<>>);
96
97 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
98
99 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(std::move(chain));
100
102 ASSERT_THAT(
103 recorded_events,
104 testing::ElementsAre(
107 MATCHER_FOR_WAIT_EXEC_EVENT(exec_B, recorded_events.at(1)),
110 MATCHER_FOR_WAIT_EXEC_EVENT(exec_A, recorded_events.at(4)),
112 MATCHER_FOR_BEGIN_FENCE(exec_A, dispatch_label(exec, "sync_wait"))));
113 } else {
114 if (Tests::Utils::are_same_instances(exec_A, exec_B)) {
115 ASSERT_THAT(
116 recorded_events,
117 testing::ElementsAre(
121 MATCHER_FOR_BEGIN_FENCE(exec_A, dispatch_label(exec, "sync_wait"))));
122 } else {
123 ASSERT_THAT(
124 recorded_events,
125 testing::ElementsAre(
127 MATCHER_FOR_BEGIN_FENCE(exec_A, dispatch_label(exec, "dependency")),
129 MATCHER_FOR_BEGIN_FENCE(exec_B, dispatch_label(exec, "dependency")),
131 MATCHER_FOR_BEGIN_FENCE(exec_A, dispatch_label(exec, "sync_wait"))));
132 }
133 }
134
135 ASSERT_EQ(data(), 3) << "A synchronization is missing.";
136}
137
144TEST_F(OnTest, many_execution_space_instances_of_different_type) {
145 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
146
147 const host_execution_space exec_h{};
148
150 const context_t esc{exec};
151
153 Tests::Utils::show_exec_space_id(exec_h, "exec_h");
154
155 auto chain = stdexec::schedule(esc.get_scheduler()) | THEN_INCREMENT(data)
156 | stdexec::on(esc_h.get_scheduler(), THEN_INCREMENT(data)) | THEN_INCREMENT(data);
157
158 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
159
160 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(std::move(chain));
161
163 ASSERT_THAT(
164 recorded_events,
165 testing::ElementsAre(
167 MATCHER_FOR_BEGIN_PFOR(exec_h, dispatch_label(exec_h, "then")),
170 } else if constexpr (
172 && std::same_as<host_execution_space, TEST_EXECUTION_SPACE>) {
173 ASSERT_THAT(
174 recorded_events,
175 testing::ElementsAre(
178 MATCHER_FOR_WAIT_EXEC_EVENT(exec_h, recorded_events.at(1)),
179 MATCHER_FOR_BEGIN_PFOR(exec_h, dispatch_label(exec_h, "then")),
181 MATCHER_FOR_WAIT_EXEC_EVENT(exec, recorded_events.at(4)),
184 } else {
185 ASSERT_THAT(
186 recorded_events,
187 testing::ElementsAre(
190 MATCHER_FOR_BEGIN_PFOR(exec_h, dispatch_label(exec_h, "then")),
191 MATCHER_FOR_BEGIN_FENCE(exec_h, dispatch_label(exec_h, "dependency")),
194 }
195
196 ASSERT_EQ(data(), 3) << "A synchronization is missing.";
197}
198
199} // namespace Tests::ExecutionSpaceImpl
constexpr std::string dispatch_label(const Exec &, Label &&label)
Get the dispatch label from Exec and label.
#define MATCHER_FOR_WAIT_EXEC_EVENT(_exec_, _record_event_variant_)
#define MATCHER_FOR_BEGIN_PFOR(_exec_, _label_)
#define MATCHER_FOR_RECORD_EVENT(_exec_)
#define MATCHER_FOR_BEGIN_FENCE(_exec_, _label_)
RecorderListener< EventDiscardMatcher< TEST_EXECUTION_SPACE >, BeginFenceEvent, BeginParallelForEvent, Kokkos::Execution::Impl::RecordEvent, Kokkos::Execution::Impl::WaitEvent > recorder_listener_t
Definition test_on.cpp:35
Determine if the Kokkos backend can enqueue a wait for an event into an execution space instance.
Kokkos::DefaultHostExecutionSpace host_execution_space
#define THEN_INCREMENT(_data_)
Add a then using Tests::Utils::Functors::Increment that may throw. // NOLINTNEXTLINE(cppcoreguideline...
Definition increment.hpp:59
constexpr check_scheduler_type_t< Tag, Schd > check_scheduler_type
auto record_sync_wait(Sndr &&sndr)
Definition sync_wait.hpp:14
void show_exec_space_id(const Exec &exec, std::string_view label="", std::ostream &out=std::cout)
Definition kokkos.hpp:33
bool are_same_instances(const Exec &exec, const OtherExec &other_exec)
Definition kokkos.hpp:13
Matcher to filter out events that are just noise for tests.
Execution context using a Kokkos execution space under the hood.
auto get_scheduler() const noexcept -> ExecutionSpaceImpl::Scheduler< Exec >
Event to be sent to Kokkos::utils::callbacks::dispatch when calling record.
Definition event.hpp:54
Event to be sent to Kokkos::utils::callbacks::dispatch when calling wait.
Definition event.hpp:75
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Definition context.hpp:27