From 4fb3a910dbc8d81d2de250f0a3ec9c6245160d4d Mon Sep 17 00:00:00 2001 From: Andrey Prokopenko Date: Sat, 5 Oct 2024 04:44:58 -0400 Subject: [PATCH] Remove PrimitivesTag and PredicatesTag --- .../brute_force_vs_bvh_timpl.hpp | 53 ++++--- .../bvh_driver/benchmark_registration.hpp | 2 +- .../dbscan/ArborX_DBSCANVerification.hpp | 2 +- .../triangulated_surface_distance.cpp | 2 +- .../example_cuda_access_traits.cpp | 4 +- .../example_host_access_traits.cpp | 4 +- examples/brute_force/example_brute_force.cpp | 4 +- examples/callback/example_callback.cpp | 4 +- .../example_molecular_dynamics.cpp | 2 +- examples/raytracing/example_raytracing.cpp | 3 +- src/cluster/ArborX_DBSCAN.hpp | 11 +- src/cluster/ArborX_MinimumSpanningTree.hpp | 4 +- src/distributed/ArborX_DistributedTree.hpp | 8 +- .../ArborX_DistributedTreeNearestHelpers.hpp | 2 +- .../ArborX_InterpMovingLeastSquares.hpp | 10 +- src/spatial/ArborX_BruteForce.hpp | 29 ++-- src/spatial/ArborX_LinearBVH.hpp | 23 ++- src/spatial/detail/ArborX_AccessTraits.hpp | 132 ++++++------------ src/spatial/detail/ArborX_AttachIndices.hpp | 38 ++--- src/spatial/detail/ArborX_Callbacks.hpp | 6 +- src/spatial/detail/ArborX_NeighborList.hpp | 4 +- src/spatial/detail/ArborX_PermutedData.hpp | 7 +- .../detail/ArborX_PredicateHelpers.hpp | 30 ++-- test/ArborXTest_LegacyTree.hpp | 5 +- test/ArborX_BoostRTreeHelpers.hpp | 3 +- test/tstAttachIndices.cpp | 6 +- test/tstCompileOnlyAccessTraits.cpp | 101 +++++++++----- test/tstCompileOnlyCallbacks.cpp | 4 +- test/tstDBSCAN.cpp | 2 +- test/tstDetailsCrsGraphWrapperImpl.cpp | 2 +- test/tstIndexableGetter.cpp | 11 +- test/tstQueryTreeIntersectsKDOP.cpp | 2 +- 32 files changed, 239 insertions(+), 281 deletions(-) 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 6440f0de9..a0ba35dea 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 @@ -23,44 +23,51 @@ using MemorySpace = ExecutionSpace::memory_space; namespace ArborXBenchmark { -template +struct PrimitivesTag +{}; +struct PredicatesTag +{}; + +template struct Placeholder { int count; }; } // namespace ArborXBenchmark -// Primitives are a set of points located at (i, i, i), -// with i = 0, ..., n-1 -template -struct ArborX::AccessTraits, - ArborX::PrimitivesTag> +template +struct ArborX::AccessTraits< + ArborXBenchmark::Placeholder> { - using Primitives = ArborXBenchmark::Placeholder; using memory_space = MemorySpace; using size_type = typename MemorySpace::size_type; - static KOKKOS_FUNCTION size_type size(Primitives d) { return d.count; } - static KOKKOS_FUNCTION auto get(Primitives, size_type i) + + static KOKKOS_FUNCTION size_type + size(ArborXBenchmark::Placeholder d) + { + return d.count; + } + + static KOKKOS_FUNCTION auto + get(ArborXBenchmark::Placeholder, + size_type i) { + // Primitives are a set of points located at (i, i, i), + // with i = 0, ..., n-1 ArborX::Point point; for (int d = 0; d < DIM; ++d) point[d] = i; return point; } -}; -// Predicates are sphere intersections with spheres of radius i -// centered at (i, i, i), with i = 0, ..., n-1 -template -struct ArborX::AccessTraits, - ArborX::PredicatesTag> -{ - using Predicates = ArborXBenchmark::Placeholder; - using memory_space = MemorySpace; - using size_type = typename MemorySpace::size_type; - static KOKKOS_FUNCTION size_type size(Predicates d) { return d.count; } - static KOKKOS_FUNCTION auto get(Predicates, size_type i) + static KOKKOS_FUNCTION auto + get(ArborXBenchmark::Placeholder, + size_type i) { + // Predicates are sphere intersections with spheres of radius i + // centered at (i, i, i), with i = 0, ..., n-1 ArborX::Point center; for (int d = 0; d < DIM; ++d) center[d] = i; @@ -76,8 +83,8 @@ static void run_fp(int nprimitives, int nqueries, int nrepeats) { ExecutionSpace space{}; - Placeholder primitives{nprimitives}; - Placeholder predicates{nqueries}; + Placeholder primitives{nprimitives}; + Placeholder predicates{nqueries}; using Point = ArborX::Point; for (int i = 0; i < nrepeats; i++) diff --git a/benchmarks/bvh_driver/benchmark_registration.hpp b/benchmarks/bvh_driver/benchmark_registration.hpp index f22991d83..64af011b8 100644 --- a/benchmarks/bvh_driver/benchmark_registration.hpp +++ b/benchmarks/bvh_driver/benchmark_registration.hpp @@ -41,7 +41,7 @@ struct Iota }; template -struct ArborX::AccessTraits, ArborX::PrimitivesTag> +struct ArborX::AccessTraits> { using Self = Iota; diff --git a/benchmarks/dbscan/ArborX_DBSCANVerification.hpp b/benchmarks/dbscan/ArborX_DBSCANVerification.hpp index d98bf4970..f45e02b61 100644 --- a/benchmarks/dbscan/ArborX_DBSCANVerification.hpp +++ b/benchmarks/dbscan/ArborX_DBSCANVerification.hpp @@ -294,7 +294,7 @@ bool verifyDBSCAN(ExecutionSpace exec_space, Primitives const &primitives, static_assert(Kokkos::is_view{}); - using Points = Details::AccessValues; + using Points = Details::AccessValues; using MemorySpace = typename Points::memory_space; static_assert(std::is_same{}); diff --git a/benchmarks/triangulated_surface_distance/triangulated_surface_distance.cpp b/benchmarks/triangulated_surface_distance/triangulated_surface_distance.cpp index 6e0dfefdc..020b17101 100644 --- a/benchmarks/triangulated_surface_distance/triangulated_surface_distance.cpp +++ b/benchmarks/triangulated_surface_distance/triangulated_surface_distance.cpp @@ -35,7 +35,7 @@ struct Triangles }; template -class ArborX::AccessTraits, ArborX::PrimitivesTag> +class ArborX::AccessTraits> { using Self = Triangles; diff --git a/examples/access_traits/example_cuda_access_traits.cpp b/examples/access_traits/example_cuda_access_traits.cpp index 2aa275a15..2a1388d07 100644 --- a/examples/access_traits/example_cuda_access_traits.cpp +++ b/examples/access_traits/example_cuda_access_traits.cpp @@ -35,7 +35,7 @@ struct Spheres }; template <> -struct ArborX::AccessTraits +struct ArborX::AccessTraits { static KOKKOS_FUNCTION std::size_t size(PointCloud const &cloud) { @@ -49,7 +49,7 @@ struct ArborX::AccessTraits }; template <> -struct ArborX::AccessTraits +struct ArborX::AccessTraits { static KOKKOS_FUNCTION std::size_t size(Spheres const &d) { return d.N; } static KOKKOS_FUNCTION auto get(Spheres const &d, std::size_t i) diff --git a/examples/access_traits/example_host_access_traits.cpp b/examples/access_traits/example_host_access_traits.cpp index 30795fb72..4f444e010 100644 --- a/examples/access_traits/example_host_access_traits.cpp +++ b/examples/access_traits/example_host_access_traits.cpp @@ -17,8 +17,8 @@ #include #include -template -struct ArborX::AccessTraits, Tag> +template +struct ArborX::AccessTraits> { static std::size_t size(std::vector const &v) { return v.size(); } static T const &get(std::vector const &v, std::size_t i) { return v[i]; } diff --git a/examples/brute_force/example_brute_force.cpp b/examples/brute_force/example_brute_force.cpp index 22445f79a..08f982602 100644 --- a/examples/brute_force/example_brute_force.cpp +++ b/examples/brute_force/example_brute_force.cpp @@ -32,7 +32,7 @@ struct Iota }; template -struct ArborX::AccessTraits, ArborX::PrimitivesTag> +struct ArborX::AccessTraits> { using Self = Iota; @@ -54,7 +54,7 @@ struct DummyIndexableGetter }; template <> -struct ArborX::AccessTraits +struct ArborX::AccessTraits { using memory_space = MemorySpace; using size_type = typename MemorySpace::size_type; diff --git a/examples/callback/example_callback.cpp b/examples/callback/example_callback.cpp index 40f885719..121b99469 100644 --- a/examples/callback/example_callback.cpp +++ b/examples/callback/example_callback.cpp @@ -29,7 +29,7 @@ struct NearestToOrigin }; template <> -struct ArborX::AccessTraits +struct ArborX::AccessTraits { static KOKKOS_FUNCTION std::size_t size(FirstOctant) { return 1; } static KOKKOS_FUNCTION auto get(FirstOctant, std::size_t) @@ -40,7 +40,7 @@ struct ArborX::AccessTraits }; template <> -struct ArborX::AccessTraits +struct ArborX::AccessTraits { static KOKKOS_FUNCTION std::size_t size(NearestToOrigin) { return 1; } static KOKKOS_FUNCTION auto get(NearestToOrigin d, std::size_t) diff --git a/examples/molecular_dynamics/example_molecular_dynamics.cpp b/examples/molecular_dynamics/example_molecular_dynamics.cpp index 03014c969..14dffe312 100644 --- a/examples/molecular_dynamics/example_molecular_dynamics.cpp +++ b/examples/molecular_dynamics/example_molecular_dynamics.cpp @@ -24,7 +24,7 @@ struct Neighbors }; template -struct ArborX::AccessTraits, ArborX::PredicatesTag> +struct ArborX::AccessTraits> { using memory_space = MemorySpace; using size_type = std::size_t; diff --git a/examples/raytracing/example_raytracing.cpp b/examples/raytracing/example_raytracing.cpp index 5535f2108..8153d1c6b 100644 --- a/examples/raytracing/example_raytracing.cpp +++ b/examples/raytracing/example_raytracing.cpp @@ -87,8 +87,7 @@ struct DepositEnergy } // namespace OrderedIntersectsBased template -struct ArborX::AccessTraits, - ArborX::PredicatesTag> +struct ArborX::AccessTraits> { using memory_space = MemorySpace; using size_type = std::size_t; diff --git a/src/cluster/ArborX_DBSCAN.hpp b/src/cluster/ArborX_DBSCAN.hpp index 493c9385c..a33af15a2 100644 --- a/src/cluster/ArborX_DBSCAN.hpp +++ b/src/cluster/ArborX_DBSCAN.hpp @@ -96,8 +96,7 @@ struct MixedBoxPrimitives template struct AccessTraits, - PredicatesTag> + Primitives, PermuteFilter>> { using memory_space = typename Primitives::memory_space; using Predicates = @@ -125,8 +124,7 @@ struct AccessTraits struct AccessTraits< - Details::MixedBoxPrimitives, - ArborX::PrimitivesTag> + Details::MixedBoxPrimitives> { using Primitives = Details::MixedBoxPrimitives; @@ -200,8 +198,7 @@ struct Parameters } // namespace DBSCAN template -Kokkos::View::memory_space> +Kokkos::View::memory_space> dbscan(ExecutionSpace const &exec_space, Primitives const &primitives, float eps, int core_min_size, DBSCAN::Parameters const ¶meters = DBSCAN::Parameters()) @@ -210,7 +207,7 @@ dbscan(ExecutionSpace const &exec_space, Primitives const &primitives, namespace KokkosExt = ArborX::Details::KokkosExt; - using Points = Details::AccessValues; + using Points = Details::AccessValues; using MemorySpace = typename Points::memory_space; static_assert( diff --git a/src/cluster/ArborX_MinimumSpanningTree.hpp b/src/cluster/ArborX_MinimumSpanningTree.hpp index e25be7b74..5721d3768 100644 --- a/src/cluster/ArborX_MinimumSpanningTree.hpp +++ b/src/cluster/ArborX_MinimumSpanningTree.hpp @@ -43,13 +43,13 @@ struct MinimumSpanningTree int k = 1) : edges(Kokkos::view_alloc(space, Kokkos::WithoutInitializing, "ArborX::MST::edges"), - AccessTraits::size(primitives) - 1) + AccessTraits::size(primitives) - 1) , dendrogram_parents("ArborX::MST::dendrogram_parents", 0) , dendrogram_parent_heights("ArborX::MST::dendrogram_parent_heights", 0) { Kokkos::Profiling::pushRegion("ArborX::MST::MST"); - using Points = Details::AccessValues; + using Points = Details::AccessValues; using Point = typename Points::value_type; static_assert(GeometryTraits::is_point_v); diff --git a/src/distributed/ArborX_DistributedTree.hpp b/src/distributed/ArborX_DistributedTree.hpp index 0466cd2ec..b8df311a5 100644 --- a/src/distributed/ArborX_DistributedTree.hpp +++ b/src/distributed/ArborX_DistributedTree.hpp @@ -89,7 +89,7 @@ class DistributedTreeBase Details::KokkosExt::is_accessible_from::value); - using Predicates = Details::AccessValues; + using Predicates = Details::AccessValues; static_assert(Details::KokkosExt::is_accessible_from< typename Predicates::memory_space, ExecutionSpace>::value, "Predicates must be accessible from the execution space"); @@ -156,9 +156,9 @@ KOKKOS_DEDUCTION_GUIDE #else KOKKOS_FUNCTION #endif - DistributedTree(MPI_Comm, ExecutionSpace, Values) -> DistributedTree< - typename Details::AccessValues::memory_space, - typename Details::AccessValues::value_type>; + DistributedTree(MPI_Comm, ExecutionSpace, Values) + -> DistributedTree::memory_space, + typename Details::AccessValues::value_type>; template template diff --git a/src/distributed/detail/ArborX_DistributedTreeNearestHelpers.hpp b/src/distributed/detail/ArborX_DistributedTreeNearestHelpers.hpp index aca18b246..1dc584713 100644 --- a/src/distributed/detail/ArborX_DistributedTreeNearestHelpers.hpp +++ b/src/distributed/detail/ArborX_DistributedTreeNearestHelpers.hpp @@ -148,7 +148,7 @@ KOKKOS_INLINE_FUNCTION auto approx_expand_by_radius(Geometry const &geometry, template struct AccessTraits< - Details::WithinDistanceFromPredicates, PredicatesTag> + Details::WithinDistanceFromPredicates> { using Predicate = typename Predicates::value_type; using Geometry = diff --git a/src/interpolation/ArborX_InterpMovingLeastSquares.hpp b/src/interpolation/ArborX_InterpMovingLeastSquares.hpp index 15af3fdfb..9dcd01a0a 100644 --- a/src/interpolation/ArborX_InterpMovingLeastSquares.hpp +++ b/src/interpolation/ArborX_InterpMovingLeastSquares.hpp @@ -80,9 +80,8 @@ class MovingLeastSquares "Memory space must be accessible from the execution space"); // SourcePoints is an access trait of points - ArborX::Details::check_valid_access_traits(PrimitivesTag{}, source_points); - using SourceAccess = - ArborX::Details::AccessValues; + ArborX::Details::check_valid_access_traits(source_points); + using SourceAccess = ArborX::Details::AccessValues; static_assert( KokkosExt::is_accessible_from::value, @@ -94,9 +93,8 @@ class MovingLeastSquares static constexpr int dimension = GeometryTraits::dimension_v; // TargetPoints is an access trait of points - ArborX::Details::check_valid_access_traits(PrimitivesTag{}, target_points); - using TargetAccess = - ArborX::Details::AccessValues; + ArborX::Details::check_valid_access_traits(target_points); + using TargetAccess = ArborX::Details::AccessValues; static_assert( KokkosExt::is_accessible_from::value, diff --git a/src/spatial/ArborX_BruteForce.hpp b/src/spatial/ArborX_BruteForce.hpp index 5d46d9f34..ba61532ec 100644 --- a/src/spatial/ArborX_BruteForce.hpp +++ b/src/spatial/ArborX_BruteForce.hpp @@ -78,7 +78,7 @@ class BruteForce check_valid_callback_if_first_argument_is_not_a_view( callback_or_view, user_predicates, view); - using Predicates = Details::AccessValues; + using Predicates = Details::AccessValues; using Tag = typename Predicates::value_type::Tag; Details::CrsGraphWrapperImpl::queryDispatch( @@ -105,9 +105,9 @@ KOKKOS_DEDUCTION_GUIDE #else KOKKOS_FUNCTION #endif - BruteForce(ExecutionSpace, Values) -> BruteForce< - typename Details::AccessValues::memory_space, - typename Details::AccessValues::value_type>; + BruteForce(ExecutionSpace, Values) + -> BruteForce::memory_space, + typename Details::AccessValues::value_type>; template #if KOKKOS_VERSION >= 40400 @@ -115,10 +115,10 @@ KOKKOS_DEDUCTION_GUIDE #else KOKKOS_FUNCTION #endif - BruteForce(ExecutionSpace, Values, IndexableGetter) -> BruteForce< - typename Details::AccessValues::memory_space, - typename Details::AccessValues::value_type, - IndexableGetter>; + BruteForce(ExecutionSpace, Values, IndexableGetter) + -> BruteForce::memory_space, + typename Details::AccessValues::value_type, + IndexableGetter>; template @@ -126,7 +126,7 @@ template BruteForce::BruteForce( ExecutionSpace const &space, UserValues const &user_values, IndexableGetter const &indexable_getter) - : _size(AccessTraits::size(user_values)) + : _size(AccessTraits::size(user_values)) , _values(Kokkos::view_alloc(space, Kokkos::WithoutInitializing, "ArborX::BruteForce::values"), _size) @@ -134,11 +134,9 @@ BruteForce::BruteForce( { static_assert(Details::KokkosExt::is_accessible_from::value); - // FIXME redo with RangeTraits - Details::check_valid_access_traits( - PrimitivesTag{}, user_values, Details::DoNotCheckGetReturnType()); + Details::check_valid_access_traits(user_values); - using Values = Details::AccessValues; + using Values = Details::AccessValues; Values values{user_values}; // NOLINT static_assert( @@ -167,10 +165,11 @@ void BruteForce::query( { static_assert(Details::KokkosExt::is_accessible_from::value); - Details::check_valid_access_traits(PredicatesTag{}, user_predicates); + Details::check_valid_access_traits(user_predicates, + Details::CheckReturnTypeTag{}); Details::check_valid_callback(callback, user_predicates); - using Predicates = Details::AccessValues; + using Predicates = Details::AccessValues; static_assert( Details::KokkosExt::is_accessible_from::value, diff --git a/src/spatial/ArborX_LinearBVH.hpp b/src/spatial/ArborX_LinearBVH.hpp index 2a408562f..1228610ed 100644 --- a/src/spatial/ArborX_LinearBVH.hpp +++ b/src/spatial/ArborX_LinearBVH.hpp @@ -100,7 +100,7 @@ class BoundingVolumeHierarchy check_valid_callback_if_first_argument_is_not_a_view( callback_or_view, user_predicates, view); - using Predicates = Details::AccessValues; + using Predicates = Details::AccessValues; using Tag = typename Predicates::value_type::Tag; Details::CrsGraphWrapperImpl::queryDispatch( @@ -148,8 +148,8 @@ KOKKOS_DEDUCTION_GUIDE KOKKOS_FUNCTION #endif BoundingVolumeHierarchy(ExecutionSpace, Values) -> BoundingVolumeHierarchy< - typename Details::AccessValues::memory_space, - typename Details::AccessValues::value_type>; + typename Details::AccessValues::memory_space, + typename Details::AccessValues::value_type>; template #if KOKKOS_VERSION >= 40400 @@ -159,8 +159,8 @@ KOKKOS_FUNCTION #endif BoundingVolumeHierarchy(ExecutionSpace, Values, IndexableGetter) -> BoundingVolumeHierarchy< - typename Details::AccessValues::memory_space, - typename Details::AccessValues::value_type, + typename Details::AccessValues::memory_space, + typename Details::AccessValues::value_type, IndexableGetter>; template :: UserValues const &user_values, IndexableGetter const &indexable_getter, SpaceFillingCurve const &curve) - : _size(AccessTraits::size(user_values)) + : _size(AccessTraits::size(user_values)) , _leaf_nodes(Kokkos::view_alloc(space, Kokkos::WithoutInitializing, "ArborX::BVH::leaf_nodes"), _size) @@ -193,11 +193,9 @@ BoundingVolumeHierarchy:: { static_assert(Details::KokkosExt::is_accessible_from::value); - // FIXME redo with RangeTraits - Details::check_valid_access_traits( - PrimitivesTag{}, user_values, Details::DoNotCheckGetReturnType()); + Details::check_valid_access_traits(user_values); - using Values = Details::AccessValues; + using Values = Details::AccessValues; Values values{user_values}; // NOLINT static_assert( @@ -275,10 +273,11 @@ void BoundingVolumeHierarchy< { static_assert(Details::KokkosExt::is_accessible_from::value); - Details::check_valid_access_traits(PredicatesTag{}, user_predicates); + Details::check_valid_access_traits(user_predicates, + Details::CheckReturnTypeTag{}); Details::check_valid_callback(callback, user_predicates); - using Predicates = Details::AccessValues; + using Predicates = Details::AccessValues; static_assert( Details::KokkosExt::is_accessible_from::value, diff --git a/src/spatial/detail/ArborX_AccessTraits.hpp b/src/spatial/detail/ArborX_AccessTraits.hpp index 4bc7c1151..45e359fa3 100644 --- a/src/spatial/detail/ArborX_AccessTraits.hpp +++ b/src/spatial/detail/ArborX_AccessTraits.hpp @@ -21,13 +21,7 @@ namespace ArborX { -struct PrimitivesTag -{}; - -struct PredicatesTag -{}; - -template +template struct AccessTraits { using not_specialized = void; // tag to detect existence of a specialization @@ -37,9 +31,9 @@ template using AccessTraitsNotSpecializedArchetypeAlias = typename Traits::not_specialized; -template +template struct AccessTraits< - View, Tag, std::enable_if_t{} && View::rank() == 1>> + View, std::enable_if_t{} && View::rank() == 1>> { // Returns a const reference KOKKOS_FUNCTION static typename View::const_value_type &get(View const &v, @@ -54,9 +48,9 @@ struct AccessTraits< using memory_space = typename View::memory_space; }; -template +template struct AccessTraits< - View, Tag, std::enable_if_t{} && View::rank() == 2>> + View, std::enable_if_t{} && View::rank() == 2>> { template KOKKOS_FUNCTION static auto getPoint(std::index_sequence, @@ -101,63 +95,23 @@ using AccessTraitsGetArchetypeExpression = template using PredicateTagArchetypeAlias = typename P::Tag; -template -void check_valid_access_traits(PredicatesTag, Predicates const &) -{ - using Access = AccessTraits; - static_assert( - !Kokkos::is_detected{}, - "Must specialize 'AccessTraits'"); - - static_assert( - Kokkos::is_detected{}, - "AccessTraits must define 'memory_space' " - "member type"); - static_assert( - Kokkos::is_memory_space< - Kokkos::detected_t>{}, - "'memory_space' member type must be a valid Kokkos memory space"); - - static_assert( - Kokkos::is_detected{}, - "AccessTraits must define 'size()' static " - "member function"); - static_assert( - std::is_integral>{}, - "size() static member function return type is not an integral type"); - - static_assert( - Kokkos::is_detected{}, - "AccessTraits must define 'get()' static " - "member function"); - - using Predicate = - std::decay_t>; - using Tag = Kokkos::detected_t; - static_assert(is_valid_predicate_tag::value, - "Invalid tag for the predicates"); -} +struct DoNotCheckReturnTypeTag +{}; -struct DoNotCheckGetReturnType : std::false_type +struct CheckReturnTypeTag {}; -template -void check_valid_access_traits(PrimitivesTag, Primitives const &, - CheckGetReturnType = {}) +template +void check_valid_access_traits(Values const &, Tag = {}) { - using Access = AccessTraits; + using Access = AccessTraits; static_assert( !Kokkos::is_detected{}, - "Must specialize 'AccessTraits'"); + "Must specialize 'AccessTraits'"); static_assert( Kokkos::is_detected{}, - "AccessTraits must define 'memory_space' " - "member type"); + "AccessTraits must define 'memory_space' member type"); static_assert( Kokkos::is_memory_space< Kokkos::detected_t>{}, @@ -165,34 +119,37 @@ void check_valid_access_traits(PrimitivesTag, Primitives const &, static_assert( Kokkos::is_detected{}, - "AccessTraits must define 'size()' static " - "member function"); + Values>{}, + "AccessTraits must define 'size()' static member function"); static_assert( std::is_integral>{}, + Access, Values>>{}, "size() static member function return type is not an integral type"); static_assert( - Kokkos::is_detected{}, - "AccessTraits must define 'get()' static " - "member function"); - using T = std::decay_t>; - if constexpr (CheckGetReturnType()) + Kokkos::is_detected{}, + "AccessTraits must define 'get()' static member function"); + static_assert( + !std::is_void_v>, + "get() static member function return type must not be void"); + + if constexpr (std::is_same_v) { - static_assert(GeometryTraits::is_point_v || GeometryTraits::is_box_v, - "AccessTraits::get() return type " - "must decay to a point or a box type"); + using Predicate = std::decay_t< + Kokkos::detected_t>; + using PredicateTag = + Kokkos::detected_t; + static_assert(is_valid_predicate_tag::value, + "Invalid tag for the predicates"); } } -template +template class AccessValuesI { private: - using Access = AccessTraits; + using Access = AccessTraits; Values _values; public: @@ -209,32 +166,29 @@ class AccessValuesI KOKKOS_FUNCTION auto size() const { return Access::size(_values); } - using self_type = AccessValuesI; + using self_type = AccessValuesI; }; -template -class AccessValuesI, Tag> : public Kokkos::View +template +class AccessValuesI> : public Kokkos::View { public: using self_type = Kokkos::View; }; -template -class AccessValuesI, Tag2> - : public AccessValuesI -{ - static_assert(std::is_same_v); -}; +template +class AccessValuesI> : public AccessValuesI +{}; -template -using AccessValues = typename AccessValuesI::self_type; +template +using AccessValues = typename AccessValuesI::self_type; } // namespace Details -template -struct AccessTraits, Tag> +template +struct AccessTraits> { - using AccessValues = Details::AccessValuesI; + using AccessValues = Details::AccessValuesI; using memory_space = typename AccessValues::memory_space; diff --git a/src/spatial/detail/ArborX_AttachIndices.hpp b/src/spatial/detail/ArborX_AttachIndices.hpp index bfb5ad668..41e3bb0d1 100644 --- a/src/spatial/detail/ArborX_AttachIndices.hpp +++ b/src/spatial/detail/ArborX_AttachIndices.hpp @@ -38,16 +38,11 @@ auto attach_indices(Values const &values) } // namespace ArborX template -struct ArborX::AccessTraits, - ArborX::PrimitivesTag> +struct ArborX::AccessTraits> { private: using Self = ArborX::Experimental::AttachIndices; - using Access = AccessTraits; - using value_type = ArborX::PairValueIndex< - std::decay_t>, - Index>; + using Access = AccessTraits; public: using memory_space = typename Access::memory_space; @@ -58,27 +53,18 @@ struct ArborX::AccessTraits, } KOKKOS_FUNCTION static auto get(Self const &self, int i) { - return value_type{Access::get(self._values, i), Index(i)}; - } -}; -template -struct ArborX::AccessTraits, - ArborX::PredicatesTag> -{ -private: - using Self = ArborX::Experimental::AttachIndices; - using Access = AccessTraits; + using namespace ArborX::Details; -public: - using memory_space = typename Access::memory_space; + using value_type = std::decay_t< + Kokkos::detected_t>; + using PredicateTag = + Kokkos::detected_t; - KOKKOS_FUNCTION static auto size(Self const &self) - { - return Access::size(self._values); - } - KOKKOS_FUNCTION static auto get(Self const &self, int i) - { - return attach(Access::get(self._values, i), Index(i)); + if constexpr (is_valid_predicate_tag::value) + return attach(Access::get(self._values, i), Index(i)); + else + return PairValueIndex{Access::get(self._values, i), + Index(i)}; } }; diff --git a/src/spatial/detail/ArborX_Callbacks.hpp b/src/spatial/detail/ArborX_Callbacks.hpp index d638fed35..625ec4dd0 100644 --- a/src/spatial/detail/ArborX_Callbacks.hpp +++ b/src/spatial/detail/ArborX_Callbacks.hpp @@ -98,8 +98,7 @@ void check_valid_callback(Callback const &callback, Predicates const &, { check_generic_lambda_support(callback); - using Predicate = - typename AccessValues::value_type; + using Predicate = typename AccessValues::value_type; using PredicateTag = typename Predicate::Tag; static_assert(!(std::is_same_v && @@ -149,8 +148,7 @@ void check_valid_callback(Callback const &callback, Predicates const &) { check_generic_lambda_support(callback); - using Predicate = - typename AccessValues::value_type; + using Predicate = typename AccessValues::value_type; using PredicateTag = typename Predicate::Tag; static_assert(is_valid_predicate_tag::value, diff --git a/src/spatial/detail/ArborX_NeighborList.hpp b/src/spatial/detail/ArborX_NeighborList.hpp index f209d8f06..6279758eb 100644 --- a/src/spatial/detail/ArborX_NeighborList.hpp +++ b/src/spatial/detail/ArborX_NeighborList.hpp @@ -52,7 +52,7 @@ void findHalfNeighborList(ExecutionSpace const &space, namespace KokkosExt = ArborX::Details::KokkosExt; using Details::HalfTraversal; - using Points = Details::AccessValues; + using Points = Details::AccessValues; using MemorySpace = typename Points::memory_space; static_assert( @@ -111,7 +111,7 @@ void findFullNeighborList(ExecutionSpace const &space, namespace KokkosExt = ArborX::Details::KokkosExt; using Details::HalfTraversal; - using Points = Details::AccessValues; + using Points = Details::AccessValues; using MemorySpace = typename Points::memory_space; static_assert( diff --git a/src/spatial/detail/ArborX_PermutedData.hpp b/src/spatial/detail/ArborX_PermutedData.hpp index 369c71b05..a70b4d6ac 100644 --- a/src/spatial/detail/ArborX_PermutedData.hpp +++ b/src/spatial/detail/ArborX_PermutedData.hpp @@ -53,8 +53,8 @@ struct PermutedData KOKKOS_FUNCTION auto size() const { return _data.size(); } }; -template -class AccessValuesI, Tag> +template +class AccessValuesI> : public PermutedData { public: @@ -64,8 +64,7 @@ class AccessValuesI, Tag> } // namespace Details template -struct AccessTraits, - PredicatesTag> +struct AccessTraits> { using PermutedPredicates = Details::PermutedData; diff --git a/src/spatial/detail/ArborX_PredicateHelpers.hpp b/src/spatial/detail/ArborX_PredicateHelpers.hpp index d988eee81..432f35c4f 100644 --- a/src/spatial/detail/ArborX_PredicateHelpers.hpp +++ b/src/spatial/detail/ArborX_PredicateHelpers.hpp @@ -25,7 +25,7 @@ namespace Experimental template class PrimitivesIntersect { - using Primitives = Details::AccessValues; + using Primitives = Details::AccessValues; // FIXME: // using Geometry = typename Primitives::value_type; // static_assert(GeometryTraits::is_valid_geometry{}); @@ -37,7 +37,7 @@ class PrimitivesIntersect template class PrimitivesOrderedIntersect { - using Primitives = Details::AccessValues; + using Primitives = Details::AccessValues; public: Primitives _primitives; @@ -46,7 +46,7 @@ class PrimitivesOrderedIntersect template class PrimitivesWithRadius { - using Primitives = Details::AccessValues; + using Primitives = Details::AccessValues; using Point = typename Primitives::value_type; static_assert(GeometryTraits::is_point::value); using Coordinate = typename GeometryTraits::coordinate_type::type; @@ -64,7 +64,7 @@ class PrimitivesWithRadius template class PrimitivesNearestK { - using Primitives = Details::AccessValues; + using Primitives = Details::AccessValues; // FIXME: // using Geometry = typename Primitives::value_type; // static_assert(GeometryTraits::is_valid_geometry{}); @@ -77,39 +77,35 @@ class PrimitivesNearestK template auto make_intersects(Primitives const &primitives) { - Details::check_valid_access_traits(PrimitivesTag{}, primitives, - Details::DoNotCheckGetReturnType()); + Details::check_valid_access_traits(primitives); return PrimitivesIntersect{primitives}; } template auto make_intersects(Primitives const &primitives, Coordinate r) { - Details::check_valid_access_traits(PrimitivesTag{}, primitives); + Details::check_valid_access_traits(primitives); return PrimitivesWithRadius(primitives, r); } template auto make_ordered_intersects(Primitives const &primitives) { - Details::check_valid_access_traits(PrimitivesTag{}, primitives, - Details::DoNotCheckGetReturnType()); + Details::check_valid_access_traits(primitives); return PrimitivesOrderedIntersect{primitives}; } template auto make_nearest(Primitives const &primitives, int k) { - Details::check_valid_access_traits(PrimitivesTag{}, primitives, - Details::DoNotCheckGetReturnType()); + Details::check_valid_access_traits(primitives); return PrimitivesNearestK{primitives, k}; } } // namespace Experimental template -struct AccessTraits, - PredicatesTag> +struct AccessTraits> { private: using Self = Experimental::PrimitivesIntersect; @@ -129,8 +125,7 @@ struct AccessTraits, }; template -struct AccessTraits, - PredicatesTag> +struct AccessTraits> { private: using Self = Experimental::PrimitivesOrderedIntersect; @@ -150,8 +145,7 @@ struct AccessTraits, }; template -struct AccessTraits, - PredicatesTag> +struct AccessTraits> { private: using Self = Experimental::PrimitivesWithRadius; @@ -176,7 +170,7 @@ struct AccessTraits, }; template -struct AccessTraits, PredicatesTag> +struct AccessTraits> { private: using Self = Experimental::PrimitivesNearestK; diff --git a/test/ArborXTest_LegacyTree.hpp b/test/ArborXTest_LegacyTree.hpp index 7cce3f502..31427e893 100644 --- a/test/ArborXTest_LegacyTree.hpp +++ b/test/ArborXTest_LegacyTree.hpp @@ -25,7 +25,7 @@ template class LegacyValues { Primitives _primitives; - using Access = ArborX::AccessTraits; + using Access = ArborX::AccessTraits; public: using memory_space = typename Access::memory_space; @@ -66,8 +66,7 @@ class LegacyValues }; template -struct ArborX::AccessTraits, - ArborX::PrimitivesTag> +struct ArborX::AccessTraits> { using self_type = LegacyValues; diff --git a/test/ArborX_BoostRTreeHelpers.hpp b/test/ArborX_BoostRTreeHelpers.hpp index 9f2d13f29..fbb8b5016 100644 --- a/test/ArborX_BoostRTreeHelpers.hpp +++ b/test/ArborX_BoostRTreeHelpers.hpp @@ -192,8 +192,7 @@ performQueries(RTree const &rtree, UserPredicates const &predicates) { namespace KokkosExt = ArborX::Details::KokkosExt; - using Predicates = - ArborX::Details::AccessValues; + using Predicates = ArborX::Details::AccessValues; static_assert(Kokkos::SpaceAccessibility::accessible); diff --git a/test/tstAttachIndices.cpp b/test/tstAttachIndices.cpp index c77570bcf..33c6e8bc6 100644 --- a/test/tstAttachIndices.cpp +++ b/test/tstAttachIndices.cpp @@ -23,8 +23,7 @@ BOOST_AUTO_TEST_CASE(attach_indices_to_primitives) Kokkos::View *, Kokkos::HostSpace> p("Testing::p", 10); auto p_with_indices = attach_indices(p); - AccessValues p_values{ - p_with_indices}; + AccessValues p_values{p_with_indices}; static_assert(std::is_same_v); BOOST_TEST(p_values(0).index == 0); BOOST_TEST(p_values(9).index == 9); @@ -38,8 +37,7 @@ BOOST_AUTO_TEST_CASE(attach_indices_to_predicates) using IntersectsPredicate = decltype(ArborX::intersects(ArborX::Point<3>{})); Kokkos::View q("Testing::q", 10); auto q_with_indices = attach_indices(q); - AccessValues q_values{ - q_with_indices}; + AccessValues q_values{q_with_indices}; BOOST_TEST(ArborX::getData(q_values(0)) == 0); BOOST_TEST(ArborX::getData(q_values(9)) == 9); } diff --git a/test/tstCompileOnlyAccessTraits.cpp b/test/tstCompileOnlyAccessTraits.cpp index 46a76d414..0870f8ae9 100644 --- a/test/tstCompileOnlyAccessTraits.cpp +++ b/test/tstCompileOnlyAccessTraits.cpp @@ -15,9 +15,8 @@ #include -using ArborX::PredicatesTag; -using ArborX::PrimitivesTag; using ArborX::Details::check_valid_access_traits; +using ArborX::Details::CheckReturnTypeTag; // NOTE Let's not bother with __host__ __device__ annotations here @@ -38,6 +37,14 @@ struct ArborX::AccessTraits using memory_space = void; }; +struct MissingSizeMemberFunction +{}; +template +struct ArborX::AccessTraits +{ + using memory_space = Kokkos::HostSpace; +}; + struct SizeMemberFunctionNotStatic {}; template @@ -47,9 +54,38 @@ struct ArborX::AccessTraits int size(SizeMemberFunctionNotStatic) { return 255; } }; -template +struct MissingGetMemberFunction +{}; +template +struct ArborX::AccessTraits +{ + using memory_space = Kokkos::HostSpace; + static int size(MissingGetMemberFunction) { return 255; } +}; + +struct GetMemberFunctionNotStatic +{}; +template +struct ArborX::AccessTraits +{ + using memory_space = Kokkos::HostSpace; + static int size(GetMemberFunctionNotStatic) { return 255; } + ArborX::Point<3> get(GetMemberFunctionNotStatic, int) { return {}; } +}; + +struct GetMemberFunctionVoid +{}; +template +struct ArborX::AccessTraits +{ + using memory_space = Kokkos::HostSpace; + static int size(GetMemberFunctionVoid) { return 255; } + static void get(GetMemberFunctionVoid, int) {} +}; + +template using deduce_type_t = - decltype(ArborX::AccessTraits::get(std::declval(), 0)); + decltype(ArborX::AccessTraits::get(std::declval(), 0)); void test_access_traits_compile_only() { @@ -57,28 +93,25 @@ void test_access_traits_compile_only() Kokkos::View p; Kokkos::View v; - check_valid_access_traits(PrimitivesTag{}, p); - check_valid_access_traits(PrimitivesTag{}, v); + check_valid_access_traits(p); + check_valid_access_traits(v); auto p_with_indices = ArborX::Experimental::attach_indices(p); - check_valid_access_traits(PrimitivesTag{}, p_with_indices, - ArborX::Details::DoNotCheckGetReturnType()); - static_assert( - std::is_same_v, - ArborX::PairValueIndex>); + check_valid_access_traits(p_with_indices); + static_assert(std::is_same_v, + ArborX::PairValueIndex>); auto p_with_indices_long = ArborX::Experimental::attach_indices(p); - static_assert(std::is_same_v< - deduce_type_t, - ArborX::PairValueIndex>); + static_assert(std::is_same_v, + ArborX::PairValueIndex>); using NearestPredicate = decltype(ArborX::nearest(Point{})); Kokkos::View q; - check_valid_access_traits(PredicatesTag{}, q); + check_valid_access_traits(q, CheckReturnTypeTag{}); auto q_with_indices = ArborX::Experimental::attach_indices(q); - check_valid_access_traits(PredicatesTag{}, q_with_indices); - using predicate = deduce_type_t; + check_valid_access_traits(q_with_indices, CheckReturnTypeTag{}); + using predicate = deduce_type_t; static_assert( std::is_same_v< std::decay_t()))>, @@ -91,38 +124,40 @@ void test_access_traits_compile_only() }; auto q_with_custom_indices = ArborX::Experimental::attach_indices(q); - check_valid_access_traits(PredicatesTag{}, q_with_custom_indices); - using predicate_custom = - deduce_type_t; + check_valid_access_traits(q_with_custom_indices, CheckReturnTypeTag{}); + using predicate_custom = deduce_type_t; static_assert(std::is_same_v()))>, CustomIndex>); // Uncomment to see error messages - // check_valid_access_traits(PrimitivesTag{}, NoAccessTraitsSpecialization{}); + // check_valid_access_traits(NoAccessTraitsSpecialization{}); + + // check_valid_access_traits(EmptySpecialization{}); + + // check_valid_access_traits(InvalidMemorySpace{}); + + // check_valid_access_traits(MissingSizeMemberFunction{}); + + // check_valid_access_traits(SizeMemberFunctionNotStatic{}); - // check_valid_access_traits(PrimitivesTag{}, EmptySpecialization{}); + // check_valid_access_traits(MissingGetMemberFunction{}); - // check_valid_access_traits(PrimitivesTag{}, InvalidMemorySpace{}); + // check_valid_access_traits(GetMemberFunctionNotStatic{}); - // check_valid_access_traits(PrimitivesTag{}, SizeMemberFunctionNotStatic{}); + // check_valid_access_traits(GetMemberFunctionVoid{}); } void test_deduce_point_type_from_view() { using ArborX::Point; - using ArborX::PrimitivesTag; static_assert( - std::is_same_v, PrimitivesTag>, - Point<3>>); + std::is_same_v>, Point<3>>); static_assert( - std::is_same_v, PrimitivesTag>, - Point<3>>); + std::is_same_v>, Point<3>>); static_assert( - std::is_same_v, PrimitivesTag>, - Point<2>>); + std::is_same_v>, Point<2>>); static_assert( - std::is_same_v, PrimitivesTag>, - Point<5>>); + std::is_same_v>, Point<5>>); } diff --git a/test/tstCompileOnlyCallbacks.cpp b/test/tstCompileOnlyCallbacks.cpp index 62bab55ce..cf4ab0faa 100644 --- a/test/tstCompileOnlyCallbacks.cpp +++ b/test/tstCompileOnlyCallbacks.cpp @@ -20,7 +20,7 @@ struct NearestPredicates {}; template <> -struct ArborX::AccessTraits +struct ArborX::AccessTraits { using memory_space = Kokkos::HostSpace; static int size(NearestPredicates const &) { return 1; } @@ -33,7 +33,7 @@ struct ArborX::AccessTraits struct SpatialPredicates {}; template <> -struct ArborX::AccessTraits +struct ArborX::AccessTraits { using memory_space = Kokkos::HostSpace; static int size(SpatialPredicates const &) { return 1; } diff --git a/test/tstDBSCAN.cpp b/test/tstDBSCAN.cpp index d0f2cfc2d..194cab196 100644 --- a/test/tstDBSCAN.cpp +++ b/test/tstDBSCAN.cpp @@ -22,7 +22,7 @@ struct HiddenView View _view; }; template -struct ArborX::AccessTraits, ArborX::PrimitivesTag> +struct ArborX::AccessTraits> { using Data = HiddenView; static KOKKOS_FUNCTION std::size_t size(Data const &data) diff --git a/test/tstDetailsCrsGraphWrapperImpl.cpp b/test/tstDetailsCrsGraphWrapperImpl.cpp index c7b00c217..527c1bb87 100644 --- a/test/tstDetailsCrsGraphWrapperImpl.cpp +++ b/test/tstDetailsCrsGraphWrapperImpl.cpp @@ -32,7 +32,7 @@ struct Test1 ArborX::Experimental::TraversalPolicy const & = ArborX::Experimental::TraversalPolicy()) const { - using Access = ArborX::AccessTraits; + using Access = ArborX::AccessTraits; Kokkos::parallel_for( Kokkos::RangePolicy(space, 0, Access::size(predicates)), diff --git a/test/tstIndexableGetter.cpp b/test/tstIndexableGetter.cpp index 1e66c702f..3f0a9cd3e 100644 --- a/test/tstIndexableGetter.cpp +++ b/test/tstIndexableGetter.cpp @@ -28,7 +28,7 @@ struct PointCloud }; template -struct ArborX::AccessTraits, ArborX::PrimitivesTag> +struct ArborX::AccessTraits> { using Points = PointCloud; @@ -51,8 +51,7 @@ struct PairPointIndexCloud }; template -struct ArborX::AccessTraits, - ArborX::PrimitivesTag> +struct ArborX::AccessTraits> { using Points = PairPointIndexCloud; @@ -106,8 +105,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(indexables, DeviceType, ARBORX_DEVICE_TYPES) { PointCloud points_cloud{points.data(), (int)points.size()}; - using Primitives = ArborX::Details::AccessValues; + using Primitives = ArborX::Details::AccessValues; Primitives primitives(points_cloud); ArborX::Details::Indexables indexables{primitives, indexable_getter}; @@ -121,8 +119,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(indexables, DeviceType, ARBORX_DEVICE_TYPES) PairPointIndexCloud points_cloud{points.data(), (int)points.size()}; - using Primitives = ArborX::Details::AccessValues; + using Primitives = ArborX::Details::AccessValues; Primitives primitives(points_cloud); ArborX::Details::Indexables indexables{primitives, indexable_getter}; diff --git a/test/tstQueryTreeIntersectsKDOP.cpp b/test/tstQueryTreeIntersectsKDOP.cpp index 21dac3737..4657716a6 100644 --- a/test/tstQueryTreeIntersectsKDOP.cpp +++ b/test/tstQueryTreeIntersectsKDOP.cpp @@ -27,7 +27,7 @@ struct Iota }; template -struct ArborX::AccessTraits, ArborX::PrimitivesTag> +struct ArborX::AccessTraits> { using Self = Iota;