kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_operation_state.cpp
Go to the documentation of this file.
6
18
20
21class OpStateTest : public Tests::Utils::ExecutionSpaceContextTest<TEST_EXECUTION_SPACE> { };
22
24consteval bool test_op_state_traits() {
26 using schd_sndr_t = typename OpStateTest::schedule_sender_t;
27
30 using policy_t = Kokkos::RangePolicy<TEST_EXECUTION_SPACE>;
32
34 using rcvr_t = Tests::Utils::SinkReceiver;
35
38
41
43 static_assert(std::derived_from<op_state_t, Kokkos::Execution::Impl::Immovable>);
44 static_assert(!std::move_constructible<op_state_t>);
45 static_assert(!std::is_move_assignable_v<op_state_t>);
46
47 static_assert(!std::copy_constructible<op_state_t>);
48 static_assert(!std::is_copy_assignable_v<op_state_t>);
49
50 return true;
51}
52static_assert(test_op_state_traits());
53
58constexpr bool test_op_state_passed_by_const_ref() {
59 using sndr_t = decltype(Kokkos::Execution::parallel_for(
60 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
61 "hello from pfor",
62 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
64
65 static_assert(!std::is_const_v<sndr_t>);
66
68 using op_state_from_sndr_const_ref_t = stdexec::connect_result_t<const sndr_t&, Tests::Utils::SinkReceiver>;
69
70 static_assert(std::same_as<
71 op_state_from_sndr_const_ref_t,
73 const typename OpStateTest::schedule_sender_t&,
76 std::string,
78 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
79 >
80 >
81 >);
82
83 return true;
84}
86
88TEST_F(OpStateTest, construct_query_and_start) {
89 constexpr size_t size = 10;
90
91 const view_s_t witness(Kokkos::view_alloc(exec, "witness - shared space"));
92
93 const context_t esc{exec};
94
96 "hello from pfor", Tests::Utils::Functors::SumIndices{.data = witness}, Kokkos::RangePolicy(exec, 2, size)};
97 Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure clsr{.data = std::move(pfor_data)};
98
100 stdexec::schedule(esc.get_scheduler()), Tests::Utils::SinkReceiver{}, std::move(clsr)};
101
102 ASSERT_EQ(Kokkos::Execution::Impl::get_exec(op_state).get(), exec);
103
104 op_state.start();
105 exec.fence();
106
107 ASSERT_EQ(witness(), size / 2 * (size - 1) - 1);
108}
109
112 using sndr_t = decltype(Kokkos::Execution::parallel_for(
114 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
115 "hello from pfor",
116 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
118 "hello again from pfor",
119 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
121
122 using op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
123
125 std::string,
127 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
128 >;
130 std::string,
132 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
133 >;
134
135 static_assert(std::same_as<
136 op_state_t,
140 clsr_0_t,
141 clsr_1_t
142 >
143 >);
144
145 static_assert(!std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t>);
146
147 static_assert(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 2);
148
149 return true;
150}
151static_assert(test_op_state_flattened_from_two());
152
155 using sndr_t = decltype(Kokkos::Execution::parallel_for(
158 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
159 "hello from pfor",
160 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
162 "hello again from pfor",
163 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
165 "hello one more time from pfor",
166 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
168
169 using op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
170
172 std::string,
174 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
175 >;
177 std::string,
179 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
180 >;
182 std::string,
184 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
185 >;
186
187 static_assert(std::same_as<
188 op_state_t,
192 clsr_0_t,
193 clsr_1_t,
194 clsr_2_t
195 >
196 >);
197
198 static_assert(
199 !std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t, clsr_2_t>);
200
201 static_assert(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 3);
202
203 return true;
204}
206
209 using sndr_t = decltype(stdexec::then(
210 stdexec::bulk(
212 stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
213 "hello from pfor",
214 Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::IndexType<size_t>>(0, 10),
216 stdexec::par,
217 10,
220
221 using op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
222
224 std::string,
226 Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::IndexType<size_t>>
227 >;
229 std::string_view,
231 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
232 >;
234 std::string_view,
236 Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::LaunchBounds<1>>
237 >;
238
239 static_assert(std::same_as<
240 op_state_t,
244 clsr_0_t,
245 clsr_1_t,
246 clsr_2_t
247 >
248 >);
249
250 static_assert(
251 !std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t, clsr_2_t>);
252
253 static_assert(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 3);
254
255 return true;
256}
258
259} // namespace Tests::ExecutionSpaceImpl
A stricter variant of stdexec::operation_state.
Definition stdexec.hpp:37
constexpr get_exec_t get_exec
Definition get_exec.hpp:17
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.