cuda.core.textures.CUDAArray#
- class cuda.core.textures.CUDAArray(*args, **kwargs)#
An opaque, hardware-laid-out GPU allocation for texture/surface access.
Distinct from
Buffer: aCUarrayhas no exposed device pointer and can only be accessed from kernels through aTextureObjectorSurfaceObject. Its memory layout is chosen by the driver for 2D/3D spatial locality.Copy-only interop. Because the layout is opaque and there is no linear device pointer, a
CUDAArraycannot expose__cuda_array_interface__/ DLPack and cannot be shared zero-copy with NumPy, CuPy, numba-cuda, or PyTorch. Moving data in or out is therefore always a copy: usecopy_from()/copy_to()against a linearBufferor a host buffer-protocol object. There is no allocation helper — allocate the linearBufferyourself (e.g.mr.allocate(arr.size_bytes, stream=s)) and copy.Construct via
from_descriptor(). Only plain 1D/2D/3D allocations are supported in this initial version; layered/cubemap/sparse variants will follow once their shape semantics are settled.Methods
- __init__(*args, **kwargs)#
- close(self)#
Release this object’s reference to the underlying
CUarray.Destruction (
cuArrayDestroy) happens via the handle’s deleter when the last reference is dropped; for a non-owning handle (graphics interop or a mipmap-level view) nothing is destroyed. Idempotent: a second call (or destruction afterclose()) is a no-op.
- copy_from(self, src, *, stream) None#
Copy a full-array’s worth of data into this array.
- Parameters:
src (Buffer or buffer-protocol object) – Source data. Must contain at least
self.size_bytesbytes of contiguous data.stream (Stream or GraphBuilder) – Stream to issue the copy on. A
GraphBuilderis accepted so the copy can be captured into a graph.
- copy_to(self, dst, *, stream)#
Copy a full-array’s worth of data out of this array.
- Parameters:
dst (Buffer or writable buffer-protocol object) – Destination. Must have at least
self.size_bytesbytes of writable, contiguous space.stream (Stream or GraphBuilder) – Stream to issue the copy on. A
GraphBuilderis accepted so the copy can be captured into a graph.
- Return type:
The
dstobject, for parity withBuffer.copy_to().
- classmethod from_descriptor(
- cls,
- *,
- shape,
- format,
- num_channels,
- is_surface_load_store=False,
Allocate a new CUDA array.
- Parameters:
shape (tuple of int) –
(width,),(width, height), or(width, height, depth)in elements.format (ArrayFormat) – Element format.
num_channels (int) – Channels per element. Must be 1, 2, or 4.
is_surface_load_store (bool) – If True, allocate with
CUDA_ARRAY3D_SURFACE_LDSTso the array can be bound as aSurfaceObjectfor kernel-side writes. Default False.
- Return type:
Attributes
- device#
The
Devicethis array was allocated on.
- element_size#
Bytes per element (format size * channels).
- format#
The element
ArrayFormat.
- handle#
The underlying
CUarrayas an integer.
- is_surface_load_store#
True if this array was created with
CUDA_ARRAY3D_SURFACE_LDSTand can be bound as aSurfaceObject.
- num_channels#
Channels per element (1, 2, or 4).
- shape#
Allocation shape, in elements.
- size_bytes#
Total bytes of array storage (
prod(shape) * element_size).