34using namespace Kokkos::utils::callbacks;
36class TEST_CATEGORY(ParallelReduceTest)
57 template <
typename...>
typename SndrAdptr,
58 bool ExptIsDispatchingSender,
59 template <
typename>
typename ExptTransformSenderType
66 using label_t = std::string;
68 using policy_t = Kokkos::RangePolicy<TEST_EXECUTION_SPACE>;
76 using pred_sndr_t = SndrAdptr<schd_sndr_t, TEST_EXECUTION_SPACE, label_t, functor_t, policy_t, reducer_t>;
80 static_assert(std::same_as<Kokkos::Execution::Impl::exec_of_t<pred_sndr_t>, TEST_EXECUTION_SPACE>);
86 static_assert(!stdexec::dependent_sender<pred_sndr_t>);
88 stdexec::get_completion_signatures<pred_sndr_t>()
89 == stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_error_t(std::exception_ptr)>{});
92 static_assert(std::same_as<
93 stdexec::__completion_domain_of_t<stdexec::set_value_t, pred_sndr_t, stdexec::env<>>,
98 static_assert(std::same_as<
104 static_assert(stdexec::sender_to<pred_sndr_t, Tests::Utils::SinkReceiver>);
106 static_assert(std::same_as<
107 stdexec::transform_sender_result_t<pred_sndr_t, stdexec::env_of_t<Tests::Utils::SinkReceiver>>,
111 TEST_EXECUTION_SPACE,
117 static_assert(stdexec::__nothrow_connectable<pred_sndr_t, Tests::Utils::SinkReceiver>);
122template <
typename Sndr,
typename Exec,
typename Label,
typename Functor,
typename Policy,
typename Reducer>
128template <
typename Sndr,
typename Exec,
typename Label,
typename Functor,
typename Policy,
typename Reducer>
145 using label_t = std::string;
147 using policy_t = Kokkos::RangePolicy<TEST_EXECUTION_SPACE>;
153 static_assert(stdexec::__applicable<
156 const stdexec::env<>&
162static_assert(test_sndr_is_transformable());
165template <
typename ViewType>
166consteval bool test_closure_traits() {
168 using policy_t = Kokkos::RangePolicy<TEST_EXECUTION_SPACE>;
169 using reducer_t = ViewType;
181 static_assert(std::is_nothrow_move_constructible_v<closure_t>);
186static_assert(test_closure_traits<typename TEST_CATEGORY(ParallelReduceTest)::view_s_t>());
187static_assert(test_closure_traits<std::span<int>>());
193 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
194 Tests::Utils::Functors::NoOp<false, false, false>,
198template <
typename ViewType>
211 constexpr size_t size = 10;
218 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, size),
221 testing::ElementsAre(
225 ASSERT_EQ(target(), size / 2 * (size - 1));
235INSTANTIATE_TYPED_TEST_SUITE_P(
236 ParallelReduceManagedAndUnManagedTestInstantiation,
242 constexpr size_t size = 5;
244 using data_view_t = Kokkos::View<value_t[size], TEST_EXECUTION_SPACE>;
245 using max_loc_t = Kokkos::MaxLoc<value_t, typename TEST_EXECUTION_SPACE::index_type, Kokkos::SharedSpace>;
248 const data_view_t data(Kokkos::view_alloc(Kokkos::WithoutInitializing,
exec));
252 const typename max_loc_t::result_view_type target(Kokkos::view_alloc(
exec));
254 using combined_functor_reducer_t = Kokkos::Impl::CombinedFunctorReducer<
256 Kokkos::Impl::FunctorAnalysis<
257 Kokkos::Impl::FunctorPatternInterface::REDUCE,
258 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
260 typename max_loc_t::value_type
269 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 1),
270 KOKKOS_LAMBDA<std::integral T>(
const T) {
278 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, size),
279 max_loc_functor_t{.data = data},
281 testing::ElementsAre(
286 ASSERT_EQ(target().val, 56);
287 ASSERT_EQ(target().loc, 3);
292 constexpr int size = 2048;
294 const auto [num_teams, team_size] = [&]() {
296#if defined(KOKKOS_ENABLE_HPX)
297 if constexpr (std::same_as<TEST_EXECUTION_SPACE, Kokkos::Experimental::HPX>) {
298 return std::make_tuple(size, 1);
301 const int team_size_ = std::bit_floor(
static_cast<unsigned short>(std::min(
exec.concurrency(), size / 2)));
302 return std::make_tuple(size / team_size_, team_size_);
305 ASSERT_EQ(team_size * num_teams, size);
307 const view_s_t target(Kokkos::view_alloc(
exec,
"data - shared space"));
314 Kokkos::TeamPolicy<TEST_EXECUTION_SPACE>(num_teams, team_size),
316 TEST_EXECUTION_SPACE,
321 ASSERT_EQ(target(), size / 2 * (size - 1));
324template <
typename ViewType, Kokkos::ExecutionSpace Exec>
327 const ViewType& target,
329 return stdexec::schedule(esc.get_scheduler())
331 "passing label, execution policy, functor and target",
332 Kokkos::RangePolicy<Exec>(0, size),
341 Kokkos::range_slice<size_t, size_t>{4, 6}, Tests::Utils::Functors::ReduceIndices{}, target);
346 constexpr size_t size = 10;
348 const view_s_t target(Kokkos::view_alloc(
exec,
"data - shared space"));
354 using combined_functor_reducer_t = Kokkos::Impl::CombinedFunctorReducer<
356 Kokkos::Impl::FunctorAnalysis<
357 Kokkos::Impl::FunctorPatternInterface::REDUCE,
358 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
367 testing::ElementsAre(
375 ASSERT_EQ(target(), 4 + 5);
380 constexpr size_t size = 10;
382 const view_s_t target(Kokkos::view_alloc(
exec,
"data - shared space"));
390 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, size),
395 .prev = size / 2 * (size - 1), .value = 0, .data = target.data()})
399 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 2 * size),
405 testing::ElementsAre(
411 ASSERT_EQ(target(), 2 * size * (2 * size - 1) / 2);
416 constexpr size_t size = 10;
418 const view_s_t target(Kokkos::view_alloc(
exec,
"data - shared space"));
424 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, size),
428 using chain_t =
decltype(chain);
431 stdexec::get_completion_signatures<chain_t>()
432 == stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_error_t(std::exception_ptr)>{});
435 std::same_as<stdexec::__completion_domain_of_t<stdexec::set_value_t, chain_t>, stdexec::indeterminate_domain<>>);
438 auto starts_on = stdexec::starts_on(esc.
get_scheduler(), std::move(chain));
440 using starts_on_t =
decltype(starts_on);
442 static_assert(stdexec::__has_eptr_completion<chain_t>);
443 static_assert(!stdexec::dependent_sender<starts_on_t>);
445 stdexec::get_completion_signatures<starts_on_t>()
446 == stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_error_t(std::exception_ptr)>{});
454 static_assert(stdexec::__is_instance_of<
455 stdexec::transform_sender_result_t<
457 stdexec::env_of_t<Kokkos::Execution::Impl::SyncWait::Receiver<TEST_EXECUTION_SPACE>>
459 stdexec::__seq::__sndr
464 ASSERT_THAT(recorded_events, [&]() {
466 return testing::ElementsAre(
471 return testing::ElementsAre(
477 ASSERT_EQ(target(), size / 2 * (size - 1));
482 constexpr size_t size = 10;
484 const view_s_t target(Kokkos::view_alloc(
exec,
"data - shared space"));
486 std::atomic<size_t> count = 0;
492 stdexec::sender
auto sndr =
493 stdexec::read_env(stdexec::get_allocator)
499 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, size),
504 ASSERT_EQ(target(), 0) <<
"Eager execution is not allowed.";
508 ASSERT_THAT(recorded_events, [&]() {
510 return testing::ElementsAre(
515 return testing::ElementsAre(
521 ASSERT_EQ(target(), size / 2 * (size - 1));
523 ASSERT_EQ(value, 42);
constexpr std::string dispatch_label(const Exec &, const std::string_view label)
Get the dispatch label from Exec and label.
#define MATCHER_FOR_BEGIN_PRED(_exec_, _label_)
#define MATCHER_FOR_DEV_ID(_type_, _exec_)
#define MATCHER_FOR_BEGIN_SINGLE(_exec_, _label_)
#define MATCHER_FOR_WAIT_EVENT(_record_event_variant_)
#define MATCHER_FOR_RECORD_EVENT(_exec_)
#define MATCHER_FOR_BEGIN_FENCE(_exec_, _label_)
#define TEST_CATEGORY(_name_)
RecorderListener< EventDiscardMatcher< TEST_EXECUTION_SPACE >, BeginDeepCopyEvent, BeginFenceEvent, BeginParallelForEvent, BeginParallelReduceEvent, BeginSingleEvent, Kokkos::Execution::Impl::RecordEvent, Kokkos::Execution::Impl::WaitEvent > recorder_listener_t
gtest_TypeParam_ TypeParam
Concept for a sender whose completion scheduler is Kokkos::Execution::ExecutionSpaceImpl::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 auto display_string_of() noexcept -> std::string_view
constexpr parallel_for_t parallel_for
constexpr parallel_reduce_t parallel_reduce
auto ABeginParallelForEvent(Matchers &&... matchers)
::testing::Types< typename ParallelReduceTest::view_s_t, typename ParallelReduceTest::view_um_s_t > pred_managed_and_unmanaged_types_t
Kokkos::Execution::ExecutionSpaceImpl::ParallelReduceSender< Kokkos::Execution::parallel_reduce_t, Sndr, Exec, Kokkos::Execution::Impl::ParallelReduceData< Functor, Policy, Reducer, Kokkos::Execution::Impl::Label< Label > > > pred_impl_t
consteval bool test_sndr_traits()
auto closure_object_creation_overloads(const size_t size, const ViewType &witness, const Kokkos::Execution::ExecutionSpaceContext< Exec > &esc) -> stdexec::sender auto
Kokkos::Execution::Impl::ParallelReduceSender< Sndr, Kokkos::Execution::Impl::ParallelReduceData< Functor, Policy, Reducer, Kokkos::Execution::Impl::Label< Label > > > pred_generic_t
consteval bool test_sndr_is_transformable()
auto record_sync_wait(Sndr &&sndr)
consteval bool check_continues_on_after_just_stopped()
constexpr check_rcvr_env_queryable_with_t< true, Queries... > check_rcvr_env_queryable_with
auto round_trip_allocate(Allocator &allocator, T &&value)
Matcher to filter out events that are just noise for tests.
Execution context using a Kokkos execution space under the hood.
auto get_scheduler() const noexcept -> ExecutionSpaceImpl::Scheduler< execution_space >
Scheduler for a Kokkos execution space.
Event to be sent to Kokkos::utils::callbacks::dispatch when calling record.
Event to be sent to Kokkos::utils::callbacks::dispatch when calling wait.
Custom algorithm for the Kokkos::parallel_reduce construct.
Kokkos::View< value_t, Kokkos::SharedSpace > view_s_t
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Load the value at data and check it is equal to prev. Then, add value to it.
Can be used in a parallel_reduce to find the greater of the values in data alongside its index.
Similar to ReduceIndices, with a team policy.
A minimal tracking allocator.