Skip to content

Commit

Permalink
Switch spheres to new hyper-dimensional ones (#1146)
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop authored Sep 20, 2024
1 parent bc0588a commit bbd63ae
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 155 deletions.
8 changes: 2 additions & 6 deletions benchmarks/brute_force_vs_bvh/brute_force_vs_bvh_timpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
****************************************************************************/

#include <ArborX_BruteForce.hpp>
#include <ArborX_HyperSphere.hpp>
#include <ArborX_LinearBVH.hpp>
#include <ArborX_Point.hpp>
#include <ArborX_Sphere.hpp>

#include <Kokkos_Core.hpp>

Expand Down Expand Up @@ -64,11 +64,7 @@ struct ArborX::AccessTraits<ArborXBenchmark::Placeholder<DIM, FloatingPoint>,
ArborX::Point<DIM, FloatingPoint> center;
for (int d = 0; d < DIM; ++d)
center[d] = i;
return attach(
intersects(
ArborX::ExperimentalHyperGeometry::Sphere<DIM, FloatingPoint>{
center, (FloatingPoint)i}),
i);
return attach(intersects(ArborX::Sphere{center, (FloatingPoint)i}), i);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/

#include <ArborX_HyperSphere.hpp>
#include <ArborX_LinearBVH.hpp>
#include <ArborX_Point.hpp>
#include <ArborX_Sphere.hpp>
#include <ArborX_Version.hpp>

#include <Kokkos_Core.hpp>
Expand Down Expand Up @@ -144,7 +144,7 @@ int main(int argc, char *argv[])
};

using Point = ArborX::Point<3>;
using Sphere = ArborX::ExperimentalHyperGeometry::Sphere<3>;
using Sphere = ArborX::Sphere<3>;

Kokkos::View<Point *, MemorySpace> primitives(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "Benchmark::primitives"),
Expand Down
2 changes: 1 addition & 1 deletion examples/access_traits/example_cuda_access_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct ArborX::AccessTraits<Spheres, ArborX::PredicatesTag>
static KOKKOS_FUNCTION auto get(Spheres const &d, std::size_t i)
{
return ArborX::intersects(
ArborX::Sphere{{{d.d_x[i], d.d_y[i], d.d_z[i]}}, d.d_r[i]});
ArborX::Sphere{ArborX::Point{d.d_x[i], d.d_y[i], d.d_z[i]}, d.d_r[i]});
}
using memory_space = Kokkos::CudaSpace;
};
Expand Down
3 changes: 1 addition & 2 deletions examples/brute_force/example_brute_force.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ struct ArborX::AccessTraits<Dummy, ArborX::PredicatesTag>
static KOKKOS_FUNCTION auto get(Dummy const &, size_type i)
{
ArborX::Point center{(float)i, (float)i, (float)i};
return ArborX::intersects(
ExperimentalHyperGeometry::Sphere{center, (float)i});
return ArborX::intersects(Sphere{center, (float)i});
}
};

Expand Down
3 changes: 1 addition & 2 deletions examples/molecular_dynamics/example_molecular_dynamics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ struct ArborX::AccessTraits<Neighbors<MemorySpace>, ArborX::PredicatesTag>
}
static KOKKOS_FUNCTION auto get(Neighbors<MemorySpace> const &x, size_type i)
{
return intersects(
ExperimentalHyperGeometry::Sphere{x._particles(i), x._radius});
return intersects(Sphere{x._particles(i), x._radius});
}
};

Expand Down
7 changes: 2 additions & 5 deletions src/ArborX_DBSCAN.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <ArborX_DetailsSortUtils.hpp>
#include <ArborX_DetailsUtils.hpp> // sortObjects
#include <ArborX_HyperBox.hpp>
#include <ArborX_HyperSphere.hpp>
#include <ArborX_LinearBVH.hpp>
#include <ArborX_PredicateHelpers.hpp>
#include <ArborX_Sphere.hpp>
Expand Down Expand Up @@ -67,7 +66,7 @@ struct WithinRadiusGetter
auto const &hyper_point =
reinterpret_cast<::ArborX::Point<dim> const &>(pair.value);
using ArborX::intersects;
return intersects(ExperimentalHyperGeometry::Sphere<dim>{hyper_point, _r});
return intersects(Sphere{hyper_point, _r});
}
};

Expand Down Expand Up @@ -119,9 +118,7 @@ struct AccessTraits<Details::PrimitivesWithRadiusReorderedAndFiltered<
// point structure (e.g., struct MyPoint { float y; float x; })
auto const &hyper_point =
reinterpret_cast<::ArborX::Point<dim> const &>(point);
return attach(
intersects(ExperimentalHyperGeometry::Sphere<dim>{hyper_point, w._r}),
(int)index);
return attach(intersects(Sphere{hyper_point, w._r}), (int)index);
}
};

