cuda.bindings. When the import succeeds, host-pinned
allocations + a direct cudaMemcpy replace numpy’s default pageable d2h:
the pageable path forces the driver to stage the transfer through internal
pinned scratch before copying into the user buffer (host-DRAM-bandwidth
bound), while a pinned destination skips the staging hop and lets d2h reach
PCIe line rate. When the import fails, copy_d2h transparently falls
back to numpy.array.
alloc_pinned_numpy
base chain pins the underlying _PinnedBuf
alive until the array and all derived views are dropped; only then does
cudaFreeHost run.
Parameters:
nbytes(int) — Size of the underlying allocation in bytes. Must be at leastprod(shape) * dtype.itemsize.dtype— numpy-compatible dtype for the returned view.shape— Shape of the returned view.
np.ndarray— ndarray of the requested shape and dtype, backed by pinned memory.
RuntimeError— if cuda.bindings is unavailable, or the underlyingcudaHostAllocfails.
copy_d2h
src— Single-device contiguous array-like exposingunsafe_buffer_pointer(),nbytes,shape, anddtype. The caller must sync to the source’s stream before invocation (jax.block_until_ready(src)for a jax.Array).dst(np.ndarray | None) — Optional pre-allocated pinned ndarray to write into. Must have at leastsrc.nbytesbytes.
np.ndarray— ndarray with the same shape and dtype assrc.