kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_on.cpp
Go to the documentation of this file.
3
10
22
23using host_execution_space = Kokkos::DefaultHostExecutionSpace;
24
26
27using namespace Kokkos::utils::callbacks;
28
41
47TEST_F(OnTest, on_same_execution_space_instance) {
48 const view_s_t data(Kokkos::view_alloc("data", exec));
49
50 const context_t esc{exec};
51
52 auto chain = stdexec::schedule(esc.get_scheduler())
54 | stdexec::on(
55 esc.get_scheduler(),
58
59 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
60
61 ASSERT_THAT(
63 testing::ElementsAre(
68
69 ASSERT_EQ(data(), 3);
70}
71
78TEST_F(OnTest, on_another_execution_space_instance_same_type) {
79 const view_s_t data(Kokkos::view_alloc("data", exec));
80
81 const auto [exec_A, exec_B] = Kokkos::Experimental::partition_space(exec, 1, 1);
82
83 const context_t esc_A{exec_A};
84 Tests::Utils::show_exec_space_id(exec_A, "exec_A");
85 const context_t esc_B{exec_B};
86 Tests::Utils::show_exec_space_id(exec_B, "exec_B");
87
88 auto chain = stdexec::schedule(esc_A.get_scheduler()) | THEN_INCREMENT(data)
89 | stdexec::on(esc_B.get_scheduler(), THEN_INCREMENT(data)) | THEN_INCREMENT(data);
90
91 static_assert(!Tests::Utils::has_completion_scheduler_for<decltype(chain), stdexec::set_value_t>);
92 static_assert(stdexec::dependent_sender<decltype(chain)>);
93 static_assert(Tests::Utils::has_completion_scheduler_for<decltype(chain), stdexec::set_value_t, stdexec::env<>>);
94
95 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
96
97 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(std::move(chain));
98
99 if (Tests::Utils::are_same_instances(exec_A, exec_B)) {
100 ASSERT_THAT(
101 recorded_events,
102 testing::ElementsAre(
106 MATCHER_FOR_BEGIN_FENCE(exec_A, dispatch_label(exec, "sync_wait"))));
107 } else {
108 ASSERT_THAT(
109 recorded_events,
110 testing::ElementsAre(
112 MATCHER_FOR_BEGIN_FENCE(exec_A, dispatch_label(exec, "schedule_from")),
114 MATCHER_FOR_BEGIN_FENCE(exec_B, dispatch_label(exec, "schedule_from")),
116 MATCHER_FOR_BEGIN_FENCE(exec_A, dispatch_label(exec, "sync_wait"))));
117 }
118
119 ASSERT_EQ(data(), 3) << "A synchronization is missing.";
120}
121
128TEST_F(OnTest, many_execution_space_instances_of_different_type) {
129 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
130
131 const host_execution_space exec_h{};
132
134 const context_t esc{exec};
135
137 Tests::Utils::show_exec_space_id(exec_h, "exec_h");
138
139 auto chain = stdexec::schedule(esc.get_scheduler()) | THEN_INCREMENT(data)
140 | stdexec::on(esc_h.get_scheduler(), THEN_INCREMENT(data)) | THEN_INCREMENT(data);
141
142 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
143
144 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(std::move(chain));
145
147 ASSERT_THAT(
148 recorded_events,
149 testing::ElementsAre(
151 MATCHER_FOR_BEGIN_PFOR(exec_h, dispatch_label(exec_h, "then")),
154 } else {
155 ASSERT_THAT(
156 recorded_events,
157 testing::ElementsAre(
160 MATCHER_FOR_BEGIN_PFOR(exec_h, dispatch_label(exec_h, "then")),
161 MATCHER_FOR_BEGIN_FENCE(exec_h, dispatch_label(exec_h, "schedule_from")),
164 }
165
166 ASSERT_EQ(data(), 3) << "A synchronization is missing.";
167}
168
169} // namespace Tests::ExecutionSpaceImpl
constexpr std::string dispatch_label(const Exec &, Label &&label)
Get the dispatch label from Exec and label.
#define MATCHER_FOR_BEGIN_PFOR(_exec_, _label_)
#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:33
#define THEN_INCREMENT(_data_)
Add a then using Tests::Utils::Functors::Increment that may throw. // NOLINTNEXTLINE(cppcoreguideline...
Definition increment.hpp:35
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:52
Event to be sent to Kokkos::utils::callbacks::dispatch when calling wait.
Definition event.hpp:73
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Definition context.hpp:27
Kokkos::DefaultHostExecutionSpace host_execution_space