Skip to content

Commit

Permalink
Get rid of APIv1 in BVH
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop committed Sep 26, 2024
1 parent c44f9c3 commit 2085d66
Show file tree
Hide file tree
Showing 19 changed files with 272 additions and 355 deletions.
2 changes: 1 addition & 1 deletion src/ArborX_BruteForce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
#include <ArborX_AccessTraits.hpp>
#include <ArborX_AttachIndices.hpp>
#include <ArborX_Box.hpp>
#include <ArborX_Callbacks.hpp>
#include <ArborX_CrsGraphWrapper.hpp>
#include <ArborX_DetailsBruteForceImpl.hpp>
#include <ArborX_DetailsCrsGraphWrapperImpl.hpp>
#include <ArborX_DetailsKokkosExtAccessibilityTraits.hpp>
#include <ArborX_DetailsLegacy.hpp>
#include <ArborX_IndexableGetter.hpp>
#include <ArborX_PairValueIndex.hpp>
#include <ArborX_PredicateHelpers.hpp>
Expand Down
125 changes: 14 additions & 111 deletions src/ArborX_LinearBVH.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <ArborX_DetailsBatchedQueries.hpp>
#include <ArborX_DetailsCrsGraphWrapperImpl.hpp>
#include <ArborX_DetailsKokkosExtAccessibilityTraits.hpp>
#include <ArborX_DetailsLegacy.hpp>
#include <ArborX_DetailsNode.hpp>
#include <ArborX_DetailsPermutedData.hpp>
#include <ArborX_DetailsSortUtils.hpp>
Expand Down Expand Up @@ -49,14 +48,13 @@ namespace Details
struct HappyTreeFriends;
} // namespace Details

template <
typename MemorySpace, typename Value = Details::LegacyDefaultTemplateValue,
typename IndexableGetter = Details::DefaultIndexableGetter,
typename BoundingVolume =
Box<GeometryTraits::dimension_v<
std::decay_t<std::invoke_result_t<IndexableGetter, Value>>>,
typename GeometryTraits::coordinate_type_t<
std::decay_t<std::invoke_result_t<IndexableGetter, Value>>>>>
template <typename MemorySpace, typename Value,
typename IndexableGetter = Details::DefaultIndexableGetter,
typename BoundingVolume = Box<
GeometryTraits::dimension_v<
std::decay_t<std::invoke_result_t<IndexableGetter, Value>>>,
typename GeometryTraits::coordinate_type_t<
std::decay_t<std::invoke_result_t<IndexableGetter, Value>>>>>
class BoundingVolumeHierarchy
{
public:
Expand Down Expand Up @@ -170,108 +168,13 @@ class BoundingVolumeHierarchy
IndexableGetter _indexable_getter;
};

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

public:
using bounding_volume_type = typename base_type::bounding_volume_type;

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

template <typename ExecutionSpace, typename Primitives,
typename SpaceFillingCurve = Experimental::Morton64>
BoundingVolumeHierarchy(ExecutionSpace const &space,
Primitives const &primitives,
SpaceFillingCurve const &curve = SpaceFillingCurve())
: base_type(
space,
// Validate the primitives before calling the base constructor
(Details::check_valid_access_traits(PrimitivesTag{}, primitives),
Details::LegacyValues<Primitives, bounding_volume_type>{
primitives}),
Details::DefaultIndexableGetter(), curve)
{}

template <typename ExecutionSpace, typename Predicates, typename Callback>
void query(ExecutionSpace const &space, Predicates const &predicates,
Callback const &callback,
Experimental::TraversalPolicy const &policy =
Experimental::TraversalPolicy()) const
{
Details::check_valid_callback<int>(callback, predicates);
base_type::query(space, predicates,
Details::LegacyCallbackWrapper<Callback>{callback},
policy);
}

template <typename ExecutionSpace, typename Predicates, typename View,
typename... Args>
std::enable_if_t<Kokkos::is_view_v<std::decay_t<View>>>
query(ExecutionSpace const &space, Predicates const &predicates, View &&view,
Args &&...args) const
{
base_type::query(space, predicates, Details::LegacyDefaultCallback{},
std::forward<View>(view), std::forward<Args>(args)...);
}

