From 7d044fbf48c143d9977d7e61d67f2d4ee3b2c599 Mon Sep 17 00:00:00 2001 From: Andrey Prokopenko Date: Sat, 5 Oct 2024 05:10:18 -0400 Subject: [PATCH] Fix examples, benchmarks, tests --- .../brute_force_vs_bvh_timpl.hpp | 53 ++++++---- .../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 | 29 +++-- examples/callback/example_callback.cpp | 4 +- .../example_molecular_dynamics.cpp | 2 +- examples/raytracing/example_raytracing.cpp | 3 +- test/ArborXTest_LegacyTree.hpp | 5 +- test/ArborX_BoostRTreeHelpers.hpp | 3 +- test/tstAttachIndices.cpp | 6 +- test/tstCompileOnlyAccessTraits.cpp | 100 ++++++++++++------ test/tstCompileOnlyCallbacks.cpp | 4 +- test/tstDBSCAN.cpp | 2 +- test/tstDetailsCrsGraphWrapperImpl.cpp | 2 +- test/tstIndexableGetter.cpp | 11 +- 17 files changed, 134 insertions(+), 102 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 db95d0bd6..d6a075c3f 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; @@ -75,8 +82,8 @@ template static void run_fp(int nprimitives, int nqueries, int nrepeats) { ExecutionSpace space{}; - Placeholder primitives{nprimitives}; - Placeholder predicates{nqueries}; + Placeholder primitives{nprimitives}; + Placeholder predicates{nqueries}; for (int i = 0; i < nrepeats; i++) { diff --git a/benchmarks/dbscan/ArborX_DBSCANVerification.hpp b/benchmarks/dbscan/ArborX_DBSCANVerification.hpp index 78fa1eff9..4c0e3d288 100644 --- a/benchmarks/dbscan/ArborX_DBSCANVerification.hpp +++ b/benchmarks/dbscan/ArborX_DBSCANVerification.hpp @@ -284,7 +284,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 e323f03ac..9ebca792f 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 6bf5543d2..606e43230 100644 --- a/examples/brute_force/example_brute_force.cpp +++ b/examples/brute_force/example_brute_force.cpp @@ -15,6 +15,12 @@ #include +struct PrimitivesTag +{}; +struct PredicatesTag +{}; + +template struct Dummy { int count; @@ -23,26 +29,17 @@ struct Dummy using ExecutionSpace = Kokkos::DefaultExecutionSpace; using MemorySpace = ExecutionSpace::memory_space; -template <> -struct ArborX::AccessTraits +template +struct ArborX::AccessTraits> { using memory_space = MemorySpace; using size_type = typename MemorySpace::size_type; - static KOKKOS_FUNCTION size_type size(Dummy const &d) { return d.count; } - static KOKKOS_FUNCTION auto get(Dummy const &, size_type i) + static KOKKOS_FUNCTION size_type size(Dummy const &d) { return d.count; } + static KOKKOS_FUNCTION auto get(Dummy const &, size_type i) { return ArborX::Point{(float)i, (float)i, (float)i}; } -}; - -template <> -struct ArborX::AccessTraits -{ - using memory_space = MemorySpace; - using size_type = typename MemorySpace::size_type; - - static KOKKOS_FUNCTION size_type size(Dummy const &d) { return d.count; } - static KOKKOS_FUNCTION auto get(Dummy const &, size_type i) + static KOKKOS_FUNCTION auto get(Dummy const &, size_type i) { ArborX::Point center{(float)i, (float)i, (float)i}; return ArborX::intersects(Sphere{center, (float)i}); @@ -69,8 +66,8 @@ int main(int argc, char *argv[]) int nprimitives = 5; int npredicates = 5; - Dummy primitives{nprimitives}; - Dummy predicates{npredicates}; + Dummy primitives{nprimitives}; + Dummy predicates{npredicates}; unsigned int out_count; { 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/test/ArborXTest_LegacyTree.hpp b/test/ArborXTest_LegacyTree.hpp index 64123bc95..ef0db02bf 100644 --- a/test/ArborXTest_LegacyTree.hpp +++ b/test/ArborXTest_LegacyTree.hpp @@ -26,7 +26,7 @@ template class LegacyValues { Primitives _primitives; - using Access = ArborX::AccessTraits; + using Access = ArborX::AccessTraits; public: using memory_space = typename Access::memory_space; @@ -67,8 +67,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 efca3fd09..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,27 +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); - 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()))>, @@ -90,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 b36c6af46..ddf721d31 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{ @@ -122,8 +120,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{