Expand Down
3 changes: 1 addition & 2 deletions src/details/ArborX_DetailsDistributedTreeNearestHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ struct approx_expand_by_radius<PointTag, Point>
{
constexpr int DIM = GeometryTraits::dimension_v<Box>;
using Coordinate = GeometryTraits::coordinate_type_t<Point>;
return ExperimentalHyperGeometry::Sphere<DIM, Coordinate>{
Kokkos::bit_cast<::ArborX::Point<DIM, Coordinate>>(point), r};
return Sphere{Kokkos::bit_cast<::ArborX::Point<DIM, Coordinate>>(point), r};
}
};

Expand Down
5 changes: 2 additions & 3 deletions src/details/ArborX_NeighborList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include <ArborX_DetailsKokkosExtStdAlgorithms.hpp>
#include <ArborX_DetailsKokkosExtViewHelpers.hpp> // reallocWithoutInitializing
#include <ArborX_GeometryTraits.hpp>
#include <ArborX_HyperSphere.hpp>
#include <ArborX_LinearBVH.hpp>
#include <ArborX_Sphere.hpp>

#include <Kokkos_Core.hpp>

Expand All @@ -39,8 +39,7 @@ struct NeighborListPredicateGetter

auto const &hyper_point =
reinterpret_cast<::ArborX::Point<dim, Coordinate> const &>(pair.value);
return intersects(ExperimentalHyperGeometry::Sphere<dim, Coordinate>{
hyper_point, _radius});
return intersects(Sphere{hyper_point, _radius});
}
};

Expand Down
5 changes: 2 additions & 3 deletions src/details/ArborX_PredicateHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#include <ArborX_AccessTraits.hpp>
#include <ArborX_GeometryTraits.hpp>
#include <ArborX_HyperSphere.hpp>
#include <ArborX_Predicates.hpp>
#include <ArborX_Sphere.hpp>

namespace ArborX
{
Expand Down Expand Up @@ -173,8 +173,7 @@ struct AccessTraits<Experimental::PrimitivesWithRadius<Primitives>,
// point structure (e.g., struct MyPoint { float y; float x; })
auto const &hyper_point =
reinterpret_cast<::ArborX::Point<dim, Coordinate> const &>(point);
return intersects(
ExperimentalHyperGeometry::Sphere<dim, Coordinate>(hyper_point, x._r));
return intersects(Sphere(hyper_point, x._r));
}
};

Expand Down
68 changes: 0 additions & 68 deletions src/geometry/ArborX_HyperSphere.hpp

This file was deleted.

6 changes: 3 additions & 3 deletions src/geometry/ArborX_Ray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ KOKKOS_INLINE_FUNCTION bool solveQuadratic(float const a, float const b,
// a2 = |d|^2, a1 = 2*(d, o - c), and a0 = |o - c|^2 - r^2.
// Then, we only need to intersect the solution interval [tmin, tmax] with
// [0, +inf) for the unidirectional ray.
KOKKOS_INLINE_FUNCTION bool intersection(Ray const &ray, Sphere const &sphere,
float &tmin, float &tmax)
KOKKOS_INLINE_FUNCTION bool
intersection(Ray const &ray, Sphere<3> const &sphere, float &tmin, float &tmax)
{
namespace KokkosExt = ArborX::Details::KokkosExt;

Expand Down Expand Up @@ -510,7 +510,7 @@ overlapDistance(Ray const &ray, Geometry const &geometry, float &length,
}

KOKKOS_INLINE_FUNCTION float overlapDistance(Ray const &ray,
Sphere const &sphere)
Sphere<3> const &sphere)
{
float distance_to_origin;
float length;
Expand Down
44 changes: 22 additions & 22 deletions src/geometry/ArborX_Sphere.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* *
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/
#ifndef ARBORX_Sphere_HPP
#define ARBORX_Sphere_HPP
#ifndef ARBORX_SPHERE_HPP
#define ARBORX_SPHERE_HPP

#include <ArborX_GeometryTraits.hpp>
#include <ArborX_Point.hpp>
Expand All @@ -19,47 +19,47 @@
namespace ArborX
{

template <int DIM, class Coordinate = float>
struct Sphere
{
KOKKOS_DEFAULTED_FUNCTION
Sphere() = default;

KOKKOS_INLINE_FUNCTION
constexpr Sphere(Point<3> const &centroid,
double radius) // FIXME
KOKKOS_FUNCTION
constexpr Sphere(Point<DIM, Coordinate> const &centroid, Coordinate radius)
: _centroid(centroid)
, _radius(static_cast<float>(radius))
, _radius(radius)
{}

KOKKOS_INLINE_FUNCTION
KOKKOS_FUNCTION
constexpr auto &centroid() { return _centroid; }

KOKKOS_INLINE_FUNCTION
KOKKOS_FUNCTION
constexpr auto const &centroid() const { return _centroid; }

KOKKOS_INLINE_FUNCTION
constexpr float radius() const { return _radius; }
KOKKOS_FUNCTION
constexpr auto radius() const { return _radius; }

Point<3> _centroid = {};
float _radius = 0.;
Point<DIM, Coordinate> _centroid = {};
Coordinate _radius = 0;
};

template <>
struct GeometryTraits::dimension<ArborX::Sphere>
} // namespace ArborX

template <int DIM, class Coordinate>
struct ArborX::GeometryTraits::dimension<ArborX::Sphere<DIM, Coordinate>>
{
static constexpr int value = 3;
static constexpr int value = DIM;
};
template <>
struct GeometryTraits::tag<ArborX::Sphere>
template <int DIM, class Coordinate>
struct ArborX::GeometryTraits::tag<ArborX::Sphere<DIM, Coordinate>>
{
using type = SphereTag;
};
template <>
struct ArborX::GeometryTraits::coordinate_type<ArborX::Sphere>
template <int DIM, class Coordinate>
struct ArborX::GeometryTraits::coordinate_type<ArborX::Sphere<DIM, Coordinate>>
{
using type = float;
using type = Coordinate;
};

} // namespace ArborX

#endif
21 changes: 1 addition & 20 deletions test/ArborX_BoostRTreeHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <ArborX_DetailsKokkosExtStdAlgorithms.hpp> // exclusive_scan
#include <ArborX_DetailsKokkosExtViewHelpers.hpp> // lastElement
#include <ArborX_HyperBox.hpp>
#include <ArborX_HyperSphere.hpp>
#include <ArborX_Predicates.hpp>
#include <ArborX_Sphere.hpp>
#ifdef ARBORX_ENABLE_MPI
Expand Down Expand Up @@ -153,27 +152,9 @@ struct UnaryPredicate
Function _pred;
};

