diff --git a/examples/access_traits/example_cuda_access_traits.cpp b/examples/access_traits/example_cuda_access_traits.cpp index dcd27c4c1..976b77559 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) { @@ -50,7 +50,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 19472534c..3c1be1bdb 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/callback/example_callback.cpp b/examples/callback/example_callback.cpp index 50bfc5b9a..3526e265e 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/raytracing/example_raytracing.cpp b/examples/raytracing/example_raytracing.cpp index e0969dcfb..5b6387440 100644 --- a/examples/raytracing/example_raytracing.cpp +++ b/examples/raytracing/example_raytracing.cpp @@ -86,8 +86,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/ArborX_BruteForce.hpp b/src/ArborX_BruteForce.hpp index 22d81cb9a..a3ab2af0c 100644 --- a/src/ArborX_BruteForce.hpp +++ b/src/ArborX_BruteForce.hpp @@ -212,10 +212,7 @@ template BruteForce::BruteForce( ExecutionSpace const &space, UserValues const &user_values, IndexableGetter const &indexable_getter) - : _size(AccessTraits::size(user_values)) - , _values(Kokkos::view_alloc(space, Kokkos::WithoutInitializing, - "ArborX::BruteForce::values"), - _size) + : _values("ArborX::BruteForce::values", 0) , _indexable_getter(indexable_getter) { static_assert(Details::KokkosExt::is_accessible_from::BruteForce( Kokkos::Profiling::ScopedRegion guard("ArborX::BruteForce::BruteForce"); + _size = values.size(); if (empty()) { return; } + Details::KokkosExt::reallocWithoutInitializing(space, _values, _size); + Details::BruteForceImpl::initializeBoundingVolumesAndReduceBoundsOfTheScene( space, values, _indexable_getter, _values, _bounds); } diff --git a/src/ArborX_DBSCAN.hpp b/src/ArborX_DBSCAN.hpp index 2e60e1c3c..8cf1c8cb1 100644 --- a/src/ArborX_DBSCAN.hpp +++ b/src/ArborX_DBSCAN.hpp @@ -98,8 +98,7 @@ struct MixedBoxPrimitives template struct AccessTraits, - PredicatesTag> + Primitives, PermuteFilter>> { using memory_space = typename Primitives::memory_space; using Predicates = @@ -129,8 +128,7 @@ struct AccessTraits struct AccessTraits< - Details::MixedBoxPrimitives, - ArborX::PrimitivesTag> + Details::MixedBoxPrimitives> { using Primitives = Details::MixedBoxPrimitives; diff --git a/src/ArborX_LinearBVH.hpp b/src/ArborX_LinearBVH.hpp index 24147cb44..4d215845f 100644 --- a/src/ArborX_LinearBVH.hpp +++ b/src/ArborX_LinearBVH.hpp @@ -285,13 +285,8 @@ BoundingVolumeHierarchy:: UserValues const &user_values, IndexableGetter const &indexable_getter, SpaceFillingCurve const &curve) - : _size(AccessTraits::size(user_values)) - , _leaf_nodes(Kokkos::view_alloc(space, Kokkos::WithoutInitializing, - "ArborX::BVH::leaf_nodes"), - _size) - , _internal_nodes(Kokkos::view_alloc(space, Kokkos::WithoutInitializing, - "ArborX::BVH::internal_nodes"), - _size > 1 ? _size - 1 : 0) + : _leaf_nodes("ArborX::BVH::leaf_nodes", 0) + , _internal_nodes("ArborX::BVH::internal_nodes", 0) , _indexable_getter(indexable_getter) { static_assert(Details::KokkosExt::is_accessible_from:: Kokkos::Profiling::ScopedRegion guard("ArborX::BVH::BVH"); + _size = values.size(); if (empty()) { return; } + Details::KokkosExt::reallocWithoutInitializing(space, _leaf_nodes, _size); + Details::KokkosExt::reallocWithoutInitializing(space, _internal_nodes, + _size - 1); + if (size() == 1) { Details::TreeConstruction::initializeSingleLeafTree( diff --git a/src/details/ArborX_AccessTraits.hpp b/src/details/ArborX_AccessTraits.hpp index 79d66da1a..bba353806 100644 --- a/src/details/ArborX_AccessTraits.hpp +++ b/src/details/ArborX_AccessTraits.hpp @@ -28,16 +28,31 @@ struct PrimitivesTag struct PredicatesTag {}; -template +namespace Details +{ +struct AnyTag +{}; +} // namespace Details + +template struct AccessTraits { using not_specialized = void; // tag to detect existence of a specialization }; +namespace Details +{ template using AccessTraitsNotSpecializedArchetypeAlias = typename Traits::not_specialized; +template +using TrueTag = std::conditional_t< + !Kokkos::is_detected>{}, + AnyTag, Tag>; +} // namespace Details + template struct AccessTraits< View, Tag, std::enable_if_t{} && View::rank == 1>> @@ -105,7 +120,8 @@ using PredicateTagArchetypeAlias = typename P::Tag; template void check_valid_access_traits(PredicatesTag, Predicates const &) { - using Access = AccessTraits; + using Access = + AccessTraits>; static_assert( !Kokkos::is_detected{}, "Must specialize 'AccessTraits'"); @@ -150,7 +166,8 @@ template void check_valid_access_traits(PrimitivesTag, Primitives const &, CheckGetReturnType = {}) { - using Access = AccessTraits; + using Access = + AccessTraits>; static_assert( !Kokkos::is_detected{}, "Must specialize 'AccessTraits'"); @@ -193,7 +210,7 @@ template class AccessValuesI { private: - using Access = AccessTraits; + using Access = AccessTraits>; Values _values; public: @@ -210,7 +227,7 @@ class AccessValuesI KOKKOS_FUNCTION auto size() const { return Access::size(_values); } - using self_type = AccessValuesI; + using self_type = AccessValuesI>; }; template @@ -224,7 +241,8 @@ template class AccessValuesI, Tag2> : public AccessValuesI { - static_assert(std::is_same_v); + static_assert(std::is_same_v || std::is_same_v || + std::is_same_v); }; template @@ -261,11 +279,10 @@ struct Access }; } // namespace Traits template -struct AccessTraits< - T, Tag, - std::enable_if_t>{}>> - : Traits::Access +struct AccessTraits>{}>> : Traits::Access { template static constexpr bool always_false = std::is_void_v; diff --git a/src/details/ArborX_AttachIndices.hpp b/src/details/ArborX_AttachIndices.hpp index a6afe358e..7f79a5b7d 100644 --- a/src/details/ArborX_AttachIndices.hpp +++ b/src/details/ArborX_AttachIndices.hpp @@ -43,7 +43,8 @@ struct ArborX::AccessTraits, { private: using Self = ArborX::Experimental::AttachIndices; - using Access = AccessTraits; + using Access = + AccessTraits>; using value_type = ArborX::PairValueIndex< std::decay_t>, @@ -67,7 +68,8 @@ struct ArborX::AccessTraits, { private: using Self = ArborX::Experimental::AttachIndices; - using Access = AccessTraits; + using Access = + AccessTraits>; public: using memory_space = typename Access::memory_space; diff --git a/src/details/ArborX_DetailsDistributedTreeNearest.hpp b/src/details/ArborX_DetailsDistributedTreeNearest.hpp index 9219408d2..2ee0f0f36 100644 --- a/src/details/ArborX_DetailsDistributedTreeNearest.hpp +++ b/src/details/ArborX_DetailsDistributedTreeNearest.hpp @@ -45,7 +45,7 @@ struct WithinDistanceFromPredicates template struct AccessTraits< - Details::WithinDistanceFromPredicates, PredicatesTag> + Details::WithinDistanceFromPredicates> { using Predicate = typename Predicates::value_type; using Geometry = diff --git a/src/details/ArborX_DetailsLegacy.hpp b/src/details/ArborX_DetailsLegacy.hpp index c34ae988a..c55917301 100644 --- a/src/details/ArborX_DetailsLegacy.hpp +++ b/src/details/ArborX_DetailsLegacy.hpp @@ -23,8 +23,9 @@ namespace ArborX::Details template class LegacyValues { + using Access = AccessTraits>; + Primitives _primitives; - using Access = AccessTraits; public: using memory_space = typename Access::memory_space;