core
Shared MPI block decomposition + asynchronous ghost-layer exchange (header-only C++20)
Loading...
Searching...
No Matches
peclet::core::python Namespace Reference

Functions

template<class MemorySpace >
std::pair< int, intdlpack_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, Tvector_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< Tndarray_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< Tndarray_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).
 

Function Documentation

◆ dlpack_device()

template<class MemorySpace >
std::pair< int, int > peclet::core::python::dlpack_device ( )
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.

◆ require_dtype()

template<class T >
void peclet::core::python::require_dtype ( const nb::ndarray<> &  a,
const char who 
)
inline

Throw if a's element type is not T.

Definition at line 64 of file ndarray_interop.hpp.

◆ view_to_ndarray()

template<class V >
auto peclet::core::python::view_to_ndarray ( const V view)

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.

◆ vector_to_ndarray()

template<class T >
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.

◆ ndarray_to_view()

template<class T >
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.

◆ ndarray_to_vector()

template<class T >
std::vector< T > peclet::core::python::ndarray_to_vector ( const nb::ndarray<> &  a)

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.

Variable Documentation

◆ is_host_space_v

template<class MemorySpace >
constexpr bool peclet::core::python::is_host_space_v
inlineconstexpr
Initial value:
=
Kokkos::SpaceAccessibility<Kokkos::HostSpace, MemorySpace>::accessible

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.