Skip to content

Commit

Permalink
Merge pull request #970 from aprokop/the_great_unification
Browse files Browse the repository at this point in the history
Unify old and new interfaces in a single class
  • Loading branch information
aprokop authored Dec 20, 2023
2 parents fd157d7 + d64e481 commit 528631b
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 79 deletions.
7 changes: 3 additions & 4 deletions benchmarks/brute_force_vs_bvh/brute_force_vs_bvh_timpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ static void run_fp(int nprimitives, int nqueries, int nrepeats)
[[maybe_unused]] unsigned int out_count;
{
Kokkos::Timer timer;
ArborX::BasicBoundingVolumeHierarchy<
MemorySpace, ArborX::Details::PairIndexVolume<Point>>
ArborX::BoundingVolumeHierarchy<MemorySpace,
ArborX::Details::PairIndexVolume<Point>>
bvh{space, ArborX::Details::LegacyValues<decltype(primitives), Point>{
primitives}};

Expand All @@ -110,8 +110,7 @@ static void run_fp(int nprimitives, int nqueries, int nrepeats)

{
Kokkos::Timer timer;
ArborX::BasicBruteForce<MemorySpace,
ArborX::Details::PairIndexVolume<Point>>
ArborX::BruteForce<MemorySpace, ArborX::Details::PairIndexVolume<Point>>
brute{space,
ArborX::Details::LegacyValues<decltype(primitives), Point>{
primitives}};
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/dbscan/ArborX_DBSCANVerification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ bool verifyDBSCAN(ExecutionSpace exec_space, Primitives const &primitives,
using Point = typename Points::value_type;
static_assert(GeometryTraits::is_point<Point>{});

ArborX::BasicBoundingVolumeHierarchy<MemorySpace,
ArborX::Details::PairIndexVolume<Point>>
ArborX::BoundingVolumeHierarchy<MemorySpace,
ArborX::Details::PairIndexVolume<Point>>
bvh(exec_space, ArborX::Details::LegacyValues<Points, Point>{points});

auto const predicates = Details::PrimitivesWithRadius<Points>{points, eps};
Expand Down
4 changes: 2 additions & 2 deletions examples/triangle_intersection/triangle_intersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ int main()
Triangles<MemorySpace> triangles(execution_space);

// Create BVH tree
ArborX::BasicBoundingVolumeHierarchy<
MemorySpace, ArborX::Details::PairIndexVolume<Box>> const
ArborX::BoundingVolumeHierarchy<MemorySpace,
ArborX::Details::PairIndexVolume<Box>> const
tree(execution_space,
ArborX::Details::LegacyValues<decltype(triangles), Box>{triangles});

Expand Down
52 changes: 26 additions & 26 deletions src/ArborX_BruteForce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
namespace ArborX
{

template <typename MemorySpace, typename Value,
typename IndexableGetter = Details::DefaultIndexableGetter,
typename BoundingVolume = ExperimentalHyperGeometry::Box<
GeometryTraits::dimension_v<
std::decay_t<std::invoke_result_t<IndexableGetter, Value>>>,
typename GeometryTraits::coordinate_type<std::decay_t<
std::invoke_result_t<IndexableGetter, Value>>>::type>>
class BasicBruteForce
template <
typename MemorySpace, typename Value = Details::LegacyDefaultTemplateValue,
typename IndexableGetter = Details::DefaultIndexableGetter,
typename BoundingVolume = ExperimentalHyperGeometry::Box<
GeometryTraits::dimension_v<
std::decay_t<std::invoke_result_t<IndexableGetter, Value>>>,
typename GeometryTraits::coordinate_type<
std::decay_t<std::invoke_result_t<IndexableGetter, Value>>>::type>>
class BruteForce
{
public:
using memory_space = MemorySpace;
Expand All @@ -43,11 +44,11 @@ class BasicBruteForce
using bounding_volume_type = BoundingVolume;
using value_type = Value;

BasicBruteForce() = default;
BruteForce() = default;

template <typename ExecutionSpace, typename Values>
BasicBruteForce(ExecutionSpace const &space, Values const &values,
IndexableGetter const &indexable_getter = IndexableGetter());
BruteForce(ExecutionSpace const &space, Values const &values,
IndexableGetter const &indexable_getter = IndexableGetter());

KOKKOS_FUNCTION
size_type size() const noexcept { return _size; }
Expand Down Expand Up @@ -91,14 +92,15 @@ class BasicBruteForce
IndexableGetter _indexable_getter;
};

template <typename MemorySpace, typename BoundingVolume = Box>
class BruteForce
: public BasicBruteForce<MemorySpace, Details::PairIndexVolume<Box>,
Details::DefaultIndexableGetter, BoundingVolume>
template <typename MemorySpace>
class BruteForce<MemorySpace, Details::LegacyDefaultTemplateValue,
Details::DefaultIndexableGetter,
ExperimentalHyperGeometry::Box<3, float>>
: public BruteForce<MemorySpace, Details::PairIndexVolume<Box>,
Details::DefaultIndexableGetter, Box>
{
using base_type =
BasicBruteForce<MemorySpace, Details::PairIndexVolume<Box>,
Details::DefaultIndexableGetter, BoundingVolume>;
using base_type = BruteForce<MemorySpace, Details::PairIndexVolume<Box>,
Details::DefaultIndexableGetter, Box>;

public:
using bounding_volume_type = typename base_type::bounding_volume_type;
Expand Down Expand Up @@ -172,9 +174,9 @@ class BruteForce
template <typename MemorySpace, typename Value, typename IndexableGetter,
typename BoundingVolume>
template <typename ExecutionSpace, typename UserValues>
BasicBruteForce<MemorySpace, Value, IndexableGetter, BoundingVolume>::
BasicBruteForce(ExecutionSpace const &space, UserValues const &user_values,
IndexableGetter const &indexable_getter)
BruteForce<MemorySpace, Value, IndexableGetter, BoundingVolume>::BruteForce(
ExecutionSpace const &space, UserValues const &user_values,
IndexableGetter const &indexable_getter)
: _size(AccessTraits<UserValues, PrimitivesTag>::size(user_values))
, _values(Kokkos::view_alloc(space, Kokkos::WithoutInitializing,
"ArborX::BruteForce::values"),
Expand Down Expand Up @@ -209,11 +211,9 @@ template <typename MemorySpace, typename Value, typename IndexableGetter,
typename BoundingVolume>
template <typename ExecutionSpace, typename Predicates, typename Callback,
typename Ignore>
void BasicBruteForce<MemorySpace, Value, IndexableGetter,
BoundingVolume>::query(ExecutionSpace const &space,
Predicates const &predicates,
Callback const &callback,
Ignore) const
void BruteForce<MemorySpace, Value, IndexableGetter, BoundingVolume>::query(
ExecutionSpace const &space, Predicates const &predicates,
Callback const &callback, Ignore) const
{
static_assert(
KokkosExt::is_accessible_from<MemorySpace, ExecutionSpace>::value);
Expand Down
7 changes: 3 additions & 4 deletions src/ArborX_DBSCAN.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ dbscan(ExecutionSpace const &exec_space, Primitives const &primitives,
{
// Build the tree
Kokkos::Profiling::pushRegion("ArborX::DBSCAN::tree_construction");
ArborX::BasicBoundingVolumeHierarchy<MemorySpace,
Details::PairIndexVolume<Point>>
ArborX::BoundingVolumeHierarchy<MemorySpace,
Details::PairIndexVolume<Point>>
bvh(exec_space, Details::LegacyValues<Points, Point>{points});
Kokkos::Profiling::popRegion();

Expand Down Expand Up @@ -421,8 +421,7 @@ dbscan(ExecutionSpace const &exec_space, Primitives const &primitives,
sorted_cell_indices,
permute};

ArborX::BasicBoundingVolumeHierarchy<MemorySpace,
Details::PairIndexVolume<Box>>
ArborX::BoundingVolumeHierarchy<MemorySpace, Details::PairIndexVolume<Box>>
bvh(exec_space, Details::LegacyValues<decltype(mixed_primitives), Box>{
mixed_primitives});

Expand Down
62 changes: 36 additions & 26 deletions src/ArborX_LinearBVH.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ namespace Details
struct HappyTreeFriends;
} // namespace Details

template <typename MemorySpace, typename Value,
typename IndexableGetter = Details::DefaultIndexableGetter,
typename BoundingVolume = ExperimentalHyperGeometry::Box<
GeometryTraits::dimension_v<
std::decay_t<std::invoke_result_t<IndexableGetter, Value>>>,
typename GeometryTraits::coordinate_type<std::decay_t<
std::invoke_result_t<IndexableGetter, Value>>>::type>>
class BasicBoundingVolumeHierarchy
template <
typename MemorySpace, typename Value = Details::LegacyDefaultTemplateValue,
typename IndexableGetter = Details::DefaultIndexableGetter,
typename BoundingVolume = ExperimentalHyperGeometry::Box<
GeometryTraits::dimension_v<
std::decay_t<std::invoke_result_t<IndexableGetter, Value>>>,
typename GeometryTraits::coordinate_type<
std::decay_t<std::invoke_result_t<IndexableGetter, Value>>>::type>>
class BoundingVolumeHierarchy
{
public:
using memory_space = MemorySpace;
Expand All @@ -63,11 +64,11 @@ class BasicBoundingVolumeHierarchy
using bounding_volume_type = BoundingVolume;
using value_type = Value;

BasicBoundingVolumeHierarchy() = default; // build an empty tree
BoundingVolumeHierarchy() = default; // build an empty tree

template <typename ExecutionSpace, typename Values,
typename SpaceFillingCurve = Experimental::Morton64>
BasicBoundingVolumeHierarchy(
BoundingVolumeHierarchy(
ExecutionSpace const &space, Values const &values,
IndexableGetter const &indexable_getter = IndexableGetter(),
SpaceFillingCurve const &curve = SpaceFillingCurve());
Expand Down Expand Up @@ -113,7 +114,7 @@ class BasicBoundingVolumeHierarchy
Predicate const &predicate,
Callback const &callback) const
{
ArborX::Details::TreeTraversal<BasicBoundingVolumeHierarchy,
ArborX::Details::TreeTraversal<BoundingVolumeHierarchy,
/* Predicates Dummy */ std::true_type,
Callback, typename Predicate::Tag>
tree_traversal(*this, callback);
Expand All @@ -135,15 +136,17 @@ class BasicBoundingVolumeHierarchy
IndexableGetter _indexable_getter;
};

// The partial template specialization parameters *must* match the default ones
template <typename MemorySpace>
class BoundingVolumeHierarchy
: public BasicBoundingVolumeHierarchy<MemorySpace,
Details::PairIndexVolume<Box>,
Details::DefaultIndexableGetter, Box>
class BoundingVolumeHierarchy<MemorySpace, Details::LegacyDefaultTemplateValue,
Details::DefaultIndexableGetter,
ExperimentalHyperGeometry::Box<3, float>>
: public BoundingVolumeHierarchy<MemorySpace, Details::PairIndexVolume<Box>,
Details::DefaultIndexableGetter, Box>
{
using base_type =
BasicBoundingVolumeHierarchy<MemorySpace, Details::PairIndexVolume<Box>,
Details::DefaultIndexableGetter, Box>;
BoundingVolumeHierarchy<MemorySpace, Details::PairIndexVolume<Box>,
Details::DefaultIndexableGetter, Box>;

public:
using bounding_volume_type = typename base_type::bounding_volume_type;
Expand Down Expand Up @@ -227,19 +230,26 @@ class BoundingVolumeHierarchy
}
};

template <typename MemorySpace>
using BVH = BoundingVolumeHierarchy<MemorySpace>;
template <
typename MemorySpace, typename Value = Details::LegacyDefaultTemplateValue,
typename IndexableGetter = Details::DefaultIndexableGetter,
typename BoundingVolume = ExperimentalHyperGeometry::Box<
GeometryTraits::dimension_v<
std::decay_t<std::invoke_result_t<IndexableGetter, Value>>>,
typename GeometryTraits::coordinate_type<
std::decay_t<std::invoke_result_t<IndexableGetter, Value>>>::type>>
using BVH = BoundingVolumeHierarchy<MemorySpace, Value, IndexableGetter,
BoundingVolume>;

template <typename MemorySpace, typename Value, typename IndexableGetter,
typename BoundingVolume>
template <typename ExecutionSpace, typename UserValues,
typename SpaceFillingCurve>
BasicBoundingVolumeHierarchy<MemorySpace, Value, IndexableGetter,
BoundingVolume>::
BasicBoundingVolumeHierarchy(ExecutionSpace const &space,
UserValues const &user_values,
IndexableGetter const &indexable_getter,
SpaceFillingCurve const &curve)
BoundingVolumeHierarchy<MemorySpace, Value, IndexableGetter, BoundingVolume>::
BoundingVolumeHierarchy(ExecutionSpace const &space,
UserValues const &user_values,
IndexableGetter const &indexable_getter,
SpaceFillingCurve const &curve)
: _size(AccessTraits<UserValues, PrimitivesTag>::size(user_values))
, _leaf_nodes(Kokkos::view_alloc(space, Kokkos::WithoutInitializing,
"ArborX::BVH::leaf_nodes"),
Expand Down Expand Up @@ -327,7 +337,7 @@ BasicBoundingVolumeHierarchy<MemorySpace, Value, IndexableGetter,
template <typename MemorySpace, typename Value, typename IndexableGetter,
typename BoundingVolume>
template <typename ExecutionSpace, typename Predicates, typename Callback>
void BasicBoundingVolumeHierarchy<
void BoundingVolumeHierarchy<
MemorySpace, Value, IndexableGetter,
BoundingVolume>::query(ExecutionSpace const &space,
Predicates const &predicates,
Expand Down
21 changes: 21 additions & 0 deletions src/details/ArborX_DetailsLegacy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,29 @@ struct LegacyDefaultCallback
}
};

struct LegacyDefaultTemplateValue
{};

} // namespace ArborX::Details

template <>
struct ArborX::GeometryTraits::dimension<
ArborX::Details::LegacyDefaultTemplateValue>
{
static constexpr int value = 3;
};
template <>
struct ArborX::GeometryTraits::tag<ArborX::Details::LegacyDefaultTemplateValue>
{
using type = BoxTag;
};
template <>
struct ArborX::GeometryTraits::coordinate_type<
ArborX::Details::LegacyDefaultTemplateValue>
{
using type = float;
};

template <typename Primitives, typename BoundingVolume>
struct ArborX::AccessTraits<
ArborX::Details::LegacyValues<Primitives, BoundingVolume>,
Expand Down
2 changes: 1 addition & 1 deletion src/details/ArborX_MinimumSpanningTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct MinimumSpanningTree
auto const n = points.size();

Kokkos::Profiling::pushRegion("ArborX::MST::construction");
BasicBoundingVolumeHierarchy<MemorySpace, PairIndexVolume<Point>> bvh(
BoundingVolumeHierarchy<MemorySpace, PairIndexVolume<Point>> bvh(
space, Details::LegacyValues<Points, Point>{points});
Kokkos::Profiling::popRegion();

Expand Down
23 changes: 13 additions & 10 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ set(ARBORX_TEST_QUERY_TREE_SOURCES)
foreach(_test Callbacks Degenerate ManufacturedSolution ComparisonWithBoost)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH.cpp.tmp"
"#include <ArborX_LinearBVH.hpp>\n"
"#include <ArborX_Box.hpp>\n"
"#include \"ArborXTest_LegacyTree.hpp\"\n"
"template <class MemorySpace>\n"
"using ArborX_Legacy_BasicBVH_Box =\n"
" LegacyTree<ArborX::BasicBoundingVolumeHierarchy<\n"
"using ArborX_BVH_Box = ArborX::BVH<MemorySpace>;\n"
"template <class MemorySpace>\n"
"using ArborX_Legacy_BVH_Box =\n"
" LegacyTree<ArborX::BoundingVolumeHierarchy<\n"
" MemorySpace, ArborX::Details::PairIndexVolume<ArborX::Box>,\n"
" ArborX::Details::DefaultIndexableGetter, ArborX::Box>>;\n"
"#define ARBORX_TEST_TREE_TYPES Tuple<ArborX::BVH, ArborX_Legacy_BasicBVH_Box>\n"
"#define ARBORX_TEST_TREE_TYPES Tuple<ArborX_BVH_Box, ArborX_Legacy_BVH_Box>\n"
"#define ARBORX_TEST_DEVICE_TYPES std::tuple<${ARBORX_DEVICE_TYPES}>\n"
"#include <tstQueryTree${_test}.cpp>\n"
)
Expand All @@ -92,13 +95,13 @@ foreach(_test Callbacks Degenerate ManufacturedSolution ComparisonWithBoost)
"#include <ArborX_Box.hpp>\n"
"#include \"ArborXTest_LegacyTree.hpp\"\n"
"template <class MemorySpace>\n"
"using ArborX_BruteForce_Box = ArborX::BruteForce<MemorySpace, ArborX::Box>;\n"
"using ArborX_BruteForce_Box = ArborX::BruteForce<MemorySpace>;\n"
"template <class MemorySpace>\n"
"using ArborX_Legacy_BasicBruteForce_Box =\n"
" LegacyTree<ArborX::BasicBruteForce<\n"
"using ArborX_Legacy_BruteForce_Box =\n"
" LegacyTree<ArborX::BruteForce<\n"
" MemorySpace, ArborX::Details::PairIndexVolume<ArborX::Box>,\n"
" ArborX::Details::DefaultIndexableGetter, ArborX::Box>>;\n"
"#define ARBORX_TEST_TREE_TYPES Tuple<ArborX_BruteForce_Box, ArborX_Legacy_BasicBruteForce_Box>\n"
"#define ARBORX_TEST_TREE_TYPES Tuple<ArborX_BruteForce_Box, ArborX_Legacy_BruteForce_Box>\n"
"#define ARBORX_TEST_DEVICE_TYPES std::tuple<${ARBORX_DEVICE_TYPES}>\n"
"#define ARBORX_TEST_DISABLE_NEAREST_QUERY\n"
"#define ARBORX_TEST_DISABLE_CALLBACK_EARLY_EXIT\n"
Expand All @@ -119,11 +122,11 @@ foreach(_test Callbacks Degenerate ManufacturedSolution ComparisonWithBoost)
"using KDOP18 = ArborX::Experimental::KDOP<18>;\n"
"using KDOP26 = ArborX::Experimental::KDOP<26>;\n"
"template <class MemorySpace>\n"
"using ArborX_Legacy_BasicBVH_${_bounding_volume} =\n"
" LegacyTree<ArborX::BasicBoundingVolumeHierarchy<\n"
"using ArborX_Legacy_BVH_${_bounding_volume} =\n"
" LegacyTree<ArborX::BoundingVolumeHierarchy<\n"
" MemorySpace, ArborX::Details::PairIndexVolume<${_bounding_volume}>,\n"
" ArborX::Details::DefaultIndexableGetter, ${_bounding_volume}>>;\n"
"#define ARBORX_TEST_TREE_TYPES Tuple<ArborX_Legacy_BasicBVH_${_bounding_volume}>\n"
"#define ARBORX_TEST_TREE_TYPES Tuple<ArborX_Legacy_BVH_${_bounding_volume}>\n"
"#define ARBORX_TEST_DEVICE_TYPES std::tuple<${ARBORX_DEVICE_TYPES}>\n"
"#define ARBORX_TEST_DISABLE_NEAREST_QUERY\n"
"#define ARBORX_TEST_DISABLE_SPATIAL_QUERY_INTERSECTS_SPHERE\n"
Expand Down
7 changes: 4 additions & 3 deletions test/tstCompileOnlyTypeRequirements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ void check_bounding_volume_and_predicate_geometry_type_requirements()
{
using ExecutionSpace = Kokkos::DefaultExecutionSpace;
using MemorySpace = ExecutionSpace::memory_space;
using Tree = ArborX::BasicBoundingVolumeHierarchy<
MemorySpace, Test::PrimitivePointOrBox,
ArborX::Details::DefaultIndexableGetter, Test::FakeBoundingVolume>;
using Tree =
ArborX::BoundingVolumeHierarchy<MemorySpace, Test::PrimitivePointOrBox,
ArborX::Details::DefaultIndexableGetter,
Test::FakeBoundingVolume>;

Kokkos::View<Test::PrimitivePointOrBox *, MemorySpace> primitives(
"primitives", 0);
Expand Down
2 changes: 1 addition & 1 deletion test/tstDetailsMutualReachabilityDistance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ auto compute_core_distances(ExecutionSpace exec_space,

ARBORX_ASSERT(points.extent_int(0) >= k);
using MemorySpace = typename ExecutionSpace::memory_space;
ArborX::BasicBoundingVolumeHierarchy<
ArborX::BoundingVolumeHierarchy<
MemorySpace, ArborX::Details::PairIndexVolume<ArborX::Point>>
bvh{exec_space,
ArborX::Details::LegacyValues<decltype(points), ArborX::Point>{
Expand Down

0 comments on commit 528631b

Please sign in to comment.