From bbd63ae48a560cc642fd1e0f7bd2e2161a033966 Mon Sep 17 00:00:00 2001 From: Andrey Prokopenko Date: Fri, 20 Sep 2024 09:52:24 -0400 Subject: [PATCH] Switch spheres to new hyper-dimensional ones (#1146) --- .../brute_force_vs_bvh_timpl.hpp | 8 +-- .../execution_space_instances_driver.cpp | 4 +- .../example_cuda_access_traits.cpp | 2 +- examples/brute_force/example_brute_force.cpp | 3 +- .../example_molecular_dynamics.cpp | 3 +- src/ArborX_DBSCAN.hpp | 7 +- ...X_DetailsDistributedTreeNearestHelpers.hpp | 3 +- src/details/ArborX_NeighborList.hpp | 5 +- src/details/ArborX_PredicateHelpers.hpp | 5 +- src/geometry/ArborX_HyperSphere.hpp | 68 ------------------- src/geometry/ArborX_Ray.hpp | 6 +- src/geometry/ArborX_Sphere.hpp | 44 ++++++------ test/ArborX_BoostRTreeHelpers.hpp | 21 +----- test/Search_UnitTestHelpers.hpp | 6 +- test/tstCompileOnlyGeometry.cpp | 2 +- test/tstDetailsAlgorithms.cpp | 4 +- test/tstDistributedTreeSpatial.cpp | 12 ++-- test/tstQueryTreeComparisonWithBoost.cpp | 2 +- test/tstRay.cpp | 6 +- 19 files changed, 56 insertions(+), 155 deletions(-) delete mode 100644 src/geometry/ArborX_HyperSphere.hpp diff --git a/benchmarks/brute_force_vs_bvh/brute_force_vs_bvh_timpl.hpp b/benchmarks/brute_force_vs_bvh/brute_force_vs_bvh_timpl.hpp index ddde9b3da..a93a5c338 100644 --- a/benchmarks/brute_force_vs_bvh/brute_force_vs_bvh_timpl.hpp +++ b/benchmarks/brute_force_vs_bvh/brute_force_vs_bvh_timpl.hpp @@ -10,9 +10,9 @@ ****************************************************************************/ #include -#include #include #include +#include #include @@ -64,11 +64,7 @@ struct ArborX::AccessTraits, ArborX::Point center; for (int d = 0; d < DIM; ++d) center[d] = i; - return attach( - intersects( - ArborX::ExperimentalHyperGeometry::Sphere{ - center, (FloatingPoint)i}), - i); + return attach(intersects(ArborX::Sphere{center, (FloatingPoint)i}), i); } }; diff --git a/benchmarks/execution_space_instances/execution_space_instances_driver.cpp b/benchmarks/execution_space_instances/execution_space_instances_driver.cpp index 94bf99ff9..5197153b6 100644 --- a/benchmarks/execution_space_instances/execution_space_instances_driver.cpp +++ b/benchmarks/execution_space_instances/execution_space_instances_driver.cpp @@ -9,9 +9,9 @@ * SPDX-License-Identifier: BSD-3-Clause * ****************************************************************************/ -#include #include #include +#include #include #include @@ -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 primitives( Kokkos::view_alloc(Kokkos::WithoutInitializing, "Benchmark::primitives"), diff --git a/examples/access_traits/example_cuda_access_traits.cpp b/examples/access_traits/example_cuda_access_traits.cpp index ec1bcbb97..e07d1c999 100644 --- a/examples/access_traits/example_cuda_access_traits.cpp +++ b/examples/access_traits/example_cuda_access_traits.cpp @@ -55,7 +55,7 @@ struct ArborX::AccessTraits 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; }; diff --git a/examples/brute_force/example_brute_force.cpp b/examples/brute_force/example_brute_force.cpp index 219254bf2..3e29162c3 100644 --- a/examples/brute_force/example_brute_force.cpp +++ b/examples/brute_force/example_brute_force.cpp @@ -45,8 +45,7 @@ struct ArborX::AccessTraits 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}); } }; diff --git a/examples/molecular_dynamics/example_molecular_dynamics.cpp b/examples/molecular_dynamics/example_molecular_dynamics.cpp index 4f541be34..413d407d0 100644 --- a/examples/molecular_dynamics/example_molecular_dynamics.cpp +++ b/examples/molecular_dynamics/example_molecular_dynamics.cpp @@ -34,8 +34,7 @@ struct ArborX::AccessTraits, ArborX::PredicatesTag> } static KOKKOS_FUNCTION auto get(Neighbors const &x, size_type i) { - return intersects( - ExperimentalHyperGeometry::Sphere{x._particles(i), x._radius}); + return intersects(Sphere{x._particles(i), x._radius}); } }; diff --git a/src/ArborX_DBSCAN.hpp b/src/ArborX_DBSCAN.hpp index 4eb5742ea..a54522529 100644 --- a/src/ArborX_DBSCAN.hpp +++ b/src/ArborX_DBSCAN.hpp @@ -22,7 +22,6 @@ #include #include // sortObjects #include -#include #include #include #include @@ -67,7 +66,7 @@ struct WithinRadiusGetter auto const &hyper_point = reinterpret_cast<::ArborX::Point const &>(pair.value); using ArborX::intersects; - return intersects(ExperimentalHyperGeometry::Sphere{hyper_point, _r}); + return intersects(Sphere{hyper_point, _r}); } }; @@ -119,9 +118,7 @@ struct AccessTraits const &>(point); - return attach( - intersects(ExperimentalHyperGeometry::Sphere{hyper_point, w._r}), - (int)index); + return attach(intersects(Sphere{hyper_point, w._r}), (int)index); } }; diff --git a/src/details/ArborX_DetailsDistributedTreeNearestHelpers.hpp b/src/details/ArborX_DetailsDistributedTreeNearestHelpers.hpp index a0bb65e91..7bf1428ec 100644 --- a/src/details/ArborX_DetailsDistributedTreeNearestHelpers.hpp +++ b/src/details/ArborX_DetailsDistributedTreeNearestHelpers.hpp @@ -110,8 +110,7 @@ struct approx_expand_by_radius { constexpr int DIM = GeometryTraits::dimension_v; using Coordinate = GeometryTraits::coordinate_type_t; - return ExperimentalHyperGeometry::Sphere{ - Kokkos::bit_cast<::ArborX::Point>(point), r}; + return Sphere{Kokkos::bit_cast<::ArborX::Point>(point), r}; } }; diff --git a/src/details/ArborX_NeighborList.hpp b/src/details/ArborX_NeighborList.hpp index 3cb57abf6..5b26dbcf4 100644 --- a/src/details/ArborX_NeighborList.hpp +++ b/src/details/ArborX_NeighborList.hpp @@ -16,8 +16,8 @@ #include #include // reallocWithoutInitializing #include -#include #include +#include #include @@ -39,8 +39,7 @@ struct NeighborListPredicateGetter auto const &hyper_point = reinterpret_cast<::ArborX::Point const &>(pair.value); - return intersects(ExperimentalHyperGeometry::Sphere{ - hyper_point, _radius}); + return intersects(Sphere{hyper_point, _radius}); } }; diff --git a/src/details/ArborX_PredicateHelpers.hpp b/src/details/ArborX_PredicateHelpers.hpp index 4180f5e3b..c0b4af39f 100644 --- a/src/details/ArborX_PredicateHelpers.hpp +++ b/src/details/ArborX_PredicateHelpers.hpp @@ -13,8 +13,8 @@ #include #include -#include #include +#include namespace ArborX { @@ -173,8 +173,7 @@ struct AccessTraits, // point structure (e.g., struct MyPoint { float y; float x; }) auto const &hyper_point = reinterpret_cast<::ArborX::Point const &>(point); - return intersects( - ExperimentalHyperGeometry::Sphere(hyper_point, x._r)); + return intersects(Sphere(hyper_point, x._r)); } }; diff --git a/src/geometry/ArborX_HyperSphere.hpp b/src/geometry/ArborX_HyperSphere.hpp deleted file mode 100644 index 3a377f294..000000000 --- a/src/geometry/ArborX_HyperSphere.hpp +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** - * 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 * - ****************************************************************************/ -#ifndef ARBORX_HYPERSPHERE_HPP -#define ARBORX_HYPERSPHERE_HPP - -#include -#include - -#include - -namespace ArborX::ExperimentalHyperGeometry -{ - -template -struct Sphere -{ - KOKKOS_DEFAULTED_FUNCTION - Sphere() = default; - - KOKKOS_FUNCTION - constexpr Sphere(Point const ¢roid, Coordinate radius) - : _centroid(centroid) - , _radius(radius) - {} - - KOKKOS_FUNCTION - constexpr auto ¢roid() { return _centroid; } - - KOKKOS_FUNCTION - constexpr auto const ¢roid() const { return _centroid; } - - KOKKOS_FUNCTION - constexpr auto radius() const { return _radius; } - - Point _centroid = {}; - Coordinate _radius = 0; -}; - -} // namespace ArborX::ExperimentalHyperGeometry - -template -struct ArborX::GeometryTraits::dimension< - ArborX::ExperimentalHyperGeometry::Sphere> -{ - static constexpr int value = DIM; -}; -template -struct ArborX::GeometryTraits::tag< - ArborX::ExperimentalHyperGeometry::Sphere> -{ - using type = SphereTag; -}; -template -struct ArborX::GeometryTraits::coordinate_type< - ArborX::ExperimentalHyperGeometry::Sphere> -{ - using type = Coordinate; -}; - -#endif diff --git a/src/geometry/ArborX_Ray.hpp b/src/geometry/ArborX_Ray.hpp index 721e43a80..2e1ae93ef 100644 --- a/src/geometry/ArborX_Ray.hpp +++ b/src/geometry/ArborX_Ray.hpp @@ -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; @@ -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; diff --git a/src/geometry/ArborX_Sphere.hpp b/src/geometry/ArborX_Sphere.hpp index 216b53576..3398a92fb 100644 --- a/src/geometry/ArborX_Sphere.hpp +++ b/src/geometry/ArborX_Sphere.hpp @@ -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 #include @@ -19,47 +19,47 @@ namespace ArborX { +template struct Sphere { KOKKOS_DEFAULTED_FUNCTION Sphere() = default; - KOKKOS_INLINE_FUNCTION - constexpr Sphere(Point<3> const ¢roid, - double radius) // FIXME + KOKKOS_FUNCTION + constexpr Sphere(Point const ¢roid, Coordinate radius) : _centroid(centroid) - , _radius(static_cast(radius)) + , _radius(radius) {} - KOKKOS_INLINE_FUNCTION + KOKKOS_FUNCTION constexpr auto ¢roid() { return _centroid; } - KOKKOS_INLINE_FUNCTION + KOKKOS_FUNCTION constexpr auto const ¢roid() 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 _centroid = {}; + Coordinate _radius = 0; }; -template <> -struct GeometryTraits::dimension +} // namespace ArborX + +template +struct ArborX::GeometryTraits::dimension> { - static constexpr int value = 3; + static constexpr int value = DIM; }; -template <> -struct GeometryTraits::tag +template +struct ArborX::GeometryTraits::tag> { using type = SphereTag; }; -template <> -struct ArborX::GeometryTraits::coordinate_type +template +struct ArborX::GeometryTraits::coordinate_type> { - using type = float; + using type = Coordinate; }; -} // namespace ArborX - #endif diff --git a/test/ArborX_BoostRTreeHelpers.hpp b/test/ArborX_BoostRTreeHelpers.hpp index 68b8a5ef1..fbba775ee 100644 --- a/test/ArborX_BoostRTreeHelpers.hpp +++ b/test/ArborX_BoostRTreeHelpers.hpp @@ -22,7 +22,6 @@ #include // exclusive_scan #include // lastElement #include -#include #include #include #ifdef ARBORX_ENABLE_MPI @@ -153,27 +152,9 @@ struct UnaryPredicate Function _pred; }; -template -static auto translate(ArborX::Intersects const &query) -{ - auto const sphere = getGeometry(query); - auto const radius = sphere.radius(); - auto const centroid = Kokkos::bit_cast>(sphere.centroid()); - ArborX::Box box; - ArborX::Details::expand(box, sphere); - return boost::geometry::index::intersects(box) && - boost::geometry::index::satisfies( - UnaryPredicate([centroid, radius](Value const &val) { - boost::geometry::index::indexable indexableGetter; - auto const &geometry = indexableGetter(val); - return boost::geometry::distance(centroid, geometry) <= radius; - })); -} - template static auto -translate(ArborX::Intersects> const &query) +translate(ArborX::Intersects> const &query) { auto const sphere = getGeometry(query); auto const radius = sphere.radius(); diff --git a/test/Search_UnitTestHelpers.hpp b/test/Search_UnitTestHelpers.hpp index 425881ef3..c4c9772a8 100644 --- a/test/Search_UnitTestHelpers.hpp +++ b/test/Search_UnitTestHelpers.hpp @@ -25,8 +25,8 @@ #include #endif #include -#include #include +#include #include @@ -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; + using Sphere = ArborX::Sphere; int const n = spheres.size(); Kokkos::View *, DeviceType> queries( Kokkos::view_alloc(Kokkos::WithoutInitializing, @@ -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; + using Sphere = ArborX::Sphere; int const n = points.size(); Kokkos::View queries( Kokkos::view_alloc(Kokkos::WithoutInitializing, diff --git a/test/tstCompileOnlyGeometry.cpp b/test/tstCompileOnlyGeometry.cpp index 62b69b5ca..b504ac5c1 100644 --- a/test/tstCompileOnlyGeometry.cpp +++ b/test/tstCompileOnlyGeometry.cpp @@ -187,7 +187,7 @@ struct coordinate_type 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>{}); diff --git a/test/tstDetailsAlgorithms.cpp b/test/tstDetailsAlgorithms.cpp index fcd76ed40..ce0856896 100644 --- a/test/tstDetailsAlgorithms.cpp +++ b/test/tstDetailsAlgorithms.cpp @@ -12,9 +12,9 @@ #include #include #include -#include #include #include +#include #include #include @@ -24,7 +24,7 @@ using Point = ArborX::Point<3>; using Box = ArborX::ExperimentalHyperGeometry::Box<3>; -using Sphere = ArborX::ExperimentalHyperGeometry::Sphere<3>; +using Sphere = ArborX::Sphere<3>; using Triangle = ArborX::ExperimentalHyperGeometry::Triangle<3>; using Tetrahedron = ArborX::ExperimentalHyperGeometry::Tetrahedron<>; diff --git a/test/tstDistributedTreeSpatial.cpp b/test/tstDistributedTreeSpatial.cpp index d08b8aa38..2023956fd 100644 --- a/test/tstDistributedTreeSpatial.cpp +++ b/test/tstDistributedTreeSpatial.cpp @@ -34,6 +34,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(hello_world_spatial, DeviceType, using Tree = ArborX::DistributedTree; using ExecutionSpace = typename DeviceType::execution_space; using Point = ArborX::Point<3>; + using Sphere = ArborX::Sphere<3>; MPI_Comm comm = MPI_COMM_WORLD; int comm_rank; @@ -68,11 +69,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(hello_world_spatial, DeviceType, // x x x x x | | | // |<------3------>| | | | // | | | | | - Kokkos::View - queries("Testing::queries", 1); + Kokkos::View queries( + "Testing::queries", 1); auto queries_host = Kokkos::create_mirror_view(queries); queries_host(0) = ArborX::intersects( - ArborX::Sphere{{{0.5f + comm_size - 1 - comm_rank, 0., 0.}}, 0.5}); + Sphere{{{0.5f + comm_size - 1 - comm_rank, 0., 0.}}, 0.5}); deep_copy(queries, queries_host); std::vector values; @@ -452,6 +453,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(boost_comparison, DeviceType, ARBORX_DEVICE_TYPES) using ExecutionSpace = typename DeviceType::execution_space; using Point = ArborX::Point<3>; using Box = ArborX::ExperimentalHyperGeometry::Box<3>; + using Sphere = ArborX::Sphere<3>; MPI_Comm comm = MPI_COMM_WORLD; int comm_rank; @@ -516,12 +518,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(boost_comparison, DeviceType, ARBORX_DEVICE_TYPES) Kokkos::deep_copy(point_coords, point_coords_host); Kokkos::deep_copy(radii, radii_host); - Kokkos::View + Kokkos::View within_queries("Testing::within_queries", local_n); Kokkos::parallel_for( "register_within_queries", Kokkos::RangePolicy(0, local_n), KOKKOS_LAMBDA(int i) { - within_queries(i) = ArborX::intersects(ArborX::Sphere{ + within_queries(i) = ArborX::intersects(Sphere{ {{point_coords(i, 0), point_coords(i, 1), point_coords(i, 2)}}, radii(i)}); }); diff --git a/test/tstQueryTreeComparisonWithBoost.cpp b/test/tstQueryTreeComparisonWithBoost.cpp index b75044034..a09e5d2ec 100644 --- a/test/tstQueryTreeComparisonWithBoost.cpp +++ b/test/tstQueryTreeComparisonWithBoost.cpp @@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(boost_rtree_spatial_predicate, TreeTypeTraits, Kokkos::deep_copy(radii, radii_host); - using Sphere = ArborX::ExperimentalHyperGeometry::Sphere<3>; + using Sphere = ArborX::Sphere<3>; Kokkos::View within_queries("within_queries", n_points); Kokkos::parallel_for( diff --git a/test/tstRay.cpp b/test/tstRay.cpp index f0cce5dce..b267f830c 100644 --- a/test/tstRay.cpp +++ b/test/tstRay.cpp @@ -280,9 +280,8 @@ BOOST_AUTO_TEST_CASE(ray_box_distance) BOOST_AUTO_TEST_CASE(overlap_distance_sphere, *boost::unit_test::tolerance(1e-6f)) { - using ArborX::Sphere; using ArborX::Experimental::Ray; - constexpr Sphere unit_sphere{{0, 0, 0}, 1}; + constexpr ArborX::Sphere<3> unit_sphere{{0, 0, 0}, 1}; auto const sqrtf_3 = std::sqrt(3.f); auto const half_sqrtf_2 = std::sqrt(2.f) / 2; @@ -366,10 +365,9 @@ BOOST_AUTO_TEST_CASE(overlap_distance_sphere, BOOST_AUTO_TEST_CASE(ray_sphere_intersection, *boost::unit_test::tolerance(1e-6f)) { - using ArborX::Sphere; using ArborX::Experimental::Ray; - constexpr Sphere unit_sphere{{0, 0, 0}, 1}; + constexpr ArborX::Sphere<3> unit_sphere{{0.f, 0.f, 0.f}, 1}; auto const sqrtf_3 = std::sqrt(3.f); auto const sqrtf_2 = std::sqrt(2.f);