template <typename ExecutionSpace, typename Predicates, typename Callback,
typename OutputView, typename OffsetView, typename... Args>
std::enable_if_t<!Kokkos::is_view_v<std::decay_t<Callback>>>
query(ExecutionSpace const &space, Predicates const &predicates,
Callback &&callback, OutputView &&out, OffsetView &&offset,
Args &&...args) const
{
if constexpr (!Details::is_tagged_post_callback<
std::decay_t<Callback>>::value)
{
Details::check_valid_callback<int>(callback, predicates, out);
base_type::query(space, predicates,
Details::LegacyCallbackWrapper<std::decay_t<Callback>>{
std::forward<Callback>(callback)},
std::forward<OutputView>(out),
std::forward<OffsetView>(offset),
std::forward<Args>(args)...);
}
else
{
Kokkos::Profiling::ScopedRegion guard("ArborX::BVH::query_crs");

Kokkos::View<int *, MemorySpace> indices(
"ArborX::CrsGraphWrapper::query::indices", 0);
base_type::query(space, predicates, Details::LegacyDefaultCallback{},
indices, std::forward<OffsetView>(offset),
std::forward<Args>(args)...);
callback(predicates, std::forward<OffsetView>(offset), indices,
std::forward<OutputView>(out));
}
}

template <typename Predicate, typename Callback>
KOKKOS_FUNCTION void query(Experimental::PerThread tag,
Predicate const &predicate,
Callback const &callback) const
{
base_type::query(tag, predicate, callback);
}
};

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

Expand Down
16 changes: 16 additions & 0 deletions src/details/ArborX_Callbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define ARBORX_CALLBACKS_HPP

#include <ArborX_AccessTraits.hpp>
#include <ArborX_PairValueIndex.hpp>
#include <ArborX_Predicates.hpp> // is_valid_predicate_tag

#include <Kokkos_DetectionIdiom.hpp>
Expand Down Expand Up @@ -44,6 +45,21 @@ struct DefaultCallback
}
};

struct LegacyDefaultCallback
{
template <typename Query, typename Value, typename Index,
typename OutputFunctor>
KOKKOS_FUNCTION void operator()(Query const &,
PairValueIndex<Value, Index> const &value,
OutputFunctor const &output) const
{
// APIv1 callback has the signature operator()(Query, int)
// As we store PairValueIndex with potentially non int index (like
// unsigned), we explicitly cast it here.
output((int)value.index);
}
};

// archetypal alias for a 'tag' type member in user callbacks
template <typename Callback>
using CallbackTagArchetypeAlias = typename Callback::tag;
Expand Down
159 changes: 0 additions & 159 deletions src/details/ArborX_DetailsLegacy.hpp

This file was deleted.

9 changes: 9 additions & 0 deletions src/geometry/ArborX_DetailsAlgorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ struct distance<PointTag, BoxTag, Point, Box>
}
};

template <typename Box, typename Point>
struct distance<BoxTag, PointTag, Box, Point>
{
KOKKOS_FUNCTION static auto apply(Box const &box, Point const &point)
{
return Details::distance(point, box);
}
};

// distance point-sphere
template <typename Point, typename Sphere>
struct distance<PointTag, SphereTag, Point, Sphere>
Expand Down
10 changes: 10 additions & 0 deletions src/geometry/ArborX_KDOP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,16 @@ struct intersects<PointTag, KDOPTag, Point, KDOP>
}
};

template <typename KDOP, typename Point>
struct intersects<KDOPTag, PointTag, KDOP, Point>
{
KOKKOS_FUNCTION static constexpr bool apply(KDOP const &kdop,
Point const &point)
{
return Details::intersects(point, kdop);
}
};

template <typename KDOP1, typename KDOP2>
struct intersects<KDOPTag, KDOPTag, KDOP1, KDOP2>
{
Expand Down
1 change: 0 additions & 1 deletion src/interpolation/ArborX_InterpMovingLeastSquares.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include <ArborX_AccessTraits.hpp>
#include <ArborX_Box.hpp>
#include <ArborX_DetailsLegacy.hpp>
#include <ArborX_GeometryTraits.hpp>
#include <ArborX_IndexableGetter.hpp>
#include <ArborX_InterpDetailsCompactRadialBasisFunction.hpp>
Expand Down
Loading

0 comments on commit 2085d66

Please sign in to comment.