24#ifndef MORTON_KOKKOS_HPP
25#define MORTON_KOKKOS_HPP
27#if !defined(MORTON_ENABLE_KOKKOS)
28#error "morton/kokkos.hpp requires MORTON_ENABLE_KOKKOS (configure with -DMORTON_ENABLE_KOKKOS=ON)"
32#include <Kokkos_Core.hpp>
42using host_ptr_view = Kokkos::View<T*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
50template <
unsigned Bits,
class ViewX,
class ViewY,
class ViewOut>
53 using exec =
typename ViewOut::execution_space;
54 const std::size_t
n =
out.extent(0);
56 "morton::kokkos::encode2", Kokkos::RangePolicy<exec>(0,
n),
61template <
unsigned Bits,
class ViewX,
class ViewY,
class ViewZ,
class ViewOut>
64 using exec =
typename ViewOut::execution_space;
65 const std::size_t
n =
out.extent(0);
67 "morton::kokkos::encode3", Kokkos::RangePolicy<exec>(0,
n),
72template <
unsigned Bits,
class ViewCode,
class ViewX,
class ViewY>
75 using exec =
typename ViewCode::execution_space;
76 const std::size_t
n = code.extent(0);
78 "morton::kokkos::decode2", Kokkos::RangePolicy<exec>(0,
n),
80 M m = M::from_code(code(
i));
87template <
unsigned Bits,
class ViewCode,
class ViewX,
class ViewY,
class ViewZ>
90 using exec =
typename ViewCode::execution_space;
91 const std::size_t
n = code.extent(0);
93 "morton::kokkos::decode3", Kokkos::RangePolicy<exec>(0,
n),
95 M m = M::from_code(code(
i));
104template <
unsigned Dim,
unsigned Bits,
class ViewIn,
class ViewOut>
107 using C =
typename M::coord_type;
108 using exec =
typename ViewOut::execution_space;
109 const std::size_t
n =
out.extent(0);
112 neg ?
C(
static_cast<unsigned long long>(-
delta)) :
C(
static_cast<unsigned long long>(
delta));
113 Kokkos::parallel_for(
114 "morton::kokkos::add", Kokkos::RangePolicy<exec>(0,
n),
KOKKOS_LAMBDA(
const std::size_t
i) {
115 M m = M::from_code(
in(
i));
125template <
unsigned Dim,
unsigned Bits,
class ViewIn,
class ViewOut>
132template <
unsigned Dim,
unsigned Bits,
class ViewIn,
class ViewOut>
141template <
unsigned Bits>
147 Kokkos::View<C*>
dx(
"morton.x",
n),
dy(
"morton.y",
n);
148 Kokkos::View<K*>
dout(
"morton.out",
n);
155template <
unsigned Bits>
162 Kokkos::View<C*>
dx(
"morton.x",
n),
dy(
"morton.y",
n),
dz(
"morton.z",
n);
163 Kokkos::View<K*>
dout(
"morton.out",
n);
171template <
unsigned Bits>
177 Kokkos::View<K*>
dcode(
"morton.code",
n);
178 Kokkos::View<C*>
dx(
"morton.x",
n),
dy(
"morton.y",
n);
185template <
unsigned Bits>
191 Kokkos::View<K*>
dcode(
"morton.code",
n);
192 Kokkos::View<C*>
dx(
"morton.x",
n),
dy(
"morton.y",
n),
dz(
"morton.z",
n);
200template <
unsigned Dim,
unsigned Bits>
205 Kokkos::View<K*>
din(
"morton.in",
n),
dout(
"morton.out",
n);
A Morton (Z-order) code interleaving Dim unsigned coordinates of Bits bits each.
Definition morton.hpp:203
detail::uint_for_t< Bits > coord_type
Definition morton.hpp:215
detail::uint_for_t< Dim *Bits > code_type
Definition morton.hpp:214
Core Morton<Dim,Bits> type — Z-order codes with O(1) arithmetic in Morton space.
Kokkos::View< T *, Kokkos::HostSpace, Kokkos::MemoryTraits< Kokkos::Unmanaged > > host_ptr_view
Definition kokkos.hpp:42
void decode3_host(const typename Morton< 3, Bits >::code_type *code, typename Morton< 3, Bits >::coord_type *x, typename Morton< 3, Bits >::coord_type *y, typename Morton< 3, Bits >::coord_type *z, std::size_t n)
Definition kokkos.hpp:186
void decode2(const ViewCode &code, const ViewX &x, const ViewY &y)
Decode a code View back to coordinate Views (2D).
Definition kokkos.hpp:73
void decode2_host(const typename Morton< 2, Bits >::code_type *code, typename Morton< 2, Bits >::coord_type *x, typename Morton< 2, Bits >::coord_type *y, std::size_t n)
Definition kokkos.hpp:172
void add(const ViewIn &in, const ViewOut &out, unsigned axis, long long delta)
Add a signed delta to axis of every code (wraps mod 2^Bits).
Definition kokkos.hpp:105
void step(const ViewIn &in, const ViewOut &out, unsigned axis, int dir)
Step every code one cell along ±axis (dir>=0 -> +1, else -1).
Definition kokkos.hpp:133
void sub(const ViewIn &in, const ViewOut &out, unsigned axis, typename Morton< Dim, Bits >::coord_type k)
Subtract k from axis of every code (wraps). Convenience over add.
Definition kokkos.hpp:126
void encode3_host(const typename Morton< 3, Bits >::coord_type *x, const typename Morton< 3, Bits >::coord_type *y, const typename Morton< 3, Bits >::coord_type *z, typename Morton< 3, Bits >::code_type *out, std::size_t n)
Definition kokkos.hpp:156
void decode3(const ViewCode &code, const ViewX &x, const ViewY &y, const ViewZ &z)
Decode a code View back to coordinate Views (3D).
Definition kokkos.hpp:88
void encode2_host(const typename Morton< 2, Bits >::coord_type *x, const typename Morton< 2, Bits >::coord_type *y, typename Morton< 2, Bits >::code_type *out, std::size_t n)
Definition kokkos.hpp:142
void encode2(const ViewX &x, const ViewY &y, const ViewOut &out)
Encode coordinate Views (2D) into a code View. x,y,out extents must match.
Definition kokkos.hpp:51
void add_host(const typename Morton< Dim, Bits >::code_type *in, typename Morton< Dim, Bits >::code_type *out, std::size_t n, unsigned axis, long long delta)
Definition kokkos.hpp:201
void encode3(const ViewX &x, const ViewY &y, const ViewZ &z, const ViewOut &out)
Encode coordinate Views (3D) into a code View.
Definition kokkos.hpp:62