morton-arithmetic 0.1.0
Fast Morton (Z-order) codes with O(1) arithmetic
Loading...
Searching...
No Matches
kokkos.hpp File Reference

Portable Kokkos backend for the morton-arithmetic library. More...

#include <cstddef>
#include <Kokkos_Core.hpp>
#include "morton/morton.hpp"
Include dependency graph for kokkos.hpp:

Go to the source code of this file.

Namespaces

namespace  morton
 
namespace  morton::kokkos
 
namespace  morton::kokkos::detail
 

Typedefs

template<class T >
using morton::kokkos::detail::host_ptr_view = Kokkos::View< T *, Kokkos::HostSpace, Kokkos::MemoryTraits< Kokkos::Unmanaged > >
 

Functions

template<unsigned Bits, class ViewX , class ViewY , class ViewOut >
void morton::kokkos::encode2 (const ViewX &x, const ViewY &y, const ViewOut &out)
 Encode coordinate Views (2D) into a code View. x,y,out extents must match.
 
template<unsigned Bits, class ViewX , class ViewY , class ViewZ , class ViewOut >
void morton::kokkos::encode3 (const ViewX &x, const ViewY &y, const ViewZ &z, const ViewOut &out)
 Encode coordinate Views (3D) into a code View.
 
template<unsigned Bits, class ViewCode , class ViewX , class ViewY >
void morton::kokkos::decode2 (const ViewCode &code, const ViewX &x, const ViewY &y)
 Decode a code View back to coordinate Views (2D).
 
template<unsigned Bits, class ViewCode , class ViewX , class ViewY , class ViewZ >
void morton::kokkos::decode3 (const ViewCode &code, const ViewX &x, const ViewY &y, const ViewZ &z)
 Decode a code View back to coordinate Views (3D).
 
template<unsigned Dim, unsigned Bits, class ViewIn , class ViewOut >
void morton::kokkos::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).
 
template<unsigned Dim, unsigned Bits, class ViewIn , class ViewOut >
void morton::kokkos::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.
 
template<unsigned Dim, unsigned Bits, class ViewIn , class ViewOut >
void morton::kokkos::step (const ViewIn &in, const ViewOut &out, unsigned axis, int dir)
 Step every code one cell along ±axis (dir>=0 -> +1, else -1).
 
template<unsigned Bits>
void morton::kokkos::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)
 
template<unsigned Bits>
void morton::kokkos::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)
 
template<unsigned Bits>
void morton::kokkos::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)
 
template<unsigned Bits>
void morton::kokkos::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)
 
template<unsigned Dim, unsigned Bits>
void morton::kokkos::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)
 

Detailed Description

Portable Kokkos backend for the morton-arithmetic library.

The per-element work is the ordinary Morton<Dim,Bits> code path (marked MORTON_HD, which resolves to KOKKOS_FUNCTION once Kokkos is in the translation unit), so the device kernels share the exact, already-tested logic of the CPU library – there is no second implementation to keep in sync. Unlike the retired raw-CUDA backend, this runs on any Kokkos backend (CUDA / HIP / OpenMP / Serial); the backend and architecture come from the Kokkos build the suite is pointed at, not from this header.

Two layers, mirroring the rest of the suite's Kokkos idiom:

  • View-based ops take caller-owned Kokkos::Views – these compose into larger pipelines and are exactly what the transport-core halo machinery moves between ranks. The execution space is deduced from the View.
  • *_host convenience wrappers take raw host pointers + n; they stage into device Views, run, and copy back. Handy for one-shot calls/tests.

Encode/decode on the device necessarily use the software (PDEP-free) bit path (deposit/extract guard the x86 intrinsics behind !__CUDA_ARCH__).

SPDX-License-Identifier: MIT