Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Deprecate exclusivePrefixSum, accumulate, adjacentDifference, iota and provide KokkosExt ones #999

Merged
merged 16 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 2 additions & 30 deletions src/details/ArborX_DetailsUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,39 +368,12 @@ max(ViewType const &v)
return max(ExecutionSpace{}, v);
}

/** \brief Accumulate values in a view
*
* \param[in] space Execution space
* \param[in] v Input view
* \param[in] init Initial value of the sum
*
* Returns the sum of the given \p init value and elements in the given view \p
* v. Uses operator+ to sum up the elements.
*/
template <typename ExecutionSpace, typename ViewType>
typename ViewType::non_const_value_type
[[deprecated]] typename ViewType::non_const_value_type
accumulate(ExecutionSpace &&space, ViewType const &v,
typename ViewType::non_const_value_type init)
{
static_assert(ViewType::rank == 1, "accumulate requires a View of rank 1");
auto const n = v.extent(0);
// NOTE: Passing the argument init directly to the parallel_reduce() while
// using a lambda does not yield the expected result because Kokkos will
// supply a default init method that sets the reduction result to zero.
// Rather than going through the hassle of defining a custom functor for
// the reduction, introduce here a temporary variable and add it to init
// before returning.
typename ViewType::non_const_value_type tmp;
Kokkos::RangePolicy<std::decay_t<ExecutionSpace>> policy(
std::forward<ExecutionSpace>(space), 0, n);
Kokkos::parallel_reduce(
"ArborX::Algorithms::accumulate", policy,
KOKKOS_LAMBDA(int i, typename ViewType::non_const_value_type &update) {
update += v(i);
},
tmp);
init += tmp;
return init;
Details::KokkosExt::reduce(std::forward<ExecutionSpace>(space), v, init);
}

template <typename ViewType>
Expand Down Expand Up @@ -516,7 +489,6 @@ template <typename View>

namespace Details
{

template <typename ExecutionSpace, typename View, typename Offset>
void computeOffsetsInOrderedView(ExecutionSpace const &exec_space, View view,
Offset &offsets)
Expand Down
26 changes: 26 additions & 0 deletions src/kokkos_ext/ArborX_DetailsKokkosExtStdAlgorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,32 @@ exclusive_scan(ExecutionSpace &&space, Kokkos::View<T, P...> const &v)
exclusive_scan(std::forward<ExecutionSpace>(space), v, v);
}

template <typename ExecutionSpace, typename ViewType>
typename ViewType::non_const_value_type
reduce(ExecutionSpace &&space, ViewType const &v,
typename ViewType::non_const_value_type init)
{
static_assert(ViewType::rank == 1, "accumulate requires a View of rank 1");
auto const n = v.extent(0);
// NOTE: Passing the argument init directly to the parallel_reduce() while
// using a lambda does not yield the expected result because Kokkos will
// supply a default init method that sets the reduction result to zero.
// Rather than going through the hassle of defining a custom functor for
// the reduction, introduce here a temporary variable and add it to init
// before returning.
typename ViewType::non_const_value_type tmp;
Kokkos::RangePolicy<std::decay_t<ExecutionSpace>> policy(
std::forward<ExecutionSpace>(space), 0, n);
Kokkos::parallel_reduce(
"ArborX::Algorithms::accumulate", policy,
KOKKOS_LAMBDA(int i, typename ViewType::non_const_value_type &update) {
update += v(i);
},
tmp);
init += tmp;
return init;
}

} // namespace ArborX::Details::KokkosExt

#endif