zarr.buffer.gpu#
Attributes#
Classes#
Module Contents#
- class zarr.buffer.gpu.Buffer(array_like: zarr.core.buffer.core.ArrayLike)[source]#
Bases:
zarr.core.buffer.core.BufferA flat contiguous memory block on the GPU
We use Buffer throughout Zarr to represent a contiguous block of memory.
A Buffer is backed by a underlying array-like instance that represents the memory. The memory type is unspecified; can be regular host memory, CUDA device memory, or something else. The only requirement is that the array-like instance can be copied/converted to a regular Numpy array (host memory).
- Parameters:
- array_like
array-like object that must be 1-dim, contiguous, and byte dtype.
Notes
This buffer is untyped, so all indexing and sizes are in bytes.
- as_array_like() ArrayLike[source]#
Returns the underlying array (host or device memory) of this buffer
This will never copy data.
- Returns:
- The underlying 1d array such as a NumPy or CuPy array.
- as_buffer_like() zarr.core.common.BytesLike[source]#
Returns the buffer as an object that implements the Python buffer protocol.
- Returns:
- An object that implements the Python buffer protocol
Notes
Might have to copy data, since the implementation uses .as_numpy_array().
- as_numpy_array() numpy.typing.NDArray[Any][source]#
Returns the buffer as a NumPy array (host memory).
- Returns:
- NumPy array of this buffer (might be a data copy)
Notes
Might have to copy data, consider using .as_array_like() instead.
- classmethod create_zero_length() Self[source]#
Create an empty buffer with length zero
- Returns:
- New empty 0-length buffer
- classmethod from_array_like(array_like: ArrayLike) Self[source]#
Create a new buffer of an array-like object
- Parameters:
- array_like
array-like object that must be 1-dim, contiguous, and byte dtype.
- Returns:
- New buffer representing array_like
- classmethod from_buffer(buffer: zarr.core.buffer.core.Buffer) Self[source]#
Create an GPU Buffer given an arbitrary Buffer This will try to be zero-copy if buffer is already on the GPU and will trigger a copy if not.
- Returns:
- New GPU Buffer constructed from buffer
- class zarr.buffer.gpu.NDBuffer(array: zarr.core.buffer.core.NDArrayLike)[source]#
Bases:
zarr.core.buffer.core.NDBufferA n-dimensional memory block on the GPU
We use NDBuffer throughout Zarr to represent a n-dimensional memory block.
A NDBuffer is backed by a underlying ndarray-like instance that represents the memory. The memory type is unspecified; can be regular host memory, CUDA device memory, or something else. The only requirement is that the ndarray-like instance can be copied/converted to a regular Numpy array (host memory).
- Parameters:
- array
ndarray-like object that is convertible to a regular Numpy array.
Notes
The two buffer classes Buffer and NDBuffer are very similar. In fact, Buffer is a special case of NDBuffer where dim=1, stride=1, and dtype=”B”. However, in order to use Python’s type system to differentiate between the contiguous Buffer and the n-dim (non-contiguous) NDBuffer, we keep the definition of the two classes separate.
- as_ndarray_like() NDArrayLike[source]#
Returns the underlying array (host or device memory) of this buffer
This will never copy data.
- Returns:
- The underlying array such as a NumPy or CuPy array.
- as_numpy_array() numpy.typing.NDArray[Any][source]#
Returns the buffer as a NumPy array (host memory).
- Returns:
- NumPy array of this buffer (might be a data copy)
Warning
Might have to copy data, consider using .as_ndarray_like() instead.
- classmethod create(
- *,
- shape: collections.abc.Iterable[int],
- dtype: numpy.typing.DTypeLike,
- order: Literal['C', 'F'] = 'C',
- fill_value: Any | None = None,
Create a new buffer and its underlying ndarray-like object
- Parameters:
- shape
The shape of the buffer and its underlying ndarray-like object
- dtype
The datatype of the buffer and its underlying ndarray-like object
- order
Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory.
- fill_value
If not None, fill the new buffer with a scalar value.
- Returns:
- New buffer representing a new ndarray_like object
Notes
A subclass can overwrite this method to create a ndarray-like object other then the default Numpy array.
- classmethod empty(
- shape: tuple[int, Ellipsis],
- dtype: numpy.typing.DTypeLike,
- order: Literal['C', 'F'] = 'C',
Create an empty buffer with the given shape, dtype, and order.
This method can be faster than
NDBuffer.createbecause it doesn’t have to initialize the memory used by the underlying ndarray-like object.- Parameters:
- shape
The shape of the buffer and its underlying ndarray-like object
- dtype
The datatype of the buffer and its underlying ndarray-like object
- order
Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory.
- Returns:
- buffer
New buffer representing a new ndarray_like object with empty data.
See also
NDBuffer.createCreate a new buffer with some initial fill value.
- classmethod from_ndarray_like(ndarray_like: NDArrayLike) Self[source]#
Create a new buffer of a ndarray-like object
- Parameters:
- ndarray_like
ndarray-like object
- Returns:
- New buffer representing ndarray_like
- classmethod from_numpy_array(array_like: numpy.typing.ArrayLike) Self[source]#
Create a new buffer of Numpy array-like object
- Parameters:
- array_like
Object that can be coerced into a Numpy array
- Returns:
- New buffer representing array_like
- property byteorder: zarr.codecs.bytes.Endian#
- property dtype: numpy.dtype[Any]#
- property shape: tuple[int, Ellipsis]#
- zarr.buffer.gpu.buffer_prototype#