kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_parallel_for.cpp
Go to the documentation of this file.
4
7
18
29
30namespace Tests::GraphImpl {
31
32using namespace Kokkos::utils::callbacks;
33
53
58template <template <typename...> class SndrAdptr, bool IsDispatchingSender, typename... Args>
59consteval bool test_sndr_traits() {
61 using schd_sndr_t = typename ParallelForTest::schedule_sender_t;
62
64 using label_t = std::string;
66 using policy_t = Kokkos::RangePolicy<TEST_EXECUTION_SPACE>;
67 using pfor_sndr_t = SndrAdptr<schd_sndr_t, label_t, functor_t, policy_t>;
68
71
73 static_assert(Kokkos::Execution::Impl::dispatching_sender<pfor_sndr_t> == IsDispatchingSender);
74
76 static_assert(!stdexec::dependent_sender<pfor_sndr_t>);
77 static_assert(
78 stdexec::get_completion_signatures<pfor_sndr_t>()
79 == stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_error_t(std::exception_ptr)>{});
80
82 static_assert(std::same_as<
83 stdexec::__completion_domain_of_t<stdexec::set_value_t, pfor_sndr_t, stdexec::env<>>,
85 >);
86
88 static_assert(std::same_as<
91 >);
92
94 static_assert(stdexec::sender_to<pfor_sndr_t, Tests::Utils::SinkReceiver>);
95
96 static_assert(std::same_as<
97 stdexec::transform_sender_result_t<pfor_sndr_t, stdexec::env_of_t<Tests::Utils::SinkReceiver>>,
99 >);
100
102 static_assert(!stdexec::__nothrow_connectable<pfor_sndr_t, Tests::Utils::SinkReceiver>);
103
104 return true;
105}
108
110template <typename ViewType>
111consteval bool test_closure_traits() {
113 using policy_t = Kokkos::RangePolicy<TEST_EXECUTION_SPACE>;
115
118
119 static_assert(std::is_nothrow_move_constructible_v<closure_t>);
120
121 return true;
122}
124static_assert(test_closure_traits<std::span<int>>());
125
130 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
132>());
133
138TEST_F(ParallelForTest, parallel_for_schedule) {
139 constexpr size_t size = 10;
140
141 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
142
143 const context_t gctx{exec};
144
145 auto sndr = stdexec::schedule(gctx.get_scheduler())
147 std::format("{}: hello from pfor", Kokkos::Impl::TypeInfo<TEST_EXECUTION_SPACE>::name()),
148 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, size),
150
151 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(std::move(sndr));
152
153 ASSERT_THAT(
154 recorded_events,
155 testing::ElementsAre(
158 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
159 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
161
162 ASSERT_EQ(data(), size / 2 * (size - 1));
163}
164
169TEST_F(ParallelForTest, parallel_for_starts_on) {
170 constexpr size_t size = 10;
171
172 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
173
174 auto chain = stdexec::just()
176 std::format("{}: hello from pfor", Kokkos::Impl::TypeInfo<TEST_EXECUTION_SPACE>::name()),
177 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, size),
179
180 using chain_t = decltype(chain);
181
182 static_assert(
183 stdexec::get_completion_signatures<chain_t>()
184 == stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_error_t(std::exception_ptr)>{});
186 static_assert(
187 std::same_as<stdexec::__completion_domain_of_t<stdexec::set_value_t, chain_t>, stdexec::indeterminate_domain<>>);
188
189 const context_t gctx{exec};
190 auto starts_on = stdexec::starts_on(gctx.get_scheduler(), std::move(chain));
191
192 using starts_on_t = decltype(starts_on);
193
194 static_assert(stdexec::__has_eptr_completion<chain_t>);
195 static_assert(!stdexec::dependent_sender<starts_on_t>);
196 static_assert(
197 stdexec::get_completion_signatures<starts_on_t>()
198 == stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_error_t(std::exception_ptr)>{});
199
200 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(std::move(starts_on));
201
202 ASSERT_THAT(recorded_events, testing::SizeIs(4));
203
204 ASSERT_THAT(
205 recorded_events,
206 testing::ElementsAre(
209 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
210 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
211 MATCHER_FOR_BEGIN_FENCE(exec, dispatch_label(exec, "after dispatch"))));
212
213 ASSERT_EQ(data(), size / 2 * (size - 1));
214}
215
220TEST_F(ParallelForTest, parallel_for_schedule_tagged_operator) {
221 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
222
223 const context_t gctx{exec};
224
226
227 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
228 stdexec::schedule(gctx.get_scheduler())
230 Kokkos::RangePolicy<typename functor_t::Tag, TEST_EXECUTION_SPACE>(0, 1), functor_t{.data = data}));
231
232 ASSERT_THAT(
233 recorded_events,
234 testing::ElementsAre(
237 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_ROOT_NODE_OF(recorded_events.at(0))),
238 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
240
241 ASSERT_EQ(data(), 1);
242}
243
244} // namespace Tests::GraphImpl
constexpr std::string dispatch_label(const Exec &, Label &&label)
Get the dispatch label from Exec and label.
#define MATCHER_FOR_BEGIN_FENCE(_exec_, _label_)
typename recorder_listener_t::event_variant_t variant_t
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.
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 parallel_for_t parallel_for
consteval bool test_closure_traits()
consteval bool test_sndr_traits()
Definition test_bulk.cpp:57
auto record_sync_wait(Sndr &&sndr)
Definition sync_wait.hpp:14
consteval bool check_continues_on_after_just_stopped()
auto get_scheduler() const noexcept -> GraphImpl::Scheduler< Exec >
Definition graph.hpp:134
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph node is added.
Definition events.hpp:36
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is created.
Definition events.hpp:16
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is instantiated.
Definition events.hpp:66
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is submitted.
Definition events.hpp:77
Scheduler for a Kokkos::Experimental::Graph.
Definition graph.hpp:24
Event to be sent to Kokkos::utils::callbacks::dispatch when calling record.
Definition event.hpp:54
Event to be sent to Kokkos::utils::callbacks::dispatch when calling wait.
Definition event.hpp:75
Custom algorithm for the Kokkos::parallel_for construct.
Similar to EventDiscardMatcher, for graph-related events.
Definition events.hpp:80
decltype(std::declval< const context_t >().get_scheduler()) scheduler_t
Definition context.hpp:28
decltype(stdexec::schedule(std::declval< scheduler_t >())) schedule_sender_t
Definition context.hpp:29
Kokkos::View< value_t, Kokkos::SharedSpace > view_s_t
Definition context.hpp:32
#define MATCHER_FOR_GRAPH_CREATE(_device_handle_)
Definition events.hpp:17
#define MATCHER_FOR_GRAPH_SUBMIT(_exec_, _graph_create_event_variant_)
Definition events.hpp:67
#define MATCHER_FOR_GRAPH_ADDNODE(_graph_create_event_variant_, _device_handle_, _predecessor_)
Definition events.hpp:24
#define MATCHER_FOR_GRAPH_ROOT_NODE_OF(_graph_create_event_)
Definition events.hpp:47