Skip to content

Commit

Permalink
Simplify Iota struct usage
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop committed Nov 11, 2024
1 parent 1492fdf commit e1250ce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 44 deletions.
21 changes: 6 additions & 15 deletions benchmarks/bvh_driver/benchmark_registration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,12 @@ struct is_boost_rtree<BoostExt::RTree<Geometry>> : std::true_type
template <typename Geometry>
inline constexpr bool is_boost_rtree_v = is_boost_rtree<Geometry>::value;

template <typename MemorySpace, typename Index = int>
template <typename MemorySpace>
struct Iota
{
static_assert(Kokkos::is_memory_space_v<MemorySpace>);
using memory_space = MemorySpace;
using index_type = Index;

size_t _n;

template <typename T,
typename Enable = std::enable_if_t<std::is_integral_v<T>>>
Iota(T n)
: _n(n)
{}
int _n;
};

template <typename MemorySpace>
Expand All @@ -54,10 +47,7 @@ struct ArborX::AccessTraits<Iota<MemorySpace>, ArborX::PrimitivesTag>

using memory_space = typename Self::memory_space;
static KOKKOS_FUNCTION size_t size(Self const &self) { return self._n; }
static KOKKOS_FUNCTION auto get(Self const &, size_t i)
{
return (typename Self::index_type)i;
}
static KOKKOS_FUNCTION auto get(Self const &, int i) { return i; }
};

struct Spec
Expand Down Expand Up @@ -164,7 +154,8 @@ auto makeTree(ExecutionSpace const &space, Primitives const &primitives)
return TreeType(space, primitives);
else
return TreeType(space,
Iota<typename TreeType::memory_space>{primitives.size()},
Iota<typename TreeType::memory_space>{
static_cast<int>(primitives.size())},
primitives);
}

Expand Down
18 changes: 4 additions & 14 deletions examples/brute_force/example_brute_force.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,12 @@ struct Dummy
using ExecutionSpace = Kokkos::DefaultExecutionSpace;
using MemorySpace = ExecutionSpace::memory_space;

template <typename MemorySpace, typename Index = int>
template <typename MemorySpace>
struct Iota
{
static_assert(Kokkos::is_memory_space_v<MemorySpace>);
using memory_space = MemorySpace;
using index_type = Index;

size_t _n;

template <typename T,
typename Enable = std::enable_if_t<std::is_integral_v<T>>>
Iota(T n)
: _n(n)
{}
int _n;
};

template <typename MemorySpace>
Expand All @@ -45,10 +38,7 @@ struct ArborX::AccessTraits<Iota<MemorySpace>, ArborX::PrimitivesTag>

using memory_space = typename Self::memory_space;
static KOKKOS_FUNCTION size_t size(Self const &self) { return self._n; }
static KOKKOS_FUNCTION auto get(Self const &, size_t i)
{
return (typename Self::index_type)i;
}
static KOKKOS_FUNCTION auto get(Self const &, int i) { return i; }
};

struct DummyIndexableGetter
Expand Down
20 changes: 5 additions & 15 deletions test/tstQueryTreeIntersectsKDOP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,12 @@

#include <boost/test/unit_test.hpp>

template <typename MemorySpace, typename Index = int>
template <typename MemorySpace>
struct Iota
{
static_assert(Kokkos::is_memory_space_v<MemorySpace>);
using memory_space = MemorySpace;
using index_type = Index;

size_t _n;

template <typename T,
typename Enable = std::enable_if_t<std::is_integral_v<T>>>
Iota(T n)
: _n(n)
{}
int _n;
};

template <typename MemorySpace>
Expand All @@ -40,10 +33,7 @@ struct ArborX::AccessTraits<Iota<MemorySpace>, ArborX::PrimitivesTag>

using memory_space = typename Self::memory_space;
static KOKKOS_FUNCTION size_t size(Self const &self) { return self._n; }
static KOKKOS_FUNCTION auto get(Self const &, size_t i)
{
return (typename Self::index_type)i;
}
static KOKKOS_FUNCTION auto get(Self const &, int i) { return i; }
};

#include <vector>
Expand Down Expand Up @@ -73,7 +63,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(intersects_kdop, DeviceType, ARBORX_DEVICE_TYPES)
{{0, 0, 3}}, // 12
};
ArborX::BoundingVolumeHierarchy const tree(
ExecutionSpace{}, Iota<MemorySpace>{primitives.size()},
ExecutionSpace{}, Iota<MemorySpace>{static_cast<int>(primitives.size())},
Kokkos::create_mirror_view_and_copy(
MemorySpace{},
Kokkos::View<Point *, Kokkos::HostSpace, Kokkos::MemoryUnmanaged>(
Expand Down

0 comments on commit e1250ce

Please sign in to comment.