Skip to content

Commit

Permalink
Remove deprecated code in SortUtils (#1171)
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop authored Oct 9, 2024
1 parent 97fcbc2 commit 62caef6
Showing 1 changed file with 20 additions and 60 deletions.
80 changes: 20 additions & 60 deletions src/misc/ArborX_SortUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,67 +42,26 @@ auto sortObjects(ExecutionSpace const &space, ViewType &view)
return permute;
}

// Helper functions and structs for applyPermutations
namespace PermuteHelper
{
template <class DstViewType, class SrcViewType, int Rank = DstViewType::rank>
struct CopyOp;

template <class DstViewType, class SrcViewType>
struct CopyOp<DstViewType, SrcViewType, 1>
{
KOKKOS_INLINE_FUNCTION
static void copy(DstViewType const &dst, size_t i_dst, SrcViewType const &src,
size_t i_src)
{
dst(i_dst) = src(i_src);
}
};

template <class DstViewType, class SrcViewType>
struct [[deprecated]] CopyOp<DstViewType, SrcViewType, 2>
{
KOKKOS_INLINE_FUNCTION
static void copy(DstViewType const &dst, size_t i_dst, SrcViewType const &src,
size_t i_src)
{
for (unsigned int j = 0; j < dst.extent(1); j++)
dst(i_dst, j) = src(i_src, j);
}
};

template <class DstViewType, class SrcViewType>
struct [[deprecated]] CopyOp<DstViewType, SrcViewType, 3>
{
KOKKOS_INLINE_FUNCTION
static void copy(DstViewType const &dst, size_t i_dst, SrcViewType const &src,
size_t i_src)
{
for (unsigned int j = 0; j < dst.extent(1); j++)
for (unsigned int k = 0; k < dst.extent(2); k++)
dst(i_dst, j, k) = src(i_src, j, k);
}
};
} // namespace PermuteHelper

template <typename ExecutionSpace, typename PermutationView, typename InputView,
typename OutputView>
void applyInversePermutation(ExecutionSpace const &space,
PermutationView const &permutation,
InputView const &input_view,
OutputView const &output_view)
{
static_assert(Kokkos::is_view_v<InputView>);
static_assert(Kokkos::is_view_v<OutputView>);
static_assert(InputView::rank == 1);
static_assert(OutputView::rank == 1);
static_assert(std::is_integral_v<typename PermutationView::value_type>);
ARBORX_ASSERT(permutation.extent(0) == input_view.extent(0));
ARBORX_ASSERT(output_view.extent(0) == input_view.extent(0));

auto const n = input_view.extent(0);
ARBORX_ASSERT(permutation.extent(0) == n);
ARBORX_ASSERT(output_view.extent(0) == n);

Kokkos::parallel_for(
"ArborX::Sorting::inverse_permute",
Kokkos::RangePolicy(space, 0, input_view.extent(0)),
KOKKOS_LAMBDA(int i) {
PermuteHelper::CopyOp<OutputView, InputView>::copy(
output_view, permutation(i), input_view, i);
});
"ArborX::Sorting::inverse_permute", Kokkos::RangePolicy(space, 0, n),
KOKKOS_LAMBDA(int i) { output_view(permutation(i)) = input_view(i); });
}

template <typename ExecutionSpace, typename PermutationView, typename InputView,
Expand All @@ -112,24 +71,25 @@ void applyPermutation(ExecutionSpace const &space,
InputView const &input_view,
OutputView const &output_view)
{
static_assert(Kokkos::is_view_v<InputView>);
static_assert(Kokkos::is_view_v<OutputView>);
static_assert(InputView::rank == 1);
static_assert(OutputView::rank == 1);
static_assert(std::is_integral_v<typename PermutationView::value_type>);
ARBORX_ASSERT(permutation.extent(0) == input_view.extent(0));
ARBORX_ASSERT(output_view.extent(0) == input_view.extent(0));

auto const n = input_view.extent(0);
ARBORX_ASSERT(permutation.extent(0) == n);
ARBORX_ASSERT(output_view.extent(0) == n);

Kokkos::parallel_for(
"ArborX::Sorting::permute",
Kokkos::RangePolicy(space, 0, input_view.extent(0)),
KOKKOS_LAMBDA(int i) {
PermuteHelper::CopyOp<OutputView, InputView>::copy(
output_view, i, input_view, permutation(i));
});
"ArborX::Sorting::permute", Kokkos::RangePolicy(space, 0, n),
KOKKOS_LAMBDA(int i) { output_view(i) = input_view(permutation(i)); });
}

template <typename ExecutionSpace, typename PermutationView, typename View>
void applyPermutation(ExecutionSpace const &space,
PermutationView const &permutation, View &view)
{
static_assert(std::is_integral_v<typename PermutationView::value_type>);
auto scratch_view = KokkosExt::clone(space, view);
applyPermutation(space, permutation, scratch_view, view);
}
Expand Down

0 comments on commit 62caef6

Please sign in to comment.