Skip to content

Commit

Permalink
Add test with temporary access traits and indexables
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop committed Mar 15, 2024
1 parent 5b9608d commit e21c55a
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 1 deletion.
7 changes: 6 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ endif()
target_include_directories(ArborX_Test_QueryTree.exe PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
add_test(NAME ArborX_Test_QueryTree COMMAND ArborX_Test_QueryTree.exe)

add_executable(ArborX_Test_DetailsTreeConstruction.exe tstDetailsMortonCodes.cpp tstDetailsTreeConstruction.cpp utf_main.cpp)
add_executable(ArborX_Test_DetailsTreeConstruction.exe
tstDetailsMortonCodes.cpp
tstDetailsTreeConstruction.cpp
tstIndexableGetter.cpp
utf_main.cpp
)
target_link_libraries(ArborX_Test_DetailsTreeConstruction.exe PRIVATE ArborX Boost::unit_test_framework)
target_compile_definitions(ArborX_Test_DetailsTreeConstruction.exe PRIVATE BOOST_TEST_DYN_LINK)
target_include_directories(ArborX_Test_DetailsTreeConstruction.exe PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
Expand Down
135 changes: 135 additions & 0 deletions test/tstIndexableGetter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/****************************************************************************
* Copyright (c) 2017-2022 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 *
****************************************************************************/
#include "ArborX_EnableDeviceTypes.hpp" // ARBORX_DEVICE_TYPES
#include <ArborX_AccessTraits.hpp>
#include <ArborX_IndexableGetter.hpp>

#include <boost/test/unit_test.hpp>

using namespace ArborX::Details;

#include <ArborX_HyperPoint.hpp>

template <typename MemorySpace>
struct PointCloud
{
ArborX::Point *data;
int n;
};

template <typename MemorySpace>
struct ArborX::AccessTraits<PointCloud<MemorySpace>, ArborX::PrimitivesTag>
{
using Points = PointCloud<MemorySpace>;

static KOKKOS_FUNCTION std::size_t size(Points const &points)
{
return points.n;
}
static KOKKOS_FUNCTION auto get(Points const &points, std::size_t i)
{
return points.data[i];
}
using memory_space = MemorySpace;
};

template <typename MemorySpace>
struct PairPointIndexCloud
{
ArborX::Point *data;
int n;
};

template <typename MemorySpace>
struct ArborX::AccessTraits<PairPointIndexCloud<MemorySpace>,
ArborX::PrimitivesTag>
{
using Points = PairPointIndexCloud<MemorySpace>;

static KOKKOS_FUNCTION std::size_t size(Points const &points)
{
return points.n;
}
static KOKKOS_FUNCTION auto get(Points const &points, std::size_t i)
{
return ArborX::PairValueIndex<ArborX::Point, int>{points.data[i], (int)i};
}
using memory_space = MemorySpace;
};

template <typename ExecutionSpace, typename Indexables, typename Box>
inline void calculateBoundingBoxOfTheScene(ExecutionSpace const &space,
Indexables const &indexables,
Box &scene_bounding_box)
{
Kokkos::parallel_reduce(
"ArborX::TreeConstruction::calculate_bounding_box_of_the_scene",
Kokkos::RangePolicy<ExecutionSpace>(space, 0, indexables.size()),
KOKKOS_LAMBDA(int i, Box &update) { expand(update, indexables(i)); },
Kokkos::Sum<Box>{scene_bounding_box});
}

BOOST_AUTO_TEST_SUITE(MortonCodes)

BOOST_AUTO_TEST_CASE_TEMPLATE(indexables, DeviceType, ARBORX_DEVICE_TYPES)
{
// Test that the two-level wrapping Data -> AccessValues -> Indexables by
// using DefaultIndexableGetter works correctly.

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

using ArborX::Details::equals;

Kokkos::View<ArborX::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);

ArborX::Box scene_bounding_box = ArborX::Box{{-1, -1, -1}, {1, 1, 1}};

using IndexableGetter = ArborX::Details::DefaultIndexableGetter;
IndexableGetter indexable_getter;

{
PointCloud<MemorySpace> points_cloud{points.data(), (int)points.size()};

using Primitives = ArborX::Details::AccessValues<decltype(points_cloud),
ArborX::PrimitivesTag>;
Primitives primitives(points_cloud);

ArborX::Details::Indexables<Primitives, IndexableGetter> indexables{
primitives, indexable_getter};

ArborX::Box box;
calculateBoundingBoxOfTheScene(ExecutionSpace{}, indexables, box);
BOOST_ASSERT(equals(box, scene_bounding_box));
}

{
PairPointIndexCloud<MemorySpace> points_cloud{points.data(),
(int)points.size()};

using Primitives = ArborX::Details::AccessValues<decltype(points_cloud),
ArborX::PrimitivesTag>;
Primitives primitives(points_cloud);

ArborX::Details::Indexables<Primitives, IndexableGetter> indexables{
primitives, indexable_getter};

ArborX::Box box;
calculateBoundingBoxOfTheScene(ExecutionSpace{}, indexables, box);
BOOST_ASSERT(equals(box, scene_bounding_box));
}
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit e21c55a

Please sign in to comment.