Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix return type of getIndexable in HappyTreeFriends #1163

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/details/ArborX_DetailsHappyTreeFriends.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct HappyTreeFriends
}

template <class BVH>
static KOKKOS_FUNCTION auto const &getIndexable(BVH const &bvh, int i)
static KOKKOS_FUNCTION decltype(auto) getIndexable(BVH const &bvh, int i)
{
return bvh._indexable_getter(getValue(bvh, i));
}
Expand Down
50 changes: 50 additions & 0 deletions test/tstIndexableGetter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ArborX_EnableDeviceTypes.hpp" // ARBORX_DEVICE_TYPES
#include <ArborX_AccessTraits.hpp>
#include <ArborX_IndexableGetter.hpp>
#include <ArborX_LinearBVH.hpp>

#include "BoostTest_CUDA_clang_workarounds.hpp"
#include <boost/test/unit_test.hpp>
Expand Down Expand Up @@ -134,4 +135,53 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(indexables, DeviceType, ARBORX_DEVICE_TYPES)
}
}

template <typename MemorySpace, typename Geometry>
struct ReturnByValueIndexableGetter
{
Kokkos::View<Geometry *, MemorySpace> _geometries;

KOKKOS_FUNCTION auto operator()(ArborX::PairValueIndex<Geometry> value) const
{
return _geometries(value.index);
}
};

BOOST_AUTO_TEST_CASE_TEMPLATE(indexables_by_value, DeviceType,
ARBORX_DEVICE_TYPES)
{
// Test that the there is no reference to temporary when indexable getter
// returns by value. Would produce a warning.

using ExecutionSpace = typename DeviceType::execution_space;
using MemorySpace = typename DeviceType::memory_space;

using Point = ArborX::Point<3>;

Kokkos::View<Point *, MemorySpace> points("Testing::points", 2);
auto points_host = Kokkos::create_mirror_view(points);
points_host(0) = {-1, -1, -1};
points_host(1) = {1, 1, 1};
Kokkos::deep_copy(points, points_host);

using Value = ArborX::PairValueIndex<Point>;

using IndexableGetter = ReturnByValueIndexableGetter<MemorySpace, Point>;
ArborX::BoundingVolumeHierarchy<MemorySpace, Value, IndexableGetter> bvh(
ExecutionSpace{}, ArborX::Experimental::attach_indices(points),
IndexableGetter{points});

Kokkos::View<ArborX::Nearest<Point> *, MemorySpace> nearest_queries(
"Testing::nearest_queries", 1);
auto nearest_queries_host = Kokkos::create_mirror_view(nearest_queries);
nearest_queries_host(0) = ArborX::nearest<Point>({0, 0, 0}, 1);
deep_copy(nearest_queries, nearest_queries_host);

// We need to go through HappyTreeFriends to trigger the warning,
// as that's where we use `getIndexable()`
Kokkos::View<int *, MemorySpace> offsets("Testing::offsets", 0);
Kokkos::View<Value *, MemorySpace> values("Testing::values", 0);
bvh.query(ExecutionSpace{}, nearest_queries, values, offsets);
BOOST_TEST(offsets.size() == 2); // to prevent compiler to optimize out
}

BOOST_AUTO_TEST_SUITE_END()
Loading