core 1.8.1
Shared MPI block decomposition, asynchronous ghost-layer exchange, SDF geometry, load balancing (header-only C++20)
Loading...
Searching...
No Matches
ndarray_interop.hpp File Reference
#include <nanobind/nanobind.h>
#include <nanobind/ndarray.h>
#include <array>
#include <cstring>
#include <Kokkos_Core.hpp>
#include <stdexcept>
#include <type_traits>
#include <utility>
#include <vector>
#include "peclet/core/common/view.hpp"
#include "peclet/core/python/kokkos_teardown.hpp"

Go to the source code of this file.

Classes

struct  peclet::core::python::ViewCapsule< V >
 The payload of a zero-copy capsule: a reference to the exported View, registered as a Releasable so the module's shutdown can drop it before Kokkos::finalize. More...

Namespaces

namespace  peclet
namespace  peclet::core
namespace  peclet::core::python

Functions

template<class MemorySpace>
std::pair< int, int > peclet::core::python::dlpack_device ()
 Map a Kokkos memory space to a DLPack {device_type, device_id} pair.
template<class T>
void peclet::core::python::require_dtype (const nb::ndarray<> &a, const char *who)
 Throw if a's element type is not T.
template<class V, std::size_t N>
auto peclet::core::python::view_to_ndarray (const V &view, const std::array< std::size_t, N > &shape, const std::array< std::int64_t, N > &strides)
 Export a Kokkos View to a Python array without copying, with an explicit logical shape and element-unit strides over the View's memory (e.g.
template<class V>
auto peclet::core::python::view_to_ndarray (const V &view)
 Export a Kokkos View to a Python array without copying.
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.
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>.
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>.

Variables

template<class MemorySpace>
constexpr bool peclet::core::python::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).