Skip to content

Commit bf6f89b

Browse files
authored
Merge pull request #1038 from aprokop/simplify_predicates_construction
Add helper functions to construct predicates
2 parents 0e0411c + 0d7579c commit bf6f89b

16 files changed

+209
-271
lines changed

benchmarks/dbscan/ArborX_DBSCANVerification.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ bool verifyDBSCAN(ExecutionSpace exec_space, Primitives const &primitives,
314314
ArborX::BoundingVolumeHierarchy<MemorySpace, ArborX::PairValueIndex<Point>>
315315
bvh(exec_space, ArborX::Experimental::attach_indices(points));
316316

317-
auto const predicates = Details::PrimitivesWithRadius<Points>{points, eps};
317+
auto const predicates = ArborX::Experimental::attach_indices(
318+
ArborX::Experimental::make_intersects(points, eps));
318319

319320
Kokkos::View<int *, MemorySpace> indices("ArborX::DBSCAN::indices", 0);
320321
Kokkos::View<int *, MemorySpace> offset("ArborX::DBSCAN::offset", 0);

benchmarks/distributed_tree_driver/distributed_tree_driver.cpp

+6-51
Original file line numberDiff line numberDiff line change
@@ -170,52 +170,6 @@ class TimeMonitor
170170
}
171171
};
172172

173-
template <typename DeviceType>
174-
struct NearestNeighborsSearches
175-
{
176-
Kokkos::View<ArborX::Point *, DeviceType> points;
177-
int k;
178-
};
179-
template <typename DeviceType>
180-
struct RadiusSearches
181-
{
182-
Kokkos::View<ArborX::Point *, DeviceType> points;
183-
double radius;
184-
};
185-
186-
template <typename DeviceType>
187-
struct ArborX::AccessTraits<RadiusSearches<DeviceType>, ArborX::PredicatesTag>
188-
{
189-
using memory_space = typename DeviceType::memory_space;
190-
static KOKKOS_FUNCTION std::size_t
191-
size(RadiusSearches<DeviceType> const &pred)
192-
{
193-
return pred.points.extent(0);
194-
}
195-
static KOKKOS_FUNCTION auto get(RadiusSearches<DeviceType> const &pred,
196-
std::size_t i)
197-
{
198-
return ArborX::intersects(ArborX::Sphere{pred.points(i), pred.radius});
199-
}
200-
};
201-
202-
template <typename DeviceType>
203-
struct ArborX::AccessTraits<NearestNeighborsSearches<DeviceType>,
204-
ArborX::PredicatesTag>
205-
{
206-
using memory_space = typename DeviceType::memory_space;
207-
static KOKKOS_FUNCTION std::size_t
208-
size(NearestNeighborsSearches<DeviceType> const &pred)
209-
{
210-
return pred.points.extent(0);
211-
}
212-
static KOKKOS_FUNCTION auto
213-
get(NearestNeighborsSearches<DeviceType> const &pred, std::size_t i)
214-
{
215-
return ArborX::nearest(pred.points(i), pred.k);
216-
}
217-
};
218-
219173
namespace bpo = boost::program_options;
220174

221175
template <class NO>
@@ -421,8 +375,8 @@ int main_(std::vector<std::string> const &args, MPI_Comm const comm)
421375
knn->start();
422376
distributed_tree.query(
423377
ExecutionSpace{},
424-
NearestNeighborsSearches<DeviceType>{random_queries, n_neighbors},
425-
values, offsets);
378+
ArborX::Experimental::make_nearest(random_queries, n_neighbors), values,
379+
offsets);
426380
knn->stop();
427381

428382
if (comm_rank == 0)
@@ -457,9 +411,10 @@ int main_(std::vector<std::string> const &args, MPI_Comm const comm)
457411
auto radius = time_monitor.getNewTimer("radius");
458412
MPI_Barrier(comm);
459413
radius->start();
460-
distributed_tree.query(ExecutionSpace{},
461-
RadiusSearches<DeviceType>{random_queries, r},
462-
values, offsets);
414+
distributed_tree.query(
415+
ExecutionSpace{},
416+
ArborX::Experimental::make_intersects(random_queries, r), values,
417+
offsets);
463418
radius->stop();
464419

