Skip to content

Commit

Permalink
Merge pull request #930 from aprokop/fix_labels
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop authored Aug 16, 2023
2 parents 25e20e6 + 2053540 commit 5c55361
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 54 deletions.
8 changes: 4 additions & 4 deletions benchmarks/brute_force_vs_bvh/brute_force_vs_bvh_timpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ void ArborXBenchmark::run(int nprimitives, int nqueries, int nrepeats)
MemorySpace, ArborX::Details::PairIndexVolume<Box>>
bvh{space, primitives};

Kokkos::View<int *, ExecutionSpace> indices("indices_ref", 0);
Kokkos::View<int *, ExecutionSpace> offset("offset_ref", 0);
Kokkos::View<int *, ExecutionSpace> indices("Benchmark::indices_ref", 0);
Kokkos::View<int *, ExecutionSpace> offset("Benchmark::offset_ref", 0);
bvh.query(space, predicates, indices, offset);

space.fence();
Expand All @@ -111,8 +111,8 @@ void ArborXBenchmark::run(int nprimitives, int nqueries, int nrepeats)
Kokkos::Timer timer;
ArborX::BruteForce<MemorySpace, Box> brute{space, primitives};

Kokkos::View<int *, ExecutionSpace> indices("indices", 0);
Kokkos::View<int *, ExecutionSpace> offset("offset", 0);
Kokkos::View<int *, ExecutionSpace> indices("Benchmark::indices", 0);
Kokkos::View<int *, ExecutionSpace> offset("Benchmark::offset", 0);
brute.query(space, predicates, indices, offset);

space.fence();
Expand Down
27 changes: 16 additions & 11 deletions benchmarks/bvh_driver/benchmark_registration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ Kokkos::View<ArborX::Point *, DeviceType>
constructPoints(int n_values, PointCloudType point_cloud_type)
{
Kokkos::View<ArborX::Point *, DeviceType> random_points(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "random_points"),
Kokkos::view_alloc(Kokkos::WithoutInitializing,
"Benchmark::random_points"),
n_values);
// Generate random points uniformly distributed within a box. The edge
// length of the box chosen such that object density (here objects will be
Expand All @@ -119,22 +120,24 @@ makeSpatialQueries(int n_values, int n_queries, int n_neighbors,
PointCloudType target_point_cloud_type)
{
Kokkos::View<ArborX::Point *, DeviceType> random_points(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "random_points"),
Kokkos::view_alloc(Kokkos::WithoutInitializing,
"Benchmark::random_points"),
n_queries);
auto const a = std::cbrt(n_values);
generatePointCloud(target_point_cloud_type, a, random_points);

Kokkos::View<decltype(ArborX::intersects(ArborX::Sphere{})) *, DeviceType>
queries(Kokkos::view_alloc(Kokkos::WithoutInitializing, "queries"),
n_queries);
queries(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "Benchmark::queries"),
n_queries);
// Radius is computed so that the number of results per query for a uniformly
// distributed points in a [-a,a]^3 box is approximately n_neighbors.
// Calculation: n_values*(4/3*pi*r^3)/(2a)^3 = n_neighbors
double const r = std::cbrt(static_cast<double>(n_neighbors) * 6. /
Kokkos::numbers::pi_v<double>);
using ExecutionSpace = typename DeviceType::execution_space;
Kokkos::parallel_for(
"bvh_driver:setup_radius_search_queries",
"Benchmark::setup_radius_search_queries",
Kokkos::RangePolicy<ExecutionSpace>(0, n_queries), KOKKOS_LAMBDA(int i) {
queries(i) = ArborX::intersects(ArborX::Sphere{random_points(i), r});
});
Expand All @@ -147,16 +150,18 @@ makeNearestQueries(int n_values, int n_queries, int n_neighbors,
PointCloudType target_point_cloud_type)
{
Kokkos::View<ArborX::Point *, DeviceType> random_points(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "random_points"),
Kokkos::view_alloc(Kokkos::WithoutInitializing,
"Benchmark::random_points"),
n_queries);
auto const a = std::cbrt(n_values);
generatePointCloud(target_point_cloud_type, a, random_points);

