Skip to content

Commit

Permalink
Merge pull request #1200 from aprokop/test_double
Browse files Browse the repository at this point in the history
Test on-node space indexes using both float and double
aprokop authored Jan 27, 2025

Verified

This commit was signed with the committer’s verified signature. The key has expired.
HighCrit HighCrit
2 parents c72dfd4 + 2737c55 commit 7dc00bf
Showing 16 changed files with 631 additions and 551 deletions.
31 changes: 20 additions & 11 deletions src/spatial/detail/ArborX_BruteForceImpl.hpp
Original file line number Diff line number Diff line change
@@ -60,14 +60,30 @@ struct BruteForceImpl
using PredicateType = typename Predicates::value_type;
using IndexableType = std::decay_t<decltype(indexables(0))>;

using ScratchPredicateType =
Kokkos::View<PredicateType *,
typename ExecutionSpace::scratch_memory_space,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
using ScratchIndexableType =
Kokkos::View<IndexableType *,
typename ExecutionSpace::scratch_memory_space,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>;

int const n_indexables = values.size();
int const n_predicates = predicates.size();
int max_scratch_size = TeamPolicy::scratch_size_max(0);
int const max_scratch_size = TeamPolicy::scratch_size_max(0);
// FIXME: adjust max_scratch_size to compensate for potential alignment
// additions to make sure we don't accidentally exceed capacity
int const alignment_correction = ScratchPredicateType::shmem_size(0) +
ScratchIndexableType::shmem_size(0);
int available_scratch_size =
Kokkos::max(0, max_scratch_size - alignment_correction);

// half of the scratch memory used by predicates and half for indexables
int const predicates_per_team =
max_scratch_size / 2 / sizeof(PredicateType);
available_scratch_size / 2 / sizeof(PredicateType);
int const indexables_per_team =
max_scratch_size / 2 / sizeof(IndexableType);
available_scratch_size / 2 / sizeof(IndexableType);
ARBORX_ASSERT(predicates_per_team > 0);
ARBORX_ASSERT(indexables_per_team > 0);

@@ -77,16 +93,9 @@ struct BruteForceImpl
std::ceil((float)n_predicates / predicates_per_team);
int const n_teams = n_indexable_tiles * n_predicate_tiles;

using ScratchPredicateType =
Kokkos::View<PredicateType *,
typename ExecutionSpace::scratch_memory_space,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
using ScratchIndexableType =
Kokkos::View<IndexableType *,
typename ExecutionSpace::scratch_memory_space,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
int scratch_size = ScratchPredicateType::shmem_size(predicates_per_team) +
ScratchIndexableType::shmem_size(indexables_per_team);
ARBORX_ASSERT(scratch_size <= max_scratch_size);

Kokkos::parallel_for(
"ArborX::BruteForce::query::spatial::"
8 changes: 8 additions & 0 deletions src/spatial/detail/ArborX_Predicates.hpp
Original file line number Diff line number Diff line change
@@ -175,6 +175,14 @@ struct PredicateWithAttachment : Predicate
: Predicate(std::forward<Predicate>(pred))
, _data(std::forward<Data>(data))
{}
#if defined(KOKKOS_ENABLE_CUDA) && defined(KOKKOS_COMPILER_CLANG) && \
(KOKKOS_COMPILER_CLANG < 1500)
// FIXME_NVCC, FIXME_CLANG: Without explicit destructor, it causes misaligned
// address in local write when running query tests with double precision, and
// errors at least Clang 14 and CUDA 11.0.3. No idea why that happens.
KOKKOS_FUNCTION ~PredicateWithAttachment() {}
#endif

Data _data;
};

110 changes: 57 additions & 53 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -82,68 +82,72 @@ add_test(NAME ArborX_Test_Geometry COMMAND ArborX_Test_Geometry.exe)

set(ARBORX_TEST_QUERY_TREE_SOURCES)
foreach(_test Callbacks Degenerate ManufacturedSolution ComparisonWithBoost)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH.cpp.tmp"
"#include <ArborX_LinearBVH.hpp>\n"
"#include <ArborX_Box.hpp>\n"
"#include \"ArborXTest_LegacyTree.hpp\"\n"
"template <class MemorySpace>\n"
"using ArborX_Legacy_BVH_Box =\n"
" LegacyTree<ArborX::BoundingVolumeHierarchy<\n"
" MemorySpace, ArborX::PairValueIndex<ArborX::Box<3, float>>,\n"
" ArborX::Experimental::DefaultIndexableGetter, ArborX::Box<3, float>>>;\n"
"#define ARBORX_TEST_TREE_TYPES Tuple<ArborX_Legacy_BVH_Box>\n"
"#define ARBORX_TEST_DEVICE_TYPES std::tuple<${ARBORX_DEVICE_TYPES}>\n"
"#include <tstQueryTree${_test}.cpp>\n"
)
configure_file(
"${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH.cpp.tmp"
"${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH.cpp" COPYONLY
)
list(APPEND ARBORX_TEST_QUERY_TREE_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH.cpp")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BF.cpp.tmp"
"#include <ArborX_BruteForce.hpp>\n"
"#include <ArborX_Box.hpp>\n"
"#include \"ArborXTest_LegacyTree.hpp\"\n"
"template <class MemorySpace>\n"
"using ArborX_Legacy_BruteForce_Box =\n"
" LegacyTree<ArborX::BruteForce<\n"
" MemorySpace, ArborX::PairValueIndex<ArborX::Box<3, float>>,\n"
" ArborX::Experimental::DefaultIndexableGetter, ArborX::Box<3, float>>>;\n"
"#define ARBORX_TEST_TREE_TYPES Tuple<ArborX_Legacy_BruteForce_Box>\n"
"#define ARBORX_TEST_DEVICE_TYPES std::tuple<${ARBORX_DEVICE_TYPES}>\n"
"#define ARBORX_TEST_DISABLE_CALLBACK_EARLY_EXIT\n"
"#include <tstQueryTree${_test}.cpp>\n"
)
configure_file(
"${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BF.cpp.tmp"
"${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BF.cpp" COPYONLY
)
list(APPEND ARBORX_TEST_QUERY_TREE_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BF.cpp")
foreach(_bounding_volume KDOP14 KDOP18) # purposefully ommitting KDOP6 and KDOP26 to reduce the number of instantiations
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH_${_bounding_volume}.cpp.tmp"
foreach (_precision float double)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH_${_precision}.cpp.tmp"
"#include <ArborX_LinearBVH.hpp>\n"
"#include <ArborX_KDOP.hpp>\n"
"#include <ArborX_Box.hpp>\n"
"#include \"ArborXTest_LegacyTree.hpp\"\n"
"using KDOP6 = ArborX::Experimental::KDOP<3, 6>;\n"
"using KDOP14 = ArborX::Experimental::KDOP<3, 14>;\n"
"using KDOP18 = ArborX::Experimental::KDOP<3, 18>;\n"
"using KDOP26 = ArborX::Experimental::KDOP<3, 26>;\n"
"template <class MemorySpace>\n"
"using ArborX_Legacy_BVH_${_bounding_volume} =\n"
"using ArborX_Legacy_BVH_Box_${_precision} =\n"
" LegacyTree<ArborX::BoundingVolumeHierarchy<\n"
" MemorySpace, ArborX::PairValueIndex<${_bounding_volume}>,\n"
" ArborX::Experimental::DefaultIndexableGetter, ${_bounding_volume}>>;\n"
"#define ARBORX_TEST_TREE_TYPES Tuple<ArborX_Legacy_BVH_${_bounding_volume}>\n"
" MemorySpace, ArborX::PairValueIndex<ArborX::Box<3, ${_precision}>>,\n"
" ArborX::Experimental::DefaultIndexableGetter, ArborX::Box<3, ${_precision}>>>;\n"
"#define ARBORX_TEST_TREE_TYPES Tuple<ArborX_Legacy_BVH_Box_${_precision}>\n"
"#define ARBORX_TEST_DEVICE_TYPES std::tuple<${ARBORX_DEVICE_TYPES}>\n"
"#define ARBORX_TEST_DISABLE_NEAREST_QUERY\n"
"#define ARBORX_TEST_DISABLE_SPATIAL_QUERY_INTERSECTS_SPHERE\n"
"#include <tstQueryTree${_test}.cpp>\n"
)
configure_file(
"${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH_${_bounding_volume}.cpp.tmp"
"${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH_${_bounding_volume}.cpp" COPYONLY
"${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH_${_precision}.cpp.tmp"
"${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH_${_precision}.cpp" COPYONLY
)
list(APPEND ARBORX_TEST_QUERY_TREE_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH_${_bounding_volume}.cpp")
list(APPEND ARBORX_TEST_QUERY_TREE_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH_${_precision}.cpp")

file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BF_${_precision}.cpp.tmp"
"#include <ArborX_BruteForce.hpp>\n"
"#include <ArborX_Box.hpp>\n"
"#include \"ArborXTest_LegacyTree.hpp\"\n"
"template <class MemorySpace>\n"
"using ArborX_Legacy_BruteForce_Box_${_precision} =\n"
" LegacyTree<ArborX::BruteForce<\n"
" MemorySpace, ArborX::PairValueIndex<ArborX::Box<3, ${_precision}>>,\n"
" ArborX::Experimental::DefaultIndexableGetter, ArborX::Box<3, ${_precision}>>>;\n"
"#define ARBORX_TEST_TREE_TYPES Tuple<ArborX_Legacy_BruteForce_Box_${_precision}>\n"
"#define ARBORX_TEST_DEVICE_TYPES std::tuple<${ARBORX_DEVICE_TYPES}>\n"
"#define ARBORX_TEST_DISABLE_CALLBACK_EARLY_EXIT\n"
"#include <tstQueryTree${_test}.cpp>\n"
)
configure_file(
"${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BF_${_precision}.cpp.tmp"
"${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BF_${_precision}.cpp" COPYONLY
)
list(APPEND ARBORX_TEST_QUERY_TREE_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BF_${_precision}.cpp")

foreach(_bounding_volume KDOP14 KDOP18) # purposefully ommitting KDOP6 and KDOP26 to reduce the number of instantiations
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH_${_bounding_volume}_${_precision}.cpp.tmp"
"#include <ArborX_LinearBVH.hpp>\n"
"#include <ArborX_KDOP.hpp>\n"
"#include \"ArborXTest_LegacyTree.hpp\"\n"
"using KDOP6_${_precision} = ArborX::Experimental::KDOP<3, 6, ${_precision}>;\n"
"using KDOP14_${_precision} = ArborX::Experimental::KDOP<3, 14, ${_precision}>;\n"
"using KDOP18_${_precision} = ArborX::Experimental::KDOP<3, 18, ${_precision}>;\n"
"using KDOP26_${_precision} = ArborX::Experimental::KDOP<3, 26, ${_precision}>;\n"
"template <class MemorySpace>\n"
"using ArborX_Legacy_BVH_${_bounding_volume}_${_precision} =\n"
" LegacyTree<ArborX::BoundingVolumeHierarchy<\n"
" MemorySpace, ArborX::PairValueIndex<${_bounding_volume}_${_precision}>,\n"
" ArborX::Experimental::DefaultIndexableGetter, ${_bounding_volume}_${_precision}>>;\n"
"#define ARBORX_TEST_TREE_TYPES Tuple<ArborX_Legacy_BVH_${_bounding_volume}_${_precision}>\n"
"#define ARBORX_TEST_DEVICE_TYPES std::tuple<${ARBORX_DEVICE_TYPES}>\n"
"#define ARBORX_TEST_DISABLE_NEAREST_QUERY\n"
"#define ARBORX_TEST_DISABLE_SPATIAL_QUERY_INTERSECTS_SPHERE\n"
"#include <tstQueryTree${_test}.cpp>\n"
)
configure_file(
"${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH_${_bounding_volume}_${_precision}.cpp.tmp"
"${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH_${_bounding_volume}_${_precision}.cpp" COPYONLY
)
list(APPEND ARBORX_TEST_QUERY_TREE_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/tstQueryTree${_test}_BVH_${_bounding_volume}_${_precision}.cpp")
endforeach()
endforeach()
endforeach()

Loading

0 comments on commit 7dc00bf

Please sign in to comment.