kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_operation_state.cpp
Go to the documentation of this file.
5
17
19
20class OpStateTest : public Tests::Utils::ExecutionSpaceContextTest<TEST_EXECUTION_SPACE> { };
21
23consteval bool test_op_state_traits() {
25 using schd_sndr_t = typename OpStateTest::schedule_sender_t;
26
29 using policy_t = Kokkos::RangePolicy<TEST_EXECUTION_SPACE>;
31
33 using rcvr_t = Tests::Utils::SinkReceiver;
34
37
39 static_assert(stdexec::operation_state<op_state_t>);
40
42 static_assert(!std::move_constructible<op_state_t>);
43 static_assert(!std::is_move_assignable_v<op_state_t>);
44
45 static_assert(!std::copy_constructible<op_state_t>);
46 static_assert(!std::is_copy_assignable_v<op_state_t>);
47
48 return true;
49}
50static_assert(test_op_state_traits());
51
56constexpr bool test_op_state_passed_by_const_ref() {
57 using sndr_t = decltype(Kokkos::Execution::parallel_for(
58 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
59 "hello from pfor",
60 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
62
63 static_assert(!std::is_const_v<sndr_t>);
64
66 using op_state_from_sndr_const_ref_t = stdexec::connect_result_t<const sndr_t&, Tests::Utils::SinkReceiver>;
67
68 static_assert(std::same_as<
69 op_state_from_sndr_const_ref_t,
71 const typename OpStateTest::schedule_sender_t&,
74 std::string,
76 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
77 >
78 >
79 >);
80
81 return true;
82}
84
90template <stdexec::receiver Rcvr>
93 std::string_view,
95 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
96 >;
97 using opstate_t =
100 using may_delegate_completion_with_event_t =
102
103 static_assert(std::derived_from<opstate_t, opstate_base_t>);
104 static_assert(std::derived_from<opstate_base_t, may_delegate_completion_with_event_t>);
105
108 static_assert(sizeof(may_delegate_completion_with_event_t) > sizeof(Rcvr));
109 static_assert(std::same_as<
110 typename may_delegate_completion_with_event_t::receiver_t,
112 >);
113 static_assert(std::same_as<
114 typename may_delegate_completion_with_event_t::receiver_t::event_t,
116 >);
117 } else {
118 static_assert(sizeof(may_delegate_completion_with_event_t) == sizeof(Rcvr));
119 }
120
121 return true;
122}
126>());
127
129TEST_F(OpStateTest, construct_query_and_start) {
130 constexpr size_t size = 10;
131
132 const view_s_t witness(Kokkos::view_alloc(exec, "witness - shared space"));
133
134 const context_t esc{exec};
135
137 "hello from pfor", Tests::Utils::Functors::SumIndices{.data = witness}, Kokkos::RangePolicy(exec, 2, size)};
138 Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure clsr{.data = std::move(pfor_data)};
139
141 stdexec::schedule(esc.get_scheduler()), Tests::Utils::SinkReceiver{}, std::move(clsr)};
142
143 ASSERT_EQ(Kokkos::Execution::ExecutionSpaceImpl::get_exec(op_state).get(), exec);
144
145 op_state.start();
146 exec.fence();
147
148 ASSERT_EQ(witness(), size / 2 * (size - 1) - 1);
149}
150
153 using sndr_t = decltype(Kokkos::Execution::parallel_for(
155 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
156 "hello from pfor",
157 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
159 "hello again from pfor",
160 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
162
163 using op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
164
166 std::string,
168 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
169 >;
171 std::string,
173 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
174 >;
175
176 static_assert(std::same_as<
177 op_state_t,
181 clsr_0_t,
182 clsr_1_t
183 >
184 >);
185
186 static_assert(!std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t>);
187
188 static_assert(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 2);
189
190 return true;
191}
192static_assert(test_op_state_flattened_from_two());
193
196 using sndr_t = decltype(Kokkos::Execution::parallel_for(
199 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
200 "hello from pfor",
201 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
203 "hello again from pfor",
204 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
206 "hello one more time from pfor",
207 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
209
210 using op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
211
213 std::string,
215 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
216 >;
218 std::string,
220 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
221 >;
223 std::string,
225 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
226 >;
227
228 static_assert(std::same_as<
229 op_state_t,
233 clsr_0_t,
234 clsr_1_t,
235 clsr_2_t
236 >
237 >);
238
239 static_assert(
240 !std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t, clsr_2_t>);
241
242 static_assert(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 3);
243
244 return true;
245}
247
250 using sndr_t = decltype(stdexec::then(
251 stdexec::bulk(
253 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
254 "hello from pfor",
255 Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::IndexType<size_t>>(0, 10),
257 stdexec::par,
258 10,
261
262 using op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
263
265 std::string,
267 Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::IndexType<size_t>>
268 >;
270 std::string_view,
272 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
273 >;
275 std::string_view,
277 Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::LaunchBounds<1>>
278 >;
279
280 static_assert(std::same_as<
281 op_state_t,
285 clsr_0_t,
286 clsr_1_t,
287 clsr_2_t
288 >
289 >);
290
291 static_assert(
292 !std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t, clsr_2_t>);
293
294 static_assert(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 3);
295
296 return true;
297}
299
300} // namespace Tests::ExecutionSpaceImpl
The execution space supports events and the receiver is queryable for a delegation scheduler.
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_delegate_completion_with_event()
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
An event that can be recorded on an execution space instance.
Definition event.hpp:34
decltype(stdexec::schedule(std::declval< scheduler_t >())) schedule_sender_t
Definition context.hpp:27
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Definition context.hpp:25
A receiver that can handle all completions and does nothing with them.