-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow TreeTraversal to run individual queries in non-batch mode (#917)
Co-authored-by: Daniel Arndt <[email protected]>
- Loading branch information
1 parent
3f8fbc9
commit 2d3c687
Showing
4 changed files
with
172 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/**************************************************************************** | ||
* Copyright (c) 2023 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 * | ||
****************************************************************************/ | ||
|
||
#include "ArborX_EnableDeviceTypes.hpp" // ARBORX_DEVICE_TYPES | ||
#include <ArborX.hpp> | ||
|
||
#include "BoostTest_CUDA_clang_workarounds.hpp" | ||
#include <boost/test/unit_test.hpp> | ||
|
||
#include <numeric> | ||
#include <vector> | ||
|
||
BOOST_AUTO_TEST_SUITE(PerThread) | ||
|
||
struct IntersectionCallback | ||
{ | ||
int query_index; | ||
bool &success; | ||
|
||
template <typename Query, typename Value> | ||
KOKKOS_FUNCTION void operator()(Query const &, Value const &value) const | ||
{ | ||
success = (query_index == value.index); | ||
} | ||
}; | ||
|
||
BOOST_AUTO_TEST_CASE_TEMPLATE(callback_intersects, DeviceType, | ||
ARBORX_DEVICE_TYPES) | ||
{ | ||
using MemorySpace = typename DeviceType::memory_space; | ||
using ExecutionSpace = typename DeviceType::execution_space; | ||
using Tree = ArborX::BVH<MemorySpace>; | ||
|
||
int const n = 10; | ||
Kokkos::View<ArborX::Point *, DeviceType> points( | ||
Kokkos::view_alloc(Kokkos::WithoutInitializing, "points"), n); | ||
Kokkos::parallel_for( | ||
Kokkos::RangePolicy<ExecutionSpace>(0, n), KOKKOS_LAMBDA(int i) { | ||
points(i) = {{(float)i, (float)i, (float)i}}; | ||
}); | ||
|
||
Tree const tree(ExecutionSpace{}, points); | ||
|
||
bool success; | ||
Kokkos::parallel_reduce( | ||
Kokkos::RangePolicy<ExecutionSpace>(0, n), | ||
KOKKOS_LAMBDA(int i, bool &update) { | ||
float center = i; | ||
ArborX::Box box{{center - .5f, center - .5f, center - .5f}, | ||
{center + .5f, center + .5f, center + .5f}}; | ||
tree.query(ArborX::Experimental::PerThread{}, ArborX::intersects(box), | ||
IntersectionCallback{i, update}); | ||
}, | ||
Kokkos::LAnd<bool, Kokkos::HostSpace>(success)); | ||
|
||
BOOST_TEST(success); | ||
} | ||
|
||
struct OrderedIntersectionCallback | ||
{ | ||
int query_index; | ||
bool &success; | ||
|
||
template <typename Query, typename Value> | ||
KOKKOS_FUNCTION auto operator()(Query const &, Value const &value) const | ||
{ | ||
success = (query_index == value.index); | ||
return ArborX::CallbackTreeTraversalControl::early_exit; | ||
} | ||
}; | ||
|
||
BOOST_AUTO_TEST_CASE_TEMPLATE(callback_ordered_intersects, DeviceType, | ||
ARBORX_DEVICE_TYPES) | ||
{ | ||
using MemorySpace = typename DeviceType::memory_space; | ||
using ExecutionSpace = typename DeviceType::execution_space; | ||
using Tree = ArborX::BVH<MemorySpace>; | ||
|
||
int const n = 10; | ||
Kokkos::View<ArborX::Point *, DeviceType> points( | ||
Kokkos::view_alloc(Kokkos::WithoutInitializing, "points"), n); | ||
Kokkos::parallel_for( | ||
Kokkos::RangePolicy<ExecutionSpace>(0, n), KOKKOS_LAMBDA(int i) { | ||
points(i) = {{(float)i, (float)i, (float)i}}; | ||
}); | ||
|
||
Tree const tree(ExecutionSpace{}, points); | ||
|
||
bool success; | ||
Kokkos::parallel_reduce( | ||
Kokkos::RangePolicy<ExecutionSpace>(0, n), | ||
KOKKOS_LAMBDA(int i, bool &update) { | ||
float center = i; | ||
ArborX::Box box{{center - .5f, center - .5f, center - .5f}, | ||
{center + .5f, center + .5f, center + .5f}}; | ||
tree.query(ArborX::Experimental::PerThread{}, | ||
ArborX::Experimental::ordered_intersects(box), | ||
OrderedIntersectionCallback{i, update}); | ||
}, | ||
Kokkos::LAnd<bool, Kokkos::HostSpace>(success)); | ||
|
||
BOOST_TEST(success); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |