Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New BVH::query() overload that only takes predicates and callback #329

Merged
merged 17 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions examples/callback/example_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,15 @@ int main(int argc, char *argv[])

{
// EXPERIMENTAL
// TODO replace with BVH::query(ExecutionSpace, Predicates, Callback) when
// new overload is added
Kokkos::View<int, ExecutionSpace, Kokkos::MemoryTraits<Kokkos::Atomic>> c(
"counter");

ArborX::Details::traverse(
ExecutionSpace{}, bvh, FirstOctant{},
KOKKOS_LAMBDA(int i, int j) { printf("%d %d %d\n", ++c(), i, j); });
#ifndef __NVCC__
bvh.query(ExecutionSpace{}, FirstOctant{},
KOKKOS_LAMBDA(auto /*predicate*/, int j) {
printf("%d %d %d\n", ++c(), -1, j);
});
#endif
}

return 0;
Expand Down
15 changes: 3 additions & 12 deletions src/ArborX_LinearBVH.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ class BoundingVolumeHierarchy
KOKKOS_FUNCTION
bounding_volume_type bounds() const noexcept { return _bounds; }

template <typename ExecutionSpace, typename Predicates,
typename CallbackOrView, typename View, typename... Args>
template <typename ExecutionSpace, typename Predicates, typename... Args>
void query(ExecutionSpace const &space, Predicates const &predicates,
CallbackOrView &&callback_or_view, View &&view,
Args &&... args) const
dalg24 marked this conversation as resolved.
Show resolved Hide resolved
{
Details::check_valid_access_traits(PredicatesTag{}, predicates);
Expand All @@ -67,15 +65,8 @@ class BoundingVolumeHierarchy
ExecutionSpace>::value,
"Predicates must be accessible from the execution space");

Details::check_valid_callback_if_first_argument_is_not_a_view(
callback_or_view, predicates, view);

using Tag = typename Details::AccessTraitsHelper<Access>::tag;

Details::BoundingVolumeHierarchyImpl::queryDispatch(
Tag{}, *this, space, predicates,
std::forward<CallbackOrView>(callback_or_view),
std::forward<View>(view), std::forward<Args>(args)...);
Details::BoundingVolumeHierarchyImpl::query(space, *this, predicates,
std::forward<Args>(args)...);
}

private:
Expand Down
46 changes: 45 additions & 1 deletion src/details/ArborX_DetailsBoundingVolumeHierarchyImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ queryDispatch(NearestPredicateTag, BVH const &bvh, ExecutionSpace const &space,
distances(i) = out(i).second;
});
}
} // namespace BoundingVolumeHierarchyImpl

template <typename Callback, typename Predicates, typename OutputView>
std::enable_if_t<!Kokkos::is_view<Callback>{} &&
Expand Down Expand Up @@ -353,6 +352,51 @@ check_valid_callback_if_first_argument_is_not_a_view(View const &,
// do nothing
}

template <typename ExecutionSpace, typename BVH, typename Predicates,
typename CallbackOrView, typename View, typename... Args>
inline std::enable_if_t<Kokkos::is_view<std::decay_t<View>>{}>
query(ExecutionSpace const &space, BVH const &bvh, Predicates const &predicates,
CallbackOrView &&callback_or_view, View &&view, Args &&... args)
{
check_valid_callback_if_first_argument_is_not_a_view(callback_or_view,
predicates, view);

using Access = AccessTraits<Predicates, Traits::PredicatesTag>;
using Tag = typename AccessTraitsHelper<Access>::tag;

queryDispatch(Tag{}, bvh, space, predicates,
std::forward<CallbackOrView>(callback_or_view),
std::forward<View>(view), std::forward<Args>(args)...);
}

template <typename ExecutionSpace, typename BVH, typename Predicates,
typename Callback>
inline void query(ExecutionSpace const &space, BVH const &bvh,
Predicates const &predicates, Callback const &callback,
Experimental::TraversalPolicy const &policy =
Experimental::TraversalPolicy())
{
// TODO check signature of the callback
if (policy._sort_predicates)
{
Kokkos::Profiling::pushRegion("ArborX:BVH:compute_permutation");
using MemorySpace = typename BVH::memory_space;
using DeviceType = Kokkos::Device<ExecutionSpace, MemorySpace>;
auto permute =
Details::BatchedQueries<DeviceType>::sortQueriesAlongZOrderCurve(
space, bvh.bounds(), predicates);
Kokkos::Profiling::popRegion();

using PermutedPredicates = PermutedData<Predicates, decltype(permute)>;
traverse(space, bvh, PermutedPredicates{predicates, permute}, callback);
}
else
{
traverse(space, bvh, predicates, callback);
}
}

} // namespace BoundingVolumeHierarchyImpl
} // namespace Details
} // namespace ArborX

Expand Down
Loading