kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_parallel_for.cpp
Go to the documentation of this file.
4
7
20
31
32namespace Tests::GraphImpl {
33
34using namespace Kokkos::utils::callbacks;
35
54
59template <
60 template <typename...> class SndrAdptr,
61 bool ExptIsDispatchingSender,
62 template <typename> typename ExptTransformSenderType
63>
64consteval bool test_sndr_traits() {
66 using schd_sndr_t = typename TEST_CATEGORY(ParallelForTest)::schedule_sender_t;
67
69 using label_t = std::string;
70 using functor_t = Tests::Utils::Functors::SumIndices<typename TEST_CATEGORY(ParallelForTest)::view_s_t>;
71 using policy_t = Kokkos::RangePolicy<TEST_EXECUTION_SPACE>;
72 using pfor_sndr_t = SndrAdptr<schd_sndr_t, TEST_EXECUTION_SPACE, label_t, functor_t, policy_t>;
73
76
78 static_assert(Kokkos::Execution::Impl::dispatching_sender<pfor_sndr_t> == ExptIsDispatchingSender);
79
81 static_assert(!stdexec::dependent_sender<pfor_sndr_t>);
82 static_assert(
83 stdexec::get_completion_signatures<pfor_sndr_t>()
84 == stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_error_t(std::exception_ptr)>{});
85
87 static_assert(std::same_as<
88 stdexec::__completion_domain_of_t<stdexec::set_value_t, pfor_sndr_t, stdexec::env<>>,
90 >);
91
93 static_assert(std::same_as<
96 >);
97
99 static_assert(stdexec::sender_to<pfor_sndr_t, Tests::Utils::SinkReceiver>);
100
101 static_assert(std::same_as<
102 stdexec::transform_sender_result_t<pfor_sndr_t, stdexec::env_of_t<Tests::Utils::SinkReceiver>>,
103 typename ExptTransformSenderType<Kokkos::Execution::GraphImpl::ParallelForSender< // NOLINT(modernize-type-traits)
104 schd_sndr_t,
106 functor_t,
107 policy_t
108 >>::type
109 >);
110
112 static_assert(!stdexec::__nothrow_connectable<pfor_sndr_t, Tests::Utils::SinkReceiver>);
113
114 return true;
115}
116
117template <typename Sndr, typename Exec, typename Label, typename Functor, typename Policy>
119 Sndr,
121>;
122
123template <typename Sndr, typename Exec, typename Label, typename Functor, typename Policy>
125 Sndr,
127 Functor,
128 Policy
129>;
130
133
135template <typename ViewType>
136consteval bool test_closure_traits() {
138 using policy_t = Kokkos::RangePolicy<TEST_EXECUTION_SPACE>;
139 using iter_space_t = Kokkos::dims<1, int>;
142 functor_t,
143 policy_t
144 >;
145 using closure_iter_space_t = Kokkos::Execution::GraphImpl::ParallelForClosure<
147 functor_t,
148 iter_space_t
149 >;
150
154
155 static_assert(std::is_nothrow_move_constructible_v<closure_policy_t>);
156 static_assert(std::is_nothrow_move_constructible_v<closure_iter_space_t>);
157
158 return true;
159}
160
161static_assert(test_closure_traits<typename TEST_CATEGORY(ParallelForTest)::view_s_t>());
162static_assert(test_closure_traits<std::span<int>>());
163
166 typename TEST_CATEGORY(ParallelForTest)::scheduler_t,
167 Kokkos::Execution::parallel_for_t,
168 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
169 Tests::Utils::Functors::NoOp<false, false, false>
170>());
171
176TEST_F(TEST_CATEGORY(ParallelForTest), parallel_for_schedule) {
177 constexpr size_t size = 10;
178
179 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
180
181 const context_t gctx{exec};
182
183 auto sndr =
184 stdexec::schedule(gctx.get_scheduler())
186 std::format("{}: hello from pfor", Kokkos::Execution::Impl::display_string_of<TEST_EXECUTION_SPACE>()),
187 size,
189
190 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(std::move(sndr));
191
192 ASSERT_THAT(
193 recorded_events,
194 testing::ElementsAre(
197 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
198 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
200
201 ASSERT_EQ(data(), size / 2 * (size - 1));
202}
203
205TEST_F(TEST_CATEGORY(ParallelForTest), parallel_for_starts_on) {
206 constexpr size_t size = 10;
207
208 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
209
210 auto chain =
211 stdexec::just()
213 std::format("{}: hello from pfor", Kokkos::Execution::Impl::display_string_of<TEST_EXECUTION_SPACE>()),
214 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, size),
216
217 using chain_t = decltype(chain);
218
219 static_assert(
220 stdexec::get_completion_signatures<chain_t>()
221 == stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_error_t(std::exception_ptr)>{});
223 static_assert(
224 std::same_as<stdexec::__completion_domain_of_t<stdexec::set_value_t, chain_t>, stdexec::indeterminate_domain<>>);
225
226 const context_t gctx{exec};
227 auto starts_on = stdexec::starts_on(gctx.get_scheduler(), std::move(chain));
228
229 using starts_on_t = decltype(starts_on);
230
231 static_assert(stdexec::__has_eptr_completion<chain_t>);
232 static_assert(!stdexec::dependent_sender<starts_on_t>);
233 static_assert(
234 stdexec::get_completion_signatures<starts_on_t>()
235 == stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_error_t(std::exception_ptr)>{});
236
237 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(std::move(starts_on));
238
239 ASSERT_THAT(recorded_events, testing::SizeIs(4));
240
241 ASSERT_THAT(
242 recorded_events,
243 testing::ElementsAre(
246 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
247 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
248 MATCHER_FOR_BEGIN_FENCE(exec, dispatch_label(exec, "after dispatch"))));
249
250 ASSERT_EQ(data(), size / 2 * (size - 1));
251}
252
254TEST_F(TEST_CATEGORY(ParallelForTest), with_range_slice) {
255 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
256
257 const context_t gctx{exec};
258
260
261 using expt_node_t = Kokkos::Experimental::GraphNodeRef<
262 TEST_EXECUTION_SPACE,
263 Kokkos::Impl::GraphNodeKernelImpl<
264 TEST_EXECUTION_SPACE,
265 Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::Impl::IsGraphKernelTag>,
266 functor_t,
267 Kokkos::ParallelForTag
268 >,
269 Kokkos::Experimental::GraphNodeRef<TEST_EXECUTION_SPACE, Kokkos::Experimental::GraphNodeRootTag>
270 >;
271
272 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
273 stdexec::schedule(gctx.get_scheduler())
274 | Kokkos::Execution::parallel_for(Kokkos::range_slice<size_t, size_t>{3, 5}, functor_t{.data = data})
276
277 ASSERT_THAT(
278 recorded_events,
279 testing::ElementsAre(
282 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
283 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
285
286 ASSERT_EQ(data(), 3 + 4);
287}
288
290TEST_F(TEST_CATEGORY(ParallelForTest), parallel_for_schedule_tagged_operator) {
291 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
292
293 const context_t gctx{exec};
294
296
297 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
298 stdexec::schedule(gctx.get_scheduler())
300 Kokkos::RangePolicy<typename functor_t::Tag, TEST_EXECUTION_SPACE>(0, 1), functor_t{.data = data}));
301
302 ASSERT_THAT(
303 recorded_events,
304 testing::ElementsAre(
307 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
308 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
310
311 ASSERT_EQ(data(), 1);
312}
313
314} // namespace Tests::GraphImpl
constexpr std::string dispatch_label(const Exec &, const std::string_view label)
Get the dispatch label from Exec and label.
#define MATCHER_FOR_BEGIN_FENCE(_exec_, _label_)
#define TEST_CATEGORY(_name_)
Definition category.hpp:10
RecorderListener< ConjunctionMatcher< EventDiscardMatcher< TEST_EXECUTION_SPACE >, GraphEventDiscardMatcher< TEST_EXECUTION_SPACE > >, BeginFenceEvent, BeginParallelForEvent, AllocateDataEvent, DeallocateDataEvent, Kokkos::Execution::Impl::RecordEvent, Kokkos::Execution::Impl::WaitEvent, Kokkos::Execution::GraphImpl::GraphAddNodeEvent, Kokkos::Execution::GraphImpl::GraphCreateEvent, Kokkos::Execution::GraphImpl::GraphInstantiateEvent, Kokkos::Execution::GraphImpl::GraphSubmitEvent > recorder_listener_t
Concept for a sender whose completion scheduler is Kokkos::Execution::GraphImpl::Scheduler.
Concept that constrains the type of a sender that dispatches a functor for execution.
typename Kokkos::Impl::NodeCtorProps< Kokkos::Impl::DeviceHandle< Exec >, Label >::uniform_type node_props_t
std::invoke_result_t< stdexec::get_completion_scheduler_t< Tag >, stdexec::env_of_t< Sndr >, Env... > completion_scheduler_of_t
Retrieve the completion scheduler for a given completion tag.
constexpr auto display_string_of() noexcept -> std::string_view
Definition type_info.hpp:20
constexpr parallel_for_t parallel_for
Kokkos::Execution::Impl::ParallelForSender< Sndr, Kokkos::Execution::Impl::ParallelForData< Functor, Policy, Kokkos::Execution::Impl::Label< Label > > > pfor_generic_t
consteval bool test_closure_traits()
Kokkos::Execution::GraphImpl::ParallelForSender< Sndr, Kokkos::Execution::GraphImpl::node_props_t< Exec, Label >, Functor, Policy > pfor_impl_t
consteval bool test_sndr_traits()
Definition test_bulk.cpp:57
constexpr check_node_type_t< NodeType > check_node_type
The provided type NodeType is compared without cv type qualifiers during connect.
auto record_sync_wait(Sndr &&sndr)
Definition sync_wait.hpp:14
consteval bool check_continues_on_after_just_stopped()
Tests::Utils::Functors::NoOp< false, false, false > NoOp
auto get_scheduler() const noexcept -> GraphImpl::Scheduler< execution_space >
Definition graph.hpp:134
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph node is added.
Definition events.hpp:49
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is created.
Definition events.hpp:28
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is instantiated.
Definition events.hpp:85
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is submitted.
Definition events.hpp:98
Scheduler for a Kokkos::Experimental::Graph.
Definition graph.hpp:30
Event to be sent to Kokkos::utils::callbacks::dispatch when calling record.
Definition event.hpp:59
Event to be sent to Kokkos::utils::callbacks::dispatch when calling wait.
Definition event.hpp:80
Similar to EventDiscardMatcher, for graph-related events.
Definition events.hpp:83
Kokkos::View< value_t, Kokkos::SharedSpace > view_s_t
Definition context.hpp:38
#define MATCHER_FOR_GRAPH_CREATE(_device_handle_)
Definition events.hpp:17
#define MATCHER_FOR_GRAPH_ADDNODE(_graph_create_event_variant_, _device_handle_, _predecessor_,...)
Definition events.hpp:24
#define MATCHER_FOR_GRAPH_SUBMIT(_exec_, _graph_create_event_variant_)
Definition events.hpp:71
#define MATCHER_FOR_GRAPH_ROOT_NODE_OF(_graph_create_event_)
Definition events.hpp:51