template <typename Value>
static auto translate(ArborX::Intersects<ArborX::Sphere> const &query)
{
auto const sphere = getGeometry(query);
auto const radius = sphere.radius();
auto const centroid = Kokkos::bit_cast<ArborX::Point<3>>(sphere.centroid());
ArborX::Box box;
ArborX::Details::expand(box, sphere);
return boost::geometry::index::intersects(box) &&
boost::geometry::index::satisfies(
UnaryPredicate<Value>([centroid, radius](Value const &val) {
boost::geometry::index::indexable<Value> indexableGetter;
auto const &geometry = indexableGetter(val);
return boost::geometry::distance(centroid, geometry) <= radius;
}));
}

template <typename Value, int DIM, typename Coordinate>
static auto
translate(ArborX::Intersects<ArborX::ExperimentalHyperGeometry::Sphere<
DIM, Coordinate>> const &query)
translate(ArborX::Intersects<ArborX::Sphere<DIM, Coordinate>> const &query)
{
auto const sphere = getGeometry(query);
auto const radius = sphere.radius();
Expand Down
6 changes: 3 additions & 3 deletions test/Search_UnitTestHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include <ArborX_DistributedTree.hpp>
#endif
#include <ArborX_Box.hpp>
#include <ArborX_HyperSphere.hpp>
#include <ArborX_Point.hpp>
#include <ArborX_Sphere.hpp>

#include <boost/test/unit_test.hpp>

Expand Down Expand Up @@ -242,7 +242,7 @@ auto makeSphereNearestQueries(
// NOTE: `sphere` is not a very descriptive name here. It stores both the
// center and the radius of the sphere and the number k of neighbors to query
// for.
using Sphere = ArborX::ExperimentalHyperGeometry::Sphere<DIM, Coordinate>;
using Sphere = ArborX::Sphere<DIM, Coordinate>;
int const n = spheres.size();
Kokkos::View<ArborX::Nearest<Sphere> *, DeviceType> queries(
Kokkos::view_alloc(Kokkos::WithoutInitializing,
Expand Down Expand Up @@ -291,7 +291,7 @@ auto makeIntersectsSphereQueries(
{
// NOTE: `points` is not a very descriptive name here. It stores both the
// actual point and the radius for the search around that point.
using Sphere = ArborX::ExperimentalHyperGeometry::Sphere<DIM, Coordinate>;
using Sphere = ArborX::Sphere<DIM, Coordinate>;
int const n = points.size();
Kokkos::View<decltype(ArborX::intersects(Sphere{})) *, DeviceType> queries(
Kokkos::view_alloc(Kokkos::WithoutInitializing,
Expand Down
2 changes: 1 addition & 1 deletion test/tstCompileOnlyGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ struct coordinate_type<CorrectSpecialization>
void test_geometry_compile_only()
{
check_valid_geometry_traits(ArborX::Box{});
check_valid_geometry_traits(ArborX::Sphere{});
check_valid_geometry_traits(ArborX::Sphere<3>{});

check_valid_geometry_traits(ArborX::Point<3>{});

Expand Down
Loading

0 comments on commit bbd63ae

Please sign in to comment.