Skip to content

tsim.utils.cuda_helpers.alloc_pinned_numpy

← Module overview

functionalloc_pinned_numpysource

tsim.utils.cuda_helpers.alloc_pinned_numpy

def alloc_pinned_numpy(nbytes: int, dtype, shape) -> np.ndarray

Allocate a pinned host region and return it as an ndarray view.

The returned array’s base chain pins the underlying _PinnedBuf alive until the array and all derived views are dropped; only then does cudaFreeHost run.

Parameters

NameTypeDescription
nbytesintSize of the underlying allocation in bytes. Must be at least ``prod(shape) * dtype.itemsize``.
dtype—numpy-compatible dtype for the returned view.
shape—Shape of the returned view.

Returns

np.ndarrayndarray of the requested shape and dtype, backed by pinned memory.

Raises

TypeDescription
RuntimeErrorif cuda.bindings is unavailable, or the underlying ``cudaHostAlloc`` fails.
source