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 TEST_EXECUTION_SPACE,
36 >;
37
39 using rcvr_t = Tests::Utils::SinkReceiver;
40
43
46
48 static_assert(std::derived_from<op_state_t, Kokkos::Execution::Impl::Immovable>);
49 static_assert(!std::move_constructible<op_state_t>);
50 static_assert(!std::is_move_assignable_v<op_state_t>);
51
52 static_assert(!std::copy_constructible<op_state_t>);
53 static_assert(!std::is_copy_assignable_v<op_state_t>);
54
55 return true;
56}
57
58static_assert(test_op_state_traits());
59
64constexpr bool test_op_state_passed_by_const_ref() {
65 using sndr_t = decltype(Kokkos::Execution::parallel_for(
66 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
67 Kokkos::Execution::label("hello from pfor"),
68 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
70
71 static_assert(!std::is_const_v<sndr_t>);
72
74 using op_state_from_sndr_const_ref_t = stdexec::connect_result_t<const sndr_t&, Tests::Utils::SinkReceiver>;
75
76 static_assert(std::same_as<
77 op_state_from_sndr_const_ref_t,
79 const typename OpStateTest::schedule_sender_t&,
82 TEST_EXECUTION_SPACE,
85 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
87 >
88 >
89 >
90 >);
91
92 return true;
93}
94
96
98TEST_F(OpStateTest, construct_query_and_start) {
99 constexpr size_t size = 10;
100
101 const view_s_t witness(Kokkos::view_alloc(exec, "witness - shared space"));
102
103 const context_t esc{exec};
104
106
108 functor_t,
109 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
111 >
112 pfor_data{{"hello from pfor"}, functor_t{.data = witness}, Kokkos::RangePolicy(exec, 2, size)};
113 Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure clsr{.state = &esc.m_state, .data = std::move(pfor_data)};
114
116 stdexec::schedule(esc.get_scheduler()), Tests::Utils::SinkReceiver{}, std::move(clsr)};
117
118 ASSERT_EQ(Kokkos::Execution::Impl::get_exec(op_state).get(), exec);
119
120 op_state.start();
121 exec.fence();
122
123 ASSERT_EQ(witness(), size / 2 * (size - 1) - 1);
124}
125
128 using sndr_t = decltype(Kokkos::Execution::parallel_for(
130 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
131 "hello from pfor",
132 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
134 "hello again from pfor",
135 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
137
138 using op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
139
141 TEST_EXECUTION_SPACE,
144 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
146 >
147 >;
149 TEST_EXECUTION_SPACE,
152 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
154 >
155 >;
156
157 static_assert(std::same_as<
158 op_state_t,
162 clsr_0_t,
163 clsr_1_t
164 >
165 >);
166
167 static_assert(!std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t>);
168
169 static_assert(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 2);
170
171 return true;
172}
173
174static_assert(test_op_state_flattened_from_two());
175
178 using sndr_t = decltype(Kokkos::Execution::parallel_for(
181 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
182 "hello from pfor",
183 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
185 "hello again from pfor",
186 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
188 "hello one more time from pfor",
189 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
191
192 using op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
193
195 TEST_EXECUTION_SPACE,
198 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
200 >
201 >;
203 TEST_EXECUTION_SPACE,
206 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
208 >
209 >;
211 TEST_EXECUTION_SPACE,
214 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
216 >
217 >;
218
219 static_assert(std::same_as<
220 op_state_t,
224 clsr_0_t,
225 clsr_1_t,
226 clsr_2_t
227 >
228 >);
229
230 static_assert(
231 !std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t, clsr_2_t>);
232
233 static_assert(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 3);
234
235 return true;
236}
237
239
242 using sndr_t = decltype(stdexec::then(
243 stdexec::bulk(
245 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
246 Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::IndexType<size_t>>(0, 10),
248 stdexec::par,
249 char(10),
252
253 using op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
254
256 TEST_EXECUTION_SPACE,
259 Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::IndexType<size_t>>
260 >
261 >;
263 TEST_EXECUTION_SPACE,
266 Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::IndexType<char>>,
268 >
269 >;
271 TEST_EXECUTION_SPACE,
272 std::string_view,
274 >;
275
276 static_assert(std::same_as<
277 op_state_t,
281 clsr_0_t,
282 clsr_1_t,
283 clsr_2_t
284 >
285 >);
286
287 static_assert(
288 !std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t, clsr_2_t>);
289
290 static_assert(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 3);
291
292 return true;
293}
294
296
297} // namespace Tests::ExecutionSpaceImpl
A stricter variant of stdexec::operation_state.
Definition stdexec.hpp:30
constexpr get_exec_t get_exec
Definition get_exec.hpp:24
consteval Impl::Label< std::string_view > label(std::string_view str) noexcept
Definition label.hpp:91
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< execution_space >
decltype(stdexec::schedule(std::declval< scheduler_t >())) schedule_sender_t
Definition context.hpp:35
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Definition context.hpp:33
A receiver that can handle all completions and does nothing with them.