/**************************************************************************** * Copyright (c) 2017-2023 by the ArborX authors * * All rights reserved. * * * * This file is part of the ArborX library. ArborX is * * distributed under a BSD 3-clause license. For the licensing terms see * * the LICENSE file in the top-level directory. * * * * SPDX-License-Identifier: BSD-3-Clause * ****************************************************************************/ #ifndef ARBORX_DETAILS_UTILS_HPP #define ARBORX_DETAILS_UTILS_HPP #include #include #include #include #include #include namespace ArborX { template [[deprecated]] void exclusivePrefixSum(ExecutionSpace &&space, Kokkos::View const &src, Kokkos::View const &dst) { Details::KokkosExt::exclusive_scan(std::forward(space), src, dst, 0); } template [[deprecated]] inline std::enable_if_t< Kokkos::is_execution_space>::value> exclusivePrefixSum(ExecutionSpace &&space, Kokkos::View const &v) { exclusivePrefixSum(std::forward(space), v, v); } template [[deprecated]] inline void exclusivePrefixSum(Kokkos::View const &src, Kokkos::View const &dst) { using ExecutionSpace = typename Kokkos::View::execution_space; exclusivePrefixSum(ExecutionSpace{}, src, dst); } template [[deprecated]] inline void exclusivePrefixSum(Kokkos::View const &v) { using ExecutionSpace = typename Kokkos::View::execution_space; exclusivePrefixSum(ExecutionSpace{}, v); } /** \brief Get a copy of the last element. * * Returns a copy of the last element in the view on the host. Note that it * may require communication between host and device (e.g. if the view passed * as an argument lives on the device). * * \pre \c v is of rank 1 and not empty. */ template [[deprecated]] typename Kokkos::ViewTraits::non_const_value_type lastElement(Kokkos::View const &v) { using ExecutionSpace = typename Kokkos::View::execution_space; return Details::KokkosExt::lastElement(ExecutionSpace{}, v); } template [[deprecated]] void iota(ExecutionSpace &&space, Kokkos::View const &v, typename Kokkos::ViewTraits::value_type value = 0) { Details::KokkosExt::iota(std::forward(space), v, value); } template [[deprecated]] inline void iota(Kokkos::View const &v, typename Kokkos::ViewTraits::value_type value = 0) { using ExecutionSpace = typename Kokkos::ViewTraits::execution_space; iota(ExecutionSpace{}, v, value); } template [[deprecated]] std::pair minMax(ExecutionSpace &&space, ViewType const &v) { return Details::KokkosExt::minmax_reduce(std::forward(space), v); } template [[deprecated]] inline std::pair minMax(ViewType const &v) { using ExecutionSpace = typename ViewType::execution_space; return minMax(ExecutionSpace{}, v); } template [[deprecated]] typename ViewType::non_const_value_type min(ExecutionSpace &&space, ViewType const &v) { return Details::KokkosExt::min_reduce(std::forward(space), v); } template [[deprecated]] inline typename ViewType::non_const_value_type min(ViewType const &v) { using ExecutionSpace = typename ViewType::execution_space; return min(ExecutionSpace{}, v); } template [[deprecated]] typename ViewType::non_const_value_type max(ExecutionSpace &&space, ViewType const &v) { return Details::KokkosExt::max_reduce(std::forward(space), v); } template [[deprecated]] inline typename ViewType::non_const_value_type max(ViewType const &v) { using ExecutionSpace = typename ViewType::execution_space; return max(ExecutionSpace{}, v); } template [[deprecated]] typename ViewType::non_const_value_type accumulate(ExecutionSpace &&space, ViewType const &v, typename ViewType::non_const_value_type init) { Details::KokkosExt::reduce(std::forward(space), v, init); } template [[deprecated]] inline typename ViewType::non_const_value_type accumulate(ViewType const &v, typename ViewType::non_const_value_type init) { using ExecutionSpace = typename ViewType::execution_space; return accumulate(ExecutionSpace{}, v, init); } // FIXME shameless forward declaration template typename View::non_const_type clone(View &v); template [[deprecated]] void adjacentDifference(ExecutionSpace &&space, SrcViewType const &src, DstViewType const &dst) { Details::KokkosExt::adjacent_difference(std::forward(space), src, dst); } template [[deprecated]] inline void adjacentDifference(SrcViewType const &src, DstViewType const &dst) { using ExecutionSpace = typename DstViewType::execution_space; adjacentDifference(ExecutionSpace{}, src, dst); } // FIXME split this into one for STL-like algorithms and another one for view // utility helpers // NOTE: not possible to avoid initialization with Kokkos::realloc() template [[deprecated]] void reallocWithoutInitializing(View &v, size_t n0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, size_t n1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, size_t n2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, size_t n3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, size_t n4 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG, size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG) { using ExecutionSpace = typename View::execution_space; Details::KokkosExt::reallocWithoutInitializing(ExecutionSpace{}, v, n0, n1, n2, n3, n4, n5, n6, n7); } template [[deprecated]] void reallocWithoutInitializing(View &v, typename View::array_layout const &layout) { using ExecutionSpace = typename View::execution_space; Details::KokkosExt::reallocWithoutInitializing(ExecutionSpace{}, v, layout); } template [[deprecated]] typename View::non_const_type cloneWithoutInitializingNorCopying(View &v) { using ExecutionSpace = typename View::execution_space; return Details::KokkosExt::cloneWithoutInitializingNorCopying( ExecutionSpace{}, v); } template [[deprecated]] typename View::non_const_type clone(ExecutionSpace const &space, View &v) { return Details::KokkosExt::clone(space, v); } template [[deprecated]] inline typename View::non_const_type clone(View &v) { using ExecutionSpace = typename View::execution_space; return Details::KokkosExt::clone(ExecutionSpace{}, v); } namespace Details { template void computeOffsetsInOrderedView(ExecutionSpace const &exec_space, View view, Offset &offsets) { static_assert(KokkosExt::is_accessible_from::value); static_assert(KokkosExt::is_accessible_from::value); auto const n = view.extent_int(0); int num_offsets; KokkosExt::reallocWithoutInitializing(exec_space, offsets, n + 1); Kokkos::parallel_scan( "ArborX::Algorithms::compute_offsets_in_sorted_view", Kokkos::RangePolicy(exec_space, 0, n + 1), KOKKOS_LAMBDA(int i, int &update, bool final_pass) { bool const is_cell_first_index = (i == 0 || i == n || view(i) != view(i - 1)); if (is_cell_first_index) { if (final_pass) offsets(update) = i; ++update; } }, num_offsets); Kokkos::resize(Kokkos::view_alloc(exec_space, Kokkos::WithoutInitializing), offsets, num_offsets); } } // namespace Details } // namespace ArborX #endif