|
core
Shared MPI block decomposition + asynchronous ghost-layer exchange (header-only C++20)
|
Functions | |
| template<class MemorySpace > | |
| std::pair< int, int > | dlpack_device () |
| Map a Kokkos memory space to a DLPack {device_type, device_id} pair. | |
| template<class T > | |
| void | require_dtype (const nb::ndarray<> &a, const char *who) |
Throw if a's element type is not T. | |
| template<class V > | |
| auto | view_to_ndarray (const V &view) |
| Export a Kokkos View to a Python array without copying. | |
| template<class T > | |
| nb::ndarray< nb::numpy, T > | vector_to_ndarray (std::vector< T > &&v, std::initializer_list< std::size_t > shape, std::initializer_list< std::int64_t > strides) |
Export a host std::vector<T> as a NumPy array of the given logical shape and element-unit strides, without the extra copy the old to_xyz made: the vector is moved into a capsule that backs the array. | |
| template<class T > | |
| peclet::core::View< T > | ndarray_to_view (const nb::ndarray<> &a, const std::string &label) |
Import a (contiguous) Python array into a freshly-allocated flat device peclet::core::View<T>. | |
| template<class T > | |
| std::vector< T > | ndarray_to_vector (const nb::ndarray<> &a) |
Import a (contiguous) Python array into a host std::vector<T>. | |
Variables | |
| template<class MemorySpace > | |
| constexpr bool | is_host_space_v |
True when MemorySpace is reachable from the host (NumPy export path); false for a device-resident space (CUDA/HIP — DLPack/CuPy export path). | |
|
inline |
Map a Kokkos memory space to a DLPack {device_type, device_id} pair.
Host → cpu; otherwise the active GPU backend (CUDA, or ROCm under a HIP build), with the default device's id.
Definition at line 50 of file ndarray_interop.hpp.
Throw if a's element type is not T.
Definition at line 64 of file ndarray_interop.hpp.
Export a Kokkos View to a Python array without copying.
Works for any rank and either a host or device View. The returned array references view's memory and keeps it alive via a capsule owning a copy of the (ref-counted) View. Host views come back as numpy.ndarray; device views come back as a DLPack array (consume with cupy.from_dlpack). Shape and element-unit strides are taken from the View, so non-contiguous / padded views (e.g. a ghosted inner region) export correctly.
Definition at line 76 of file ndarray_interop.hpp.
| nb::ndarray< nb::numpy, T > peclet::core::python::vector_to_ndarray | ( | std::vector< T > && | v, |
| std::initializer_list< std::size_t > | shape, | ||
| std::initializer_list< std::int64_t > | strides | ||
| ) |
Export a host std::vector<T> as a NumPy array of the given logical shape and element-unit strides, without the extra copy the old to_xyz made: the vector is moved into a capsule that backs the array.
Use for solver getters that already return a host vector (e.g. a ghost-stripped x-fastest field → shape {nx,ny,nz}, strides {1,nx,nx*ny}).
Definition at line 108 of file ndarray_interop.hpp.
| peclet::core::View< T > peclet::core::python::ndarray_to_view | ( | const nb::ndarray<> & | a, |
| const std::string & | label | ||
| ) |
Import a (contiguous) Python array into a freshly-allocated flat device peclet::core::View<T>.
A host array is staged up (deep_copy from an unmanaged host wrap == the old peclet::core::toDevice); a device array on this build's backend is wrapped unmanaged and copied on-device (no host bounce — the CuPy zero-copy-onto-GPU path). An array on an incompatible device throws. The caller must pass a contiguous array (bindings enforce this via a typed nb::ndarray<T, nb::c_contig> / nb::f_contig parameter); the data is read as a flat buffer of a.size() elements.
Definition at line 125 of file ndarray_interop.hpp.
Import a (contiguous) Python array into a host std::vector<T>.
A host array is memcpy'd; a device array is copied down to the host (for solver APIs whose setters take host vectors). The caller enforces contiguity / element order via a typed binding parameter; the array is read as a flat buffer of a.size() elements.
Definition at line 152 of file ndarray_interop.hpp.
|
inlineconstexpr |
True when MemorySpace is reachable from the host (NumPy export path); false for a device-resident space (CUDA/HIP — DLPack/CuPy export path).
Definition at line 44 of file ndarray_interop.hpp.