Gpu
zarr.buffer.gpu ¶
buffer_prototype
module-attribute
¶
buffer_prototype = BufferPrototype(
buffer=Buffer, nd_buffer=NDBuffer
)
Buffer ¶
Bases: Buffer
A flat contiguous memory block on the GPU
We use Buffer throughout Zarr to represent a contiguous block of memory.
A Buffer is backed by an 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).
Notes
This buffer is untyped, so all indexing and sizes are in bytes.
Parameters:
-
array_like(ArrayLike) –array-like object that must be 1-dim, contiguous, and byte dtype.
Source code in zarr/core/buffer/gpu.py
__add__ ¶
__eq__ ¶
__getitem__ ¶
__init__ ¶
__init__(array_like: ArrayLike) -> None
Source code in zarr/core/buffer/gpu.py
__setitem__ ¶
as_array_like ¶
as_array_like() -> ArrayLike
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.–
Source code in zarr/core/buffer/core.py
as_buffer_like ¶
Returns the buffer as an object that implements the Python buffer protocol.
Notes
Might have to copy data, since the implementation uses .as_numpy_array().
Returns:
-
An object that implements the Python buffer protocol–
Source code in zarr/core/buffer/core.py
as_numpy_array ¶
Returns the buffer as a NumPy array (host memory).
Notes
Might have to copy data, consider using .as_array_like() instead.
Returns:
-
NumPy array of this buffer (might be a data copy)–
combine ¶
Concatenate many buffers
Source code in zarr/core/buffer/gpu.py
create_zero_length
classmethod
¶
create_zero_length() -> Self
Create an empty buffer with length zero
Returns:
-
New empty 0-length buffer–
from_array_like
classmethod
¶
Create a new buffer of an array-like object
Parameters:
-
array_like(ArrayLike) –array-like object that must be 1-dim, contiguous, and byte dtype.
Returns:
-
New buffer representing `array_like`–
Source code in zarr/core/buffer/core.py
from_buffer
classmethod
¶
Create a 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`–
Source code in zarr/core/buffer/gpu.py
from_bytes
classmethod
¶
from_bytes(bytes_like: BytesLike) -> Self
Create a new buffer of a bytes-like object (host memory)
Parameters:
-
bytes_like(BytesLike) –bytes-like object
Returns:
-
New buffer representing `bytes_like`–
to_bytes ¶
to_bytes() -> bytes
Returns the buffer as bytes (host memory).
Warnings
Will always copy data, only use this method for small buffers such as metadata
buffers. If possible, use .as_numpy_array() or .as_array_like() instead.
Returns:
-
`bytes` of this buffer (data copy)–
Source code in zarr/core/buffer/core.py
NDBuffer ¶
Bases: NDBuffer
A n-dimensional memory block on the GPU
We use NDBuffer throughout Zarr to represent a n-dimensional memory block.
An NDBuffer is backed by an 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).
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.
Parameters:
-
array(NDArrayLike) –ndarray-like object that is convertible to a regular Numpy array.
Source code in zarr/core/buffer/gpu.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
__getitem__ ¶
__init__ ¶
__init__(array: NDArrayLike) -> None
Source code in zarr/core/buffer/gpu.py
__setitem__ ¶
Source code in zarr/core/buffer/gpu.py
all_equal ¶
Compare to other using np.array_equal.
Source code in zarr/core/buffer/core.py
as_ndarray_like ¶
as_ndarray_like() -> NDArrayLike
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.–
Source code in zarr/core/buffer/core.py
as_numpy_array ¶
Returns the buffer as a NumPy array (host memory).
Warnings
Might have to copy data, consider using .as_ndarray_like() instead.
Returns:
-
NumPy array of this buffer (might be a data copy)–
Source code in zarr/core/buffer/gpu.py
as_scalar ¶
Returns the buffer as a scalar value
astype ¶
create
classmethod
¶
create(
*,
shape: Iterable[int],
dtype: DTypeLike,
order: Literal["C", "F"] = "C",
fill_value: Any | None = None,
) -> Self
Create a new buffer and its underlying ndarray-like object
Parameters:
-
shape(Iterable[int]) –The shape of the buffer and its underlying ndarray-like object
-
dtype(DTypeLike) –The datatype of the buffer and its underlying ndarray-like object
-
order(Literal['C', 'F'], default:'C') –Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory.
-
fill_value(Any | None, default:None) –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 an ndarray-like object other then the default Numpy array.
Source code in zarr/core/buffer/gpu.py
empty
classmethod
¶
Create an empty buffer with the given shape, dtype, and order.
This method can be faster than NDBuffer.create because it doesn't
have to initialize the memory used by the underlying ndarray-like
object.
Parameters:
-
shape(tuple[int, ...]) –The shape of the buffer and its underlying ndarray-like object
-
dtype(DTypeLike) –The datatype of the buffer and its underlying ndarray-like object
-
order(Literal['C', 'F'], default:'C') –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.create Create a new buffer with some initial fill value.
from_ndarray_like
classmethod
¶
from_ndarray_like(ndarray_like: NDArrayLike) -> Self
Create a new buffer of an ndarray-like object
Parameters:
-
ndarray_like(NDArrayLike) –ndarray-like object
Returns:
-
New buffer representing `ndarray_like`–
Source code in zarr/core/buffer/core.py
from_numpy_array
classmethod
¶
Create a new buffer of Numpy array-like object
Parameters:
-
array_like(ArrayLike) –Object that can be coerced into a Numpy array
Returns:
-
New buffer representing `array_like`–
Source code in zarr/core/buffer/gpu.py
reshape ¶
squeeze ¶
transpose ¶
transpose(
axes: SupportsIndex | Sequence[SupportsIndex] | None,
) -> Self