kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_operation_state.cpp
Go to the documentation of this file.
2
8
20
22
23class OpStateTest : public Tests::Utils::ExecutionSpaceContextTest<TEST_EXECUTION_SPACE> { };
24
26consteval bool test_op_state_traits() {
28 using schd_sndr_t = typename OpStateTest::schedule_sender_t;
29
32 using policy_t = Kokkos::RangePolicy<TEST_EXECUTION_SPACE>;
34
36 using rcvr_t = Tests::Utils::SinkReceiver;
37
40
43
45 static_assert(std::derived_from<op_state_t, Kokkos::Execution::Impl::Immovable>);
46 static_assert(!std::move_constructible<op_state_t>);
47 static_assert(!std::is_move_assignable_v<op_state_t>);
48
49 static_assert(!std::copy_constructible<op_state_t>);
50 static_assert(!std::is_copy_assignable_v<op_state_t>);
51
52 return true;
53}
54static_assert(test_op_state_traits());
55
60constexpr bool test_op_state_passed_by_const_ref() {
61 using sndr_t = decltype(Kokkos::Execution::parallel_for(
62 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
63 "hello from pfor",
64 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
66
67 static_assert(!std::is_const_v<sndr_t>);
68
70 using op_state_from_sndr_const_ref_t = stdexec::connect_result_t<const sndr_t&, Tests::Utils::SinkReceiver>;
71
72 static_assert(std::same_as<
73 op_state_from_sndr_const_ref_t,
75 const typename OpStateTest::schedule_sender_t&,
78 std::string,
80 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
81 >
82 >
83 >);
84
85 return true;
86}
88
90TEST_F(OpStateTest, construct_query_and_start) {
91 constexpr size_t size = 10;
92
93 const view_s_t witness(Kokkos::view_alloc(exec, "witness - shared space"));
94
95 const context_t esc{exec};
96
98 "hello from pfor", Tests::Utils::Functors::SumIndices{.data = witness}, Kokkos::RangePolicy(exec, 2, size)};
99 Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure clsr{.data = std::move(pfor_data)};
100
102 stdexec::schedule(esc.get_scheduler()), Tests::Utils::SinkReceiver{}, std::move(clsr)};
103
104 ASSERT_EQ(Kokkos::Execution::Impl::get_exec(op_state).get(), exec);
105
106 op_state.start();
107 exec.fence();
108
109 ASSERT_EQ(witness(), size / 2 * (size - 1) - 1);
110}
111
114 using sndr_t = decltype(Kokkos::Execution::parallel_for(
116 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
117 "hello from pfor",
118 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
120 "hello again from pfor",
121 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
123
124 using op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
125
127 std::string,
129 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
130 >;
132 std::string,
134 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
135 >;
136
137 static_assert(std::same_as<
138 op_state_t,
142 clsr_0_t,
143 clsr_1_t
144 >
145 >);
146
147 static_assert(!std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t>);
148
149 static_assert(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 2);
150
151 return true;
152}
153static_assert(test_op_state_flattened_from_two());
154
157 using sndr_t = decltype(Kokkos::Execution::parallel_for(
160 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
161 "hello from pfor",
162 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
164 "hello again from pfor",
165 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
167 "hello one more time from pfor",
168 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
170
171 using op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
172
174 std::string,
176 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
177 >;
179 std::string,
181 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
182 >;
184 std::string,
186 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
187 >;
188
189 static_assert(std::same_as<
190 op_state_t,
194 clsr_0_t,
195 clsr_1_t,
196 clsr_2_t
197 >
198 >);
199
200 static_assert(
201 !std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t, clsr_2_t>);
202
203 static_assert(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 3);
204
205 return true;
206}
208
211 using sndr_t = decltype(stdexec::then(
212 stdexec::bulk(
214 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
215 "hello from pfor",
216 Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::IndexType<size_t>>(0, 10),
218 stdexec::par,
219 10,
222
223 using op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
224
226 std::string,
228 Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::IndexType<size_t>>
229 >;
231 std::string_view,
233 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
234 >;
236 std::string_view,
238 Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::LaunchBounds<1>>
239 >;
240
241 static_assert(std::same_as<
242 op_state_t,
246 clsr_0_t,
247 clsr_1_t,
248 clsr_2_t
249 >
250 >);
251
252 static_assert(
253 !std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t, clsr_2_t>);
254
255 static_assert(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 3);
256
257 return true;
258}
260
261} // namespace Tests::ExecutionSpaceImpl
A stricter variant of stdexec::operation_state.
Definition stdexec.hpp:37
constexpr get_exec_t get_exec
Definition get_exec.hpp:19
constexpr parallel_for_t parallel_for
consteval bool test_op_state_flattened_from_three()
constexpr bool test_op_state_passed_by_const_ref()
consteval bool test_op_state_flattened_from_two()
consteval bool test_op_state_flattened_from_three_mixed_tags()
auto get_scheduler() const noexcept -> ExecutionSpaceImpl::Scheduler< Exec >
Inspired by https://github.com/kokkos/kokkos/blob/69273c3a4e7b6adeb95066341ca201d62fe1e698/core/src/i...
Definition then.hpp:16
decltype(stdexec::schedule(std::declval< scheduler_t >())) schedule_sender_t
Definition context.hpp:29
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Definition context.hpp:27
A receiver that can handle all completions and does nothing with them.