Skip to content

Commit

Permalink
Fix examples, benchmarks, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop committed Oct 5, 2024
1 parent b00ebda commit 7d044fb
Show file tree
Hide file tree
Showing 17 changed files with 134 additions and 102 deletions.
53 changes: 30 additions & 23 deletions benchmarks/brute_force_vs_bvh/brute_force_vs_bvh_timpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,51 @@ using MemorySpace = ExecutionSpace::memory_space;

namespace ArborXBenchmark
{
template <int DIM, typename FloatingPoint>
struct PrimitivesTag
{};
struct PredicatesTag
{};

template <int DIM, typename FloatingPoint, typename Tag>
struct Placeholder
{
int count;
};
} // namespace ArborXBenchmark

// Primitives are a set of points located at (i, i, i),
// with i = 0, ..., n-1
template <int DIM, typename FloatingPoint>
struct ArborX::AccessTraits<ArborXBenchmark::Placeholder<DIM, FloatingPoint>,
ArborX::PrimitivesTag>
template <int DIM, typename FloatingPoint, typename Tag>
struct ArborX::AccessTraits<
ArborXBenchmark::Placeholder<DIM, FloatingPoint, Tag>>
{
using Primitives = ArborXBenchmark::Placeholder<DIM, FloatingPoint>;
using memory_space = MemorySpace;
using size_type = typename MemorySpace::size_type;
static KOKKOS_FUNCTION size_type size(Primitives d) { return d.count; }
static KOKKOS_FUNCTION auto get(Primitives, size_type i)

static KOKKOS_FUNCTION size_type
size(ArborXBenchmark::Placeholder<DIM, FloatingPoint, Tag> d)
{
return d.count;
}

static KOKKOS_FUNCTION auto
get(ArborXBenchmark::Placeholder<DIM, FloatingPoint,
ArborXBenchmark::PrimitivesTag>,
size_type i)
{
// Primitives are a set of points located at (i, i, i),
// with i = 0, ..., n-1
ArborX::Point<DIM, FloatingPoint> point;
for (int d = 0; d < DIM; ++d)
point[d] = i;
return point;
}
};

