Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Co-authored-by: Damien L-G <dalg24+github@gmail.com>
  • Loading branch information
aprokop and dalg24 committed Oct 4, 2024
1 parent a0c377b commit 4d6da22
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/kokkos_ext/ArborX_KokkosExtKernelStdAlgorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ KOKKOS_FUNCTION void nth_element(Iterator first, Iterator nth, Iterator last)
}

template <typename Iterator, typename T>
KOKKOS_FUNCTION auto upper_bound(Iterator first, Iterator last, T const &value)
KOKKOS_FUNCTION Iterator upper_bound(Iterator first, Iterator last,
T const &value)
{
int count = last - first;
while (count > 0)
Expand Down
48 changes: 23 additions & 25 deletions test/tstDetailsKokkosExtKernelStdAlgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
namespace tt = boost::test_tools;

template <typename T>
using UnmanagedView = Kokkos::View<T *, Kokkos::HostSpace,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
using UnmanagedHostView = Kokkos::View<T *, Kokkos::HostSpace,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>;

BOOST_AUTO_TEST_CASE_TEMPLATE(nth_element, DeviceType, ARBORX_DEVICE_TYPES)
{
Expand All @@ -45,8 +45,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(nth_element, DeviceType, ARBORX_DEVICE_TYPES)
{
int const n = v_ref.size();

Kokkos::View<float *, DeviceType> v("Testing::v", n);
Kokkos::deep_copy(space, v, UnmanagedView<float>(v_ref.data(), n));
Kokkos::View<float *, DeviceType> v("Testing::v", 0);
v = Kokkos::create_mirror_view_and_copy(
space, UnmanagedHostView<float>(v_ref.data(), n));

Kokkos::View<float *, DeviceType> nth("Testing::nth", n);
for (int i = 0; i < n; ++i)
Expand All @@ -68,40 +69,37 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(nth_element, DeviceType, ARBORX_DEVICE_TYPES)
}

template <typename DeviceType>
int upperBound(std::vector<float> const &v_host, float x)
int findUpperBound(std::vector<float> const &v_host, float x)
{
typename DeviceType::execution_space space;

auto const n = v_host.size();
Kokkos::View<float *, DeviceType> v("Testing::v", n);
Kokkos::deep_copy(v, UnmanagedHostView<float const>(v_host.data(), n));

Kokkos::deep_copy(space, v, UnmanagedView<float const>(v_host.data(), n));

int result;
int pos;
Kokkos::parallel_reduce(
Kokkos::RangePolicy(space, 0, 1),
Kokkos::RangePolicy<typename DeviceType::execution_space>(0, 1),
KOKKOS_LAMBDA(int, int &update) {
update =
ArborX::Details::KokkosExt::upper_bound(v.data(), v.data() + n, x) -
v.data();
},
result);
pos);

return result;
return pos;
}

BOOST_AUTO_TEST_CASE_TEMPLATE(upper_bound, DeviceType, ARBORX_DEVICE_TYPES)
{
BOOST_TEST(upperBound<DeviceType>({}, 0) == 0);
BOOST_TEST(upperBound<DeviceType>({0}, -1) == 0);
BOOST_TEST(upperBound<DeviceType>({0}, 0) == 1);
BOOST_TEST(upperBound<DeviceType>({0}, 1) == 1);
BOOST_TEST(upperBound<DeviceType>({1, 1}, 0) == 0);
BOOST_TEST(upperBound<DeviceType>({1, 1}, 1) == 2);
BOOST_TEST(upperBound<DeviceType>({1, 3, 5}, 1) == 1);
BOOST_TEST(upperBound<DeviceType>({1, 3, 5}, 2) == 1);
BOOST_TEST(upperBound<DeviceType>({1, 3, 5}, 3) == 2);
BOOST_TEST(upperBound<DeviceType>({1, 3, 5}, 4) == 2);
BOOST_TEST(upperBound<DeviceType>({1, 3, 5}, 5) == 3);
BOOST_TEST(upperBound<DeviceType>({1, 3, 5, 7, 9, 11, 13}, 8) == 4);
BOOST_TEST(findUpperBound<DeviceType>({}, 0) == 0);
BOOST_TEST(findUpperBound<DeviceType>({0}, -1) == 0);
BOOST_TEST(findUpperBound<DeviceType>({0}, 0) == 1);
BOOST_TEST(findUpperBound<DeviceType>({0}, 1) == 1);
BOOST_TEST(findUpperBound<DeviceType>({1, 1}, 0) == 0);
BOOST_TEST(findUpperBound<DeviceType>({1, 1}, 1) == 2);
BOOST_TEST(findUpperBound<DeviceType>({1, 3, 5}, 1) == 1);
BOOST_TEST(findUpperBound<DeviceType>({1, 3, 5}, 2) == 1);
BOOST_TEST(findUpperBound<DeviceType>({1, 3, 5}, 3) == 2);
BOOST_TEST(findUpperBound<DeviceType>({1, 3, 5}, 4) == 2);
BOOST_TEST(findUpperBound<DeviceType>({1, 3, 5}, 5) == 3);
BOOST_TEST(findUpperBound<DeviceType>({1, 3, 5, 7, 9, 11, 13}, 8) == 4);
}

0 comments on commit 4d6da22

Please sign in to comment.