kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_on.cpp
Go to the documentation of this file.
3
9
21
22using host_execution_space = Kokkos::DefaultHostExecutionSpace;
23
25
26using namespace Kokkos::utils::callbacks;
27
35
41TEST_F(OnTest, on_same_execution_space_instance) {
42 const view_s_t data(Kokkos::view_alloc("data", exec));
43
44 const context_t esc{exec};
45
46 auto chain = stdexec::schedule(esc.get_scheduler())
48 | stdexec::on(
49 esc.get_scheduler(),
52
53 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
54
55 ASSERT_THAT(
56 recorder_listener_t::record([chain = std::move(chain)]() mutable { stdexec::sync_wait(std::move(chain)); }),
57 testing::ElementsAre(
62
63 ASSERT_EQ(data(), 3);
64}
65
72TEST_F(OnTest, on_another_execution_space_instance_same_type) {
73 const view_s_t data(Kokkos::view_alloc("data", exec));
74
75 const auto [exec_A, exec_B] = Kokkos::Experimental::partition_space(exec, 1, 1);
76
77 const context_t esc_A{exec_A};
78 Tests::Utils::show_exec_space_id(exec_A, "exec_A");
79 const context_t esc_B{exec_B};
80 Tests::Utils::show_exec_space_id(exec_B, "exec_B");
81
82 auto chain = stdexec::schedule(esc_A.get_scheduler()) | THEN_INCREMENT(data)
83 | stdexec::on(esc_B.get_scheduler(), THEN_INCREMENT(data)) | THEN_INCREMENT(data);
84
85 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
86
87 const auto recorded_events = recorder_listener_t::record(
88 [chain = std::move(chain)]() mutable { stdexec::sync_wait(std::move(chain)); });
89
90 if (Tests::Utils::are_same_instances(exec_A, exec_B)) {
91 ASSERT_THAT(
92 recorded_events,
93 testing::ElementsAre(
97 MATCHER_FOR_BEGIN_FENCE(exec_A, dispatch_label(exec, "sync_wait"))));
98 } else {
99 ASSERT_THAT(
100 recorded_events,
101 testing::ElementsAre(
103 MATCHER_FOR_BEGIN_FENCE(exec_A, dispatch_label(exec, "schedule_from")),
105 MATCHER_FOR_BEGIN_FENCE(exec_B, dispatch_label(exec, "schedule_from")),
107 MATCHER_FOR_BEGIN_FENCE(exec_A, dispatch_label(exec, "sync_wait"))));
108 }
109
110 ASSERT_EQ(data(), 3) << "A synchronization is missing.";
111}
112
119TEST_F(OnTest, many_execution_space_instances_of_different_type) {
120 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
121
122 const host_execution_space exec_h{};
123
125 const context_t esc{exec};
126
128 Tests::Utils::show_exec_space_id(exec_h, "exec_h");
129
130 auto chain = stdexec::schedule(esc.get_scheduler()) | THEN_INCREMENT(data)
131 | stdexec::on(esc_h.get_scheduler(), THEN_INCREMENT(data)) | THEN_INCREMENT(data);
132
133 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
134
135 const auto recorded_events = recorder_listener_t::record(
136 [chain = std::move(chain)]() mutable { stdexec::sync_wait(std::move(chain)); });
137
139 ASSERT_THAT(
140 recorded_events,
141 testing::ElementsAre(
143 MATCHER_FOR_BEGIN_PFOR(exec_h, dispatch_label(exec_h, "then")),
146 } else {
147 ASSERT_THAT(
148 recorded_events,
149 testing::ElementsAre(
152 MATCHER_FOR_BEGIN_PFOR(exec_h, dispatch_label(exec_h, "then")),
153 MATCHER_FOR_BEGIN_FENCE(exec_h, dispatch_label(exec_h, "schedule_from")),
156 }
157
158 ASSERT_EQ(data(), 3) << "A synchronization is missing.";
159}
160
161} // 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 > recorder_listener_t
Definition test_on.cpp:32
#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
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
Execution context using a Kokkos execution space under the hood.
auto get_scheduler() const noexcept -> ExecutionSpaceImpl::Scheduler< Exec >
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Definition context.hpp:25
Kokkos::DefaultHostExecutionSpace host_execution_space