465420
if (comm_rank == 0)

examples/molecular_dynamics/example_molecular_dynamics.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct ArborX::AccessTraits<Neighbors<MemorySpace>, ArborX::PredicatesTag>
3434
}
3535
static KOKKOS_FUNCTION auto get(Neighbors<MemorySpace> const &x, size_type i)
3636
{
37-
return attach(intersects(Sphere{x._particles(i), x._radius}), (int)i);
37+
return intersects(Sphere{x._particles(i), x._radius});
3838
}
3939
};
4040

@@ -119,7 +119,9 @@ int main(int argc, char *argv[])
119119

120120
Kokkos::View<int *, MemorySpace> indices("Example::indices", 0);
121121
Kokkos::View<int *, MemorySpace> offsets("Example::offsets", 0);
122-
index.query(execution_space, Neighbors<MemorySpace>{particles, r},
122+
index.query(execution_space,
123+
ArborX::Experimental::attach_indices<int>(
124+
Neighbors<MemorySpace>{particles, r}),
123125
ExcludeSelfCollision{}, indices, offsets);
124126

125127
Kokkos::View<float *[3], MemorySpace> forces(

examples/raytracing/example_raytracing.cpp

+3-28
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,6 @@ struct ArborX::AccessTraits<OrderedIntersectsBased::Rays<MemorySpace>,
107107

108108
namespace IntersectsBased
109109
{
110-
/*
111-
* Storage for the rays and access traits used in the query/traverse.
112-
*/
113-
template <typename MemorySpace>
114-
struct Rays
115-
{
116-
Kokkos::View<ArborX::Experimental::Ray *, MemorySpace> _rays;
117-
};
118110

119111
/*
120112
* IntersectedCell is a storage container for all intersections between rays and
@@ -177,25 +169,6 @@ struct AccumulateRaySphereIntersections
177169
};
178170
} // namespace IntersectsBased
179171

180-
template <typename MemorySpace>
181-
struct ArborX::AccessTraits<IntersectsBased::Rays<MemorySpace>,
182-
ArborX::PredicatesTag>
183-
{
184-
using memory_space = MemorySpace;
185-
using size_type = std::size_t;
186-
187-
KOKKOS_FUNCTION
188-
static size_type size(IntersectsBased::Rays<MemorySpace> const &rays)
189-
{
190-
return rays._rays.extent(0);
191-
}
192-
KOKKOS_FUNCTION
193-
static auto get(IntersectsBased::Rays<MemorySpace> const &rays, size_type i)
194-
{
195-
return attach(intersects(rays._rays(i)), (int)i);
196-
}
197-
};
198-
199172
int main(int argc, char *argv[])
200173
{
201174
using ExecutionSpace = Kokkos::DefaultExecutionSpace;
@@ -336,7 +309,9 @@ int main(int argc, char *argv[])
336309
0);
337310
Kokkos::View<int *> offsets("Example::offsets", 0);
338311
bvh.query(
339-
exec_space, IntersectsBased::Rays<MemorySpace>{rays},
312+
exec_space,
313+
ArborX::Experimental::attach_indices<int>(
314+
ArborX::Experimental::make_intersects(rays)),
340315
IntersectsBased::AccumulateRaySphereIntersections<MemorySpace>{boxes},
341316
values, offsets);
342317

src/ArborX.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <ArborX_Exception.hpp>
2424
#include <ArborX_LinearBVH.hpp>
2525
#include <ArborX_Point.hpp>
26+
#include <ArborX_PredicateHelpers.hpp>
2627
#include <ArborX_Predicates.hpp>
2728
#include <ArborX_Sphere.hpp>
2829
// FIXME: we include ArborX_DetailsUtils.hpp only for backward compatibility for

src/ArborX_BruteForce.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <ArborX_DetailsLegacy.hpp>
2323
#include <ArborX_IndexableGetter.hpp>
2424
#include <ArborX_PairValueIndex.hpp>
25+
#include <ArborX_PredicateHelpers.hpp>
2526

2627
#include <Kokkos_Core.hpp>
2728
#include <Kokkos_Profiling_ScopedRegion.hpp>

src/ArborX_DBSCAN.hpp

+7-38
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <ArborX_HyperBox.hpp>
2525
#include <ArborX_HyperSphere.hpp>
2626
#include <ArborX_LinearBVH.hpp>
27+
#include <ArborX_PredicateHelpers.hpp>
2728
#include <ArborX_Sphere.hpp>
2829

2930
namespace ArborX
@@ -52,13 +53,6 @@ struct DBSCANCorePoints
5253
}
5354
};
5455

55-
template <typename Primitives>
56-
struct PrimitivesWithRadius
57-
{
58-
Primitives _primitives;
59-
float _r;
60-
};
61-
6256
struct WithinRadiusGetter
6357
{
6458
float _r;
@@ -100,31 +94,6 @@ struct MixedBoxPrimitives
10094

10195
} // namespace Details
10296

103-
template <typename Primitives>
104-
struct AccessTraits<Details::PrimitivesWithRadius<Primitives>, PredicatesTag>
105-
{
106-
using memory_space = typename Primitives::memory_space;
107-
using Predicates = Details::PrimitivesWithRadius<Primitives>;
108-
109-
static KOKKOS_FUNCTION size_t size(Predicates const &w)
110-
{
111-
return w._primitives.size();
112-
}
113-
static KOKKOS_FUNCTION auto get(Predicates const &w, size_t i)
114-
{
115-
auto const &point = w._primitives(i);
116-
constexpr int dim =
117-
GeometryTraits::dimension_v<std::decay_t<decltype(point)>>;
118-
// FIXME reinterpret_cast is dangerous here if access traits return user
119-
// point structure (e.g., struct MyPoint { float y; float x; })
120-
auto const &hyper_point =
121-
reinterpret_cast<ExperimentalHyperGeometry::Point<dim> const &>(point);
122-
return attach(
123-
intersects(ExperimentalHyperGeometry::Sphere<dim>{hyper_point, w._r}),
124-
(int)i);
125-
}
126-
};
127-
12897
template <typename Primitives, typename PermuteFilter>
12998
struct AccessTraits<Details::PrimitivesWithRadiusReorderedAndFiltered<
13099
Primitives, PermuteFilter>,
@@ -315,8 +284,8 @@ dbscan(ExecutionSpace const &exec_space, Primitives const &primitives,
315284
}
316285
else
317286
{
318-
auto const predicates =
319-
Details::PrimitivesWithRadius<Points>{points, eps};
287+
auto const predicates = ArborX::Experimental::attach_indices(
288+
ArborX::Experimental::make_intersects(points, eps));
320289

321290
// Determine core points
322291
Kokkos::Profiling::pushRegion("ArborX::DBSCAN::clusters::num_neigh");
@@ -437,8 +406,8 @@ dbscan(ExecutionSpace const &exec_space, Primitives const &primitives,
437406
// Perform the queries and build clusters through callback
438407
using CorePoints = Details::CCSCorePoints;
439408
Kokkos::Profiling::pushRegion("ArborX::DBSCAN::clusters::query");
440-
auto const predicates =
441-
Details::PrimitivesWithRadius<Points>{points, eps};
409+
auto const predicates = Experimental::attach_indices(
410+
Experimental::make_intersects(points, eps));
442411
bvh.query(exec_space, predicates,
443412
Details::FDBSCANDenseBoxCallback<UnionFind, CorePoints, Points,
444413
decltype(dense_cell_offsets),
@@ -478,8 +447,8 @@ dbscan(ExecutionSpace const &exec_space, Primitives const &primitives,
478447

479448
// Perform the queries and build clusters through callback
480449
Kokkos::Profiling::pushRegion("ArborX::DBSCAN::clusters::query");
481-
auto const predicates =
482-
Details::PrimitivesWithRadius<Points>{points, eps};
450+
auto const predicates = Experimental::attach_indices(
451+
Experimental::make_intersects(points, eps));
483452
bvh.query(exec_space, predicates,
484453
Details::FDBSCANDenseBoxCallback<UnionFind, CorePoints, Points,
485454
decltype(dense_cell_offsets),

src/ArborX_LinearBVH.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <ArborX_HyperBox.hpp>
3030
#include <ArborX_IndexableGetter.hpp>
3131
#include <ArborX_PairValueIndex.hpp>
32+
#include <ArborX_PredicateHelpers.hpp>
3233
#include <ArborX_SpaceFillingCurves.hpp>
3334
#include <ArborX_TraversalPolicy.hpp>
3435

src/details/ArborX_DetailsFDBSCANDenseBox.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ struct FDBSCANDenseBoxCallback
167167
}
168168
else
169169
{
170-
int j = _permute(_num_points_in_dense_cells + (k - _num_dense_cells));
170+
auto j = _permute(_num_points_in_dense_cells + (k - _num_dense_cells));
171171

172172
// No need to check the distance here, as the fact that we are inside the
173173
// callback guarantees that it is <= eps

src/details/ArborX_DetailsMutualReachabilityDistance.hpp

-28
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,6 @@ struct MaxDistance
4747
}
4848
};
4949

50-
template <class Primitives>
51-
struct NearestK
52-
{
53-
Primitives primitives;
54-
int k; // including self-collisions
55-
};
56-
57-
} // namespace Details
58-
59-
template <class Primitives>
60-
struct AccessTraits<Details::NearestK<Primitives>, PredicatesTag>
61-
{
62-
using memory_space = typename Primitives::memory_space;
63-
using size_type = typename memory_space::size_type;
64-
static KOKKOS_FUNCTION size_type size(Details::NearestK<Primitives> const &x)
65-
{
66-
return x.primitives.size();
67-
}
68-
static KOKKOS_FUNCTION auto get(Details::NearestK<Primitives> const &x,
69-
size_type i)
70-
{
71-
return attach(nearest(x.primitives(i), x.k), i);
72-
}
73-
};
74-
75-
namespace Details
76-
{
77-
7850
template <class CoreDistances>
7951
struct MutualReachability
8052
{

src/details/ArborX_MinimumSpanningTree.hpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <ArborX_DetailsTreeNodeLabeling.hpp>
2121
#include <ArborX_DetailsWeightedEdge.hpp>
2222
#include <ArborX_LinearBVH.hpp>
23+
#include <ArborX_PredicateHelpers.hpp>
2324

2425
#include <Kokkos_Core.hpp>
2526
#include <Kokkos_Profiling_ScopedRegion.hpp>
@@ -66,9 +67,11 @@ struct MinimumSpanningTree
6667
Kokkos::Profiling::pushRegion("ArborX::MST::compute_core_distances");
6768
Kokkos::View<float *, MemorySpace> core_distances(
6869
"ArborX::MST::core_distances", n);
69-
bvh.query(space, NearestK<Points>{points, k},
70-
MaxDistance<Points, decltype(core_distances)>{points,
71-
core_distances});
70+
bvh.query(
71+
space,
72+
Experimental::attach_indices(Experimental::make_nearest(points, k)),
73+
MaxDistance<Points, decltype(core_distances)>{points,
74+
core_distances});
7275
Kokkos::Profiling::popRegion();
7376

7477
MutualReachability<decltype(core_distances)> mutual_reachability{

0 commit comments

Comments
 (0)