Kokkos::View<ArborX::Nearest<ArborX::Point> *, DeviceType> queries(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "queries"), n_queries);
Kokkos::view_alloc(Kokkos::WithoutInitializing, "Benchmark::queries"),
n_queries);
using ExecutionSpace = typename DeviceType::execution_space;
Kokkos::parallel_for(
"bvh_driver:setup_knn_search_queries",
"Benchmark::setup_knn_search_queries",
Kokkos::RangePolicy<ExecutionSpace>(0, n_queries), KOKKOS_LAMBDA(int i) {
queries(i) =
ArborX::nearest<ArborX::Point>(random_points(i), n_neighbors);
Expand Down Expand Up @@ -314,8 +319,8 @@ void BM_knn_search(benchmark::State &state, Spec const &spec)

for (auto _ : state)
{
Kokkos::View<int *, DeviceType> offset("offset", 0);
Kokkos::View<int *, DeviceType> indices("indices", 0);
Kokkos::View<int *, DeviceType> offset("Benchmark::offset", 0);
Kokkos::View<int *, DeviceType> indices("Benchmark::indices", 0);

exec_space.fence();
auto const start = std::chrono::high_resolution_clock::now();
Expand Down Expand Up @@ -350,7 +355,7 @@ void BM_knn_callback_search(benchmark::State &state, Spec const &spec)

for (auto _ : state)
{
Kokkos::View<int *, DeviceType> num_neigh("Testing::num_neigh",
Kokkos::View<int *, DeviceType> num_neigh("Benchmark::num_neigh",
spec.n_queries);
CountCallback<DeviceType> callback{num_neigh};

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/dbscan/dbscan_timpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ bool ArborXBenchmark::run(ArborXBenchmark::Parameters const &params)
data = GanTao<DIM>(params.n, params.variable_density);
}

auto const primitives = vec2view<MemorySpace>(data, "primitives");
auto const primitives = vec2view<MemorySpace>(data, "Benchmark::primitives");

using Primitives = decltype(primitives);

Expand Down
12 changes: 6 additions & 6 deletions benchmarks/distributed_tree_driver/distributed_tree_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ int main_(std::vector<std::string> const &args, const MPI_Comm comm)
}

Kokkos::View<ArborX::Point *, DeviceType> random_values(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "Testing::values"),
Kokkos::view_alloc(Kokkos::WithoutInitializing, "Benchmark::values"),
n_values);
Kokkos::View<ArborX::Point *, DeviceType> random_queries(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "Testing::queries"),
Kokkos::view_alloc(Kokkos::WithoutInitializing, "Benchmark::queries"),
n_queries);
{
double a = 0.;
Expand Down Expand Up @@ -358,7 +358,7 @@ int main_(std::vector<std::string> const &args, const MPI_Comm comm)
// The boxes in which the points are placed have side length two, centered
// around offset_[xyz] and scaled by a.
Kokkos::View<ArborX::Point *, DeviceType> random_points(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "Testing::points"),
Kokkos::view_alloc(Kokkos::WithoutInitializing, "Benchmark::points"),
std::max(n_values, n_queries));
auto random_points_host = Kokkos::create_mirror_view(random_points);
for (int i = 0; i < random_points.extent_int(0); ++i)
Expand Down Expand Up @@ -425,9 +425,9 @@ int main_(std::vector<std::string> const &args, const MPI_Comm comm)

if (perform_knn_search)
{
Kokkos::View<int *, DeviceType> offsets("Testing::offsets", 0);
Kokkos::View<ArborX::PairIndexRank *, DeviceType> values("Testing::values",
0);
Kokkos::View<int *, DeviceType> offsets("Benchmark::offsets", 0);
Kokkos::View<ArborX::PairIndexRank *, DeviceType> values(
"Benchmark::values", 0);

auto knn = time_monitor.getNewTimer("knn");
MPI_Barrier(comm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,21 @@ int main(int argc, char *argv[])
};

Kokkos::View<ArborX::Point *, MemorySpace> primitives(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "primitives"),
Kokkos::view_alloc(Kokkos::WithoutInitializing, "Benchmark::primitives"),
num_primitives * num_problems);
Kokkos::View<decltype(ArborX::attach(ArborX::intersects(ArborX::Sphere{}),
int{})) *,
MemorySpace>
predicates(Kokkos::view_alloc(Kokkos::WithoutInitializing, "predicates"),
predicates(Kokkos::view_alloc(Kokkos::WithoutInitializing,
"Benchmark::predicates"),
num_predicates * num_problems);
for (int p = 0; p < num_problems; ++p)
{
// Points are placed in a box [offset_x-1, offset_x+1] x [-1, 1] x [-1, 1]
float offset_x = p * shift;

Kokkos::View<ArborX::Point *, MemorySpace> points(
"points", std::max(num_primitives, num_predicates));
"Benchmark::points", std::max(num_primitives, num_predicates));
auto points_host = Kokkos::create_mirror_view(points);
for (int i = 0; i < (int)points.extent(0); ++i)
points_host(i) = {offset_x + random(), random(), random()};
Expand All @@ -164,7 +165,7 @@ int main(int argc, char *argv[])
Kokkos::make_pair(p * num_primitives, (p + 1) * num_primitives)),
Kokkos::subview(points, Kokkos::make_pair(0, num_primitives)));
Kokkos::parallel_for(
"construct_predicates",
"Benchmark::construct_predicates",
Kokkos::RangePolicy<ExecutionSpace>(
ExecutionSpace{}, p * num_predicates, (p + 1) * num_predicates),
KOKKOS_LAMBDA(int i) {
Expand All @@ -190,7 +191,7 @@ int main(int argc, char *argv[])
}
ArborX::BVH<MemorySpace> tree(instances[0], primitives);

Kokkos::View<int *, MemorySpace> counts("counts",
Kokkos::View<int *, MemorySpace> counts("Benchmark::counts",
num_predicates * num_problems);

Kokkos::fence();
Expand Down
18 changes: 8 additions & 10 deletions benchmarks/union_find/union_find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ buildEdges(AllowLoops, ExecutionSpace const &exec_space, int num_edges)
using MemorySpace = typename ExecutionSpace::memory_space;
Kokkos::View<UnweightedEdge *, MemorySpace> edges(
Kokkos::view_alloc(exec_space, Kokkos::WithoutInitializing,
"ArborX::Benchmark::edges"),
"Benchmark::edges"),
num_edges);

Kokkos::Random_XorShift1024_Pool<ExecutionSpace> rand_pool(1984);
Kokkos::parallel_for(
"ArborX::Benchmark::init_edges",
"Benchmark::init_edges",
Kokkos::RangePolicy<ExecutionSpace>(exec_space, 0, num_edges),
KOKKOS_LAMBDA(unsigned i) {
auto rand_gen = rand_pool.get_state();
Expand All @@ -69,10 +69,10 @@ buildEdges(DisallowLoops, ExecutionSpace const &exec_space, int num_edges)
// Construct random permutation by sorting a vector of random values
Kokkos::View<int *, MemorySpace> random_values(
Kokkos::view_alloc(exec_space, Kokkos::WithoutInitializing,
"ArborX::Benchmark::random_values"),
"Benchmark::random_values"),
num_edges);
Kokkos::parallel_for(
"ArborX::Benchmark::init_random_values",
"Benchmark::init_random_values",
Kokkos::RangePolicy<ExecutionSpace>(exec_space, 0, num_edges),
KOKKOS_LAMBDA(int i) {
auto rand_gen = rand_pool.get_state();
Expand All @@ -84,10 +84,10 @@ buildEdges(DisallowLoops, ExecutionSpace const &exec_space, int num_edges)
// Init edges in a random order
Kokkos::View<UnweightedEdge *, MemorySpace> edges(
Kokkos::view_alloc(exec_space, Kokkos::WithoutInitializing,
"ArborX::Benchmark::edges"),
"Benchmark::edges"),
num_edges);
Kokkos::parallel_for(
"ArborX::Benchmark::init_edges",
"Benchmark::init_edges",
Kokkos::RangePolicy<ExecutionSpace>(exec_space, 0, num_edges),
KOKKOS_LAMBDA(unsigned i) {
auto rand_gen = rand_pool.get_state();
Expand All @@ -103,9 +103,7 @@ auto buildUnionFind(ExecutionSpace const &exec_space, int n)
using MemorySpace = typename ExecutionSpace::memory_space;

Kokkos::View<int *, MemorySpace> labels(
Kokkos::view_alloc(Kokkos::WithoutInitializing,
"ArborX::Benchmark::labels"),
n);
Kokkos::view_alloc(Kokkos::WithoutInitializing, "Benchmark::labels"), n);
ArborX::iota(exec_space, labels);
#ifdef KOKKOS_ENABLE_SERIAL
if constexpr (std::is_same_v<ExecutionSpace, Kokkos::Serial>)
Expand Down Expand Up @@ -134,7 +132,7 @@ void BM_union_find(benchmark::State &state)
auto const start = std::chrono::high_resolution_clock::now();

Kokkos::parallel_for(
"ArborX::Benchmark::union-find",
"Benchmark::union-find",
Kokkos::RangePolicy<ExecutionSpace>(exec_space, 0, edges.size()),
KOKKOS_LAMBDA(int e) {
int i = edges(e).source;
Expand Down
7 changes: 4 additions & 3 deletions examples/access_traits/example_cuda_access_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ int main(int argc, char *argv[])
Kokkos::Cuda cuda{stream};
ArborX::BVH<Kokkos::CudaSpace> bvh{cuda, PointCloud{d_a, d_a, d_a, N}};

Kokkos::View<int *, Kokkos::CudaSpace> indices("indices", 0);
Kokkos::View<int *, Kokkos::CudaSpace> offset("offset", 0);
Kokkos::View<int *, Kokkos::CudaSpace> indices("Example::indices", 0);
Kokkos::View<int *, Kokkos::CudaSpace> offset("Example::offset", 0);
ArborX::query(bvh, cuda, Spheres{d_a, d_a, d_a, d_a, N}, indices, offset);

Kokkos::parallel_for(
Kokkos::RangePolicy<Kokkos::Cuda>(cuda, 0, N), KOKKOS_LAMBDA(int i) {
"Example::print_indices", Kokkos::RangePolicy<Kokkos::Cuda>(cuda, 0, N),
KOKKOS_LAMBDA(int i) {
for (int j = offset(i); j < offset(i + 1); ++j)
{
printf("%i %i\n", i, indices(j));
Expand Down
8 changes: 4 additions & 4 deletions examples/brute_force/brute_force.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ int main(int argc, char *argv[])
Kokkos::Timer timer;
ArborX::BoundingVolumeHierarchy<MemorySpace> bvh{space, primitives};

Kokkos::View<int *, ExecutionSpace> indices("indices_ref", 0);
Kokkos::View<int *, ExecutionSpace> offset("offset_ref", 0);
Kokkos::View<int *, ExecutionSpace> indices("Example::indices_ref", 0);
Kokkos::View<int *, ExecutionSpace> offset("Example::offset_ref", 0);
bvh.query(space, predicates, indices, offset);

space.fence();
Expand All @@ -111,8 +111,8 @@ int main(int argc, char *argv[])
Kokkos::Timer timer;
ArborX::BruteForce<MemorySpace> brute{space, primitives};

Kokkos::View<int *, ExecutionSpace> indices("indices", 0);
Kokkos::View<int *, ExecutionSpace> offset("offset", 0);
Kokkos::View<int *, ExecutionSpace> indices("Example::indices", 0);
Kokkos::View<int *, ExecutionSpace> offset("Example::offset", 0);
brute.query(space, predicates, indices, offset);

space.fence();
Expand Down
8 changes: 4 additions & 4 deletions examples/callback/example_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ int main(int argc, char *argv[])
Kokkos::MemoryUnmanaged>(points.data(), points.size()))};

{
Kokkos::View<int *, MemorySpace> values("values", 0);
Kokkos::View<int *, MemorySpace> offsets("offsets", 0);
Kokkos::View<int *, MemorySpace> values("Example::values", 0);
Kokkos::View<int *, MemorySpace> offsets("Example::offsets", 0);
ArborX::query(bvh, ExecutionSpace{}, FirstOctant{}, PrintfCallback{},
values, offsets);
#ifndef __NVCC__
Expand All @@ -106,8 +106,8 @@ int main(int argc, char *argv[])

{
int const k = 10;
Kokkos::View<int *, MemorySpace> values("values", 0);
Kokkos::View<int *, MemorySpace> offsets("offsets", 0);
Kokkos::View<int *, MemorySpace> values("Example::values", 0);
Kokkos::View<int *, MemorySpace> offsets("Example::offsets", 0);
ArborX::query(bvh, ExecutionSpace{}, NearestToOrigin{k}, PrintfCallback{},
values, offsets);
#ifndef __NVCC__
Expand Down
2 changes: 1 addition & 1 deletion examples/dbscan/example_dbscan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int main(int argc, char *argv[])
{
Kokkos::ScopeGuard guard(argc, argv);

Kokkos::View<ArborX::Point *, MemorySpace> cloud("point_cloud", 10);
Kokkos::View<ArborX::Point *, MemorySpace> cloud("Example::point_cloud", 10);
auto cloud_host = Kokkos::create_mirror_view(cloud);
// 4 | 0 7
// 3 | 5 6
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_intersection/example_intersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ int main(int argc, char *argv[])

std::cout << "Starting the queries." << '\n';
// The query will resize indices and offsets accordingly
Kokkos::View<int *, MemorySpace> indices("indices", 0);
Kokkos::View<int *, MemorySpace> offsets("offsets", 0);
Kokkos::View<int *, MemorySpace> indices("Example::indices", 0);
Kokkos::View<int *, MemorySpace> offsets("Example::offsets", 0);

ArborX::query(tree, execution_space, boxes, indices, offsets);
std::cout << "Queries done." << '\n';
Expand Down
7 changes: 4 additions & 3 deletions examples/viz/tree_visualization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void viz(std::string const &prefix, std::string const &infile, int n_neighbors)
{
using ExecutionSpace = Kokkos::DefaultHostExecutionSpace;
using DeviceType = ExecutionSpace::device_type;
Kokkos::View<ArborX::Point *, DeviceType> points("points", 0);
Kokkos::View<ArborX::Point *, DeviceType> points("Example::points", 0);
loadPointCloud(infile, points);

ArborX::BVH<Kokkos::HostSpace> bvh{ExecutionSpace{}, points};
Expand All @@ -91,9 +91,10 @@ void viz(std::string const &prefix, std::string const &infile, int n_neighbors)
int const n_queries = bvh.size();
if (n_neighbors < 0)
n_neighbors = bvh.size();
Kokkos::View<ArborX::Nearest<ArborX::Point> *, DeviceType> queries("queries",
n_queries);
Kokkos::View<ArborX::Nearest<ArborX::Point> *, DeviceType> queries(
"Example::queries", n_queries);
Kokkos::parallel_for(
"Example::inititialize_queries",
Kokkos::RangePolicy<ExecutionSpace>(0, n_queries), KOKKOS_LAMBDA(int i) {
queries(i) = ArborX::nearest(points(i), n_neighbors);
});
Expand Down

0 comments on commit 5c55361

Please sign in to comment.