// Predicates are sphere intersections with spheres of radius i
// centered at (i, i, i), with i = 0, ..., n-1
template <int DIM, typename FloatingPoint>
struct ArborX::AccessTraits<ArborXBenchmark::Placeholder<DIM, FloatingPoint>,
ArborX::PredicatesTag>
{
using Predicates = ArborXBenchmark::Placeholder<DIM, FloatingPoint>;
using memory_space = MemorySpace;
using size_type = typename MemorySpace::size_type;
static KOKKOS_FUNCTION size_type size(Predicates d) { return d.count; }
static KOKKOS_FUNCTION auto get(Predicates, size_type i)
static KOKKOS_FUNCTION auto
get(ArborXBenchmark::Placeholder<DIM, FloatingPoint,
ArborXBenchmark::PredicatesTag>,
size_type i)
{
// Predicates are sphere intersections with spheres of radius i
// centered at (i, i, i), with i = 0, ..., n-1
ArborX::Point<DIM, FloatingPoint> center;
for (int d = 0; d < DIM; ++d)
center[d] = i;
Expand All @@ -75,8 +82,8 @@ template <int DIM, typename FloatingPoint>
static void run_fp(int nprimitives, int nqueries, int nrepeats)
{
ExecutionSpace space{};
Placeholder<DIM, FloatingPoint> primitives{nprimitives};
Placeholder<DIM, FloatingPoint> predicates{nqueries};
Placeholder<DIM, FloatingPoint, PrimitivesTag> primitives{nprimitives};
Placeholder<DIM, FloatingPoint, PredicatesTag> predicates{nqueries};

for (int i = 0; i < nrepeats; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/dbscan/ArborX_DBSCANVerification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ bool verifyDBSCAN(ExecutionSpace exec_space, Primitives const &primitives,

static_assert(Kokkos::is_view<LabelsView>{});

using Points = Details::AccessValues<Primitives, PrimitivesTag>;
using Points = Details::AccessValues<Primitives>;
using MemorySpace = typename Points::memory_space;

static_assert(std::is_same<typename LabelsView::value_type, int>{});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct Triangles
};

template <typename MemorySpace>
class ArborX::AccessTraits<Triangles<MemorySpace>, ArborX::PrimitivesTag>
class ArborX::AccessTraits<Triangles<MemorySpace>>
{
using Self = Triangles<MemorySpace>;

Expand Down
4 changes: 2 additions & 2 deletions examples/access_traits/example_cuda_access_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct Spheres
};

template <>
struct ArborX::AccessTraits<PointCloud, ArborX::PrimitivesTag>
struct ArborX::AccessTraits<PointCloud>
{
static KOKKOS_FUNCTION std::size_t size(PointCloud const &cloud)
{
Expand All @@ -49,7 +49,7 @@ struct ArborX::AccessTraits<PointCloud, ArborX::PrimitivesTag>
};

template <>
struct ArborX::AccessTraits<Spheres, ArborX::PredicatesTag>
struct ArborX::AccessTraits<Spheres>
{
static KOKKOS_FUNCTION std::size_t size(Spheres const &d) { return d.N; }
static KOKKOS_FUNCTION auto get(Spheres const &d, std::size_t i)
Expand Down
4 changes: 2 additions & 2 deletions examples/access_traits/example_host_access_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include <random>
#include <vector>

template <typename T, typename Tag>
struct ArborX::AccessTraits<std::vector<T>, Tag>
template <typename T>
struct ArborX::AccessTraits<std::vector<T>>
{
static std::size_t size(std::vector<T> const &v) { return v.size(); }
static T const &get(std::vector<T> const &v, std::size_t i) { return v[i]; }
Expand Down
29 changes: 13 additions & 16 deletions examples/brute_force/example_brute_force.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

#include <iostream>

struct PrimitivesTag
{};
struct PredicatesTag
{};

template <typename Tag>
struct Dummy
{
int count;
Expand All @@ -23,26 +29,17 @@ struct Dummy
using ExecutionSpace = Kokkos::DefaultExecutionSpace;
using MemorySpace = ExecutionSpace::memory_space;

template <>
struct ArborX::AccessTraits<Dummy, ArborX::PrimitivesTag>
template <typename Tag>
struct ArborX::AccessTraits<Dummy<Tag>>
{
using memory_space = MemorySpace;
using size_type = typename MemorySpace::size_type;
static KOKKOS_FUNCTION size_type size(Dummy const &d) { return d.count; }
static KOKKOS_FUNCTION auto get(Dummy const &, size_type i)
static KOKKOS_FUNCTION size_type size(Dummy<Tag> const &d) { return d.count; }
static KOKKOS_FUNCTION auto get(Dummy<PrimitivesTag> const &, size_type i)
{
return ArborX::Point{(float)i, (float)i, (float)i};
}
};

template <>
struct ArborX::AccessTraits<Dummy, ArborX::PredicatesTag>
{
using memory_space = MemorySpace;
using size_type = typename MemorySpace::size_type;

static KOKKOS_FUNCTION size_type size(Dummy const &d) { return d.count; }
static KOKKOS_FUNCTION auto get(Dummy const &, size_type i)
static KOKKOS_FUNCTION auto get(Dummy<PredicatesTag> const &, size_type i)
{
ArborX::Point center{(float)i, (float)i, (float)i};
return ArborX::intersects(Sphere{center, (float)i});
Expand All @@ -69,8 +66,8 @@ int main(int argc, char *argv[])
int nprimitives = 5;
int npredicates = 5;

Dummy primitives{nprimitives};
Dummy predicates{npredicates};
Dummy<PrimitivesTag> primitives{nprimitives};
Dummy<PredicatesTag> predicates{npredicates};

unsigned int out_count;
{
Expand Down
4 changes: 2 additions & 2 deletions examples/callback/example_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct NearestToOrigin
};

template <>
struct ArborX::AccessTraits<FirstOctant, ArborX::PredicatesTag>
struct ArborX::AccessTraits<FirstOctant>
{
static KOKKOS_FUNCTION std::size_t size(FirstOctant) { return 1; }
static KOKKOS_FUNCTION auto get(FirstOctant, std::size_t)
Expand All @@ -40,7 +40,7 @@ struct ArborX::AccessTraits<FirstOctant, ArborX::PredicatesTag>
};

template <>
struct ArborX::AccessTraits<NearestToOrigin, ArborX::PredicatesTag>
struct ArborX::AccessTraits<NearestToOrigin>
{
static KOKKOS_FUNCTION std::size_t size(NearestToOrigin) { return 1; }
static KOKKOS_FUNCTION auto get(NearestToOrigin d, std::size_t)
Expand Down
2 changes: 1 addition & 1 deletion examples/molecular_dynamics/example_molecular_dynamics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct Neighbors
};

template <class MemorySpace>
struct ArborX::AccessTraits<Neighbors<MemorySpace>, ArborX::PredicatesTag>
struct ArborX::AccessTraits<Neighbors<MemorySpace>>
{
using memory_space = MemorySpace;
using size_type = std::size_t;
Expand Down
3 changes: 1 addition & 2 deletions examples/raytracing/example_raytracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ struct DepositEnergy
} // namespace OrderedIntersectsBased

template <typename MemorySpace>
struct ArborX::AccessTraits<OrderedIntersectsBased::Rays<MemorySpace>,
ArborX::PredicatesTag>
struct ArborX::AccessTraits<OrderedIntersectsBased::Rays<MemorySpace>>
{
using memory_space = MemorySpace;
using size_type = std::size_t;
Expand Down
5 changes: 2 additions & 3 deletions test/ArborXTest_LegacyTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ template <typename Primitives, typename BoundingVolume>
class LegacyValues
{
Primitives _primitives;
using Access = ArborX::AccessTraits<Primitives, ArborX::PrimitivesTag>;
using Access = ArborX::AccessTraits<Primitives>;

public:
using memory_space = typename Access::memory_space;
Expand Down Expand Up @@ -67,8 +67,7 @@ class LegacyValues
};

template <typename Primitives, typename BoundingVolume>
struct ArborX::AccessTraits<LegacyValues<Primitives, BoundingVolume>,
ArborX::PrimitivesTag>
struct ArborX::AccessTraits<LegacyValues<Primitives, BoundingVolume>>
{
using self_type = LegacyValues<Primitives, BoundingVolume>;

Expand Down
3 changes: 1 addition & 2 deletions test/ArborX_BoostRTreeHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ performQueries(RTree<Indexable> const &rtree, UserPredicates const &predicates)
{
namespace KokkosExt = ArborX::Details::KokkosExt;

using Predicates =
ArborX::Details::AccessValues<UserPredicates, ArborX::PredicatesTag>;
using Predicates = ArborX::Details::AccessValues<UserPredicates>;
static_assert(Kokkos::SpaceAccessibility<typename Predicates::memory_space,
Kokkos::HostSpace>::accessible);

Expand Down
6 changes: 2 additions & 4 deletions test/tstAttachIndices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ BOOST_AUTO_TEST_CASE(attach_indices_to_primitives)

Kokkos::View<ArborX::Point<3> *, Kokkos::HostSpace> p("Testing::p", 10);
auto p_with_indices = attach_indices(p);
AccessValues<decltype(p_with_indices), ArborX::PrimitivesTag> p_values{
p_with_indices};
AccessValues<decltype(p_with_indices)> p_values{p_with_indices};
static_assert(std::is_same_v<decltype(p_values(0).index), unsigned>);
BOOST_TEST(p_values(0).index == 0);
BOOST_TEST(p_values(9).index == 9);
Expand All @@ -38,8 +37,7 @@ BOOST_AUTO_TEST_CASE(attach_indices_to_predicates)
using IntersectsPredicate = decltype(ArborX::intersects(ArborX::Point<3>{}));
Kokkos::View<IntersectsPredicate *, Kokkos::HostSpace> q("Testing::q", 10);
auto q_with_indices = attach_indices<long>(q);
AccessValues<decltype(q_with_indices), ArborX::PredicatesTag> q_values{
q_with_indices};
AccessValues<decltype(q_with_indices)> q_values{q_with_indices};
BOOST_TEST(ArborX::getData(q_values(0)) == 0);
BOOST_TEST(ArborX::getData(q_values(9)) == 9);
}
Expand Down
Loading

0 comments on commit 7d044fb

Please sign in to comment.