-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It this PR we introduce `CudaCodec`, which is a base class for all CUDA Condecs/Compressors. This makes it possible to detect if an user tries to open a Zarr file using an incompatible compressor (see #297). Additionally, `kvikio.zarr.open_cupy_array()` now handles `mode="a"` Authors: - Mads R. B. Kristensen (https://github.com/madsbk) Approvers: - Lawrence Mitchell (https://github.com/wence-) URL: #298
- Loading branch information
Showing
5 changed files
with
140 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. | ||
# See file LICENSE for terms. | ||
|
||
""" | ||
This module implements CUDA compression and transformation codecs for Numcodecs. | ||
See <https://numcodecs.readthedocs.io/en/stable/> | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from abc import abstractmethod | ||
from typing import Any, Optional, Union | ||
|
||
import cupy.typing | ||
import numpy.typing | ||
from numcodecs.abc import Codec | ||
|
||
# TODO: replace `ANY` with `collections.abc.Buffer` from PEP-688 | ||
# when it becomes available. | ||
BufferLike = Union[cupy.typing.NDArray, numpy.typing.ArrayLike, Any] | ||
|
||
|
||
class CudaCodec(Codec): | ||
"""Abstract base class for CUDA codecs""" | ||
|
||
@abstractmethod | ||
def encode(self, buf: BufferLike) -> cupy.typing.NDArray: | ||
"""Encode `buf` using CUDA. | ||
This method should support both device and host buffers. | ||
Parameters | ||
---------- | ||
buf | ||
A numpy array like object such as numpy.ndarray, cupy.ndarray, | ||
or any object exporting a buffer interface. | ||
Returns | ||
------- | ||
The compressed buffer wrapped in a CuPy array | ||
""" | ||
|
||
@abstractmethod | ||
def decode(self, buf: BufferLike, out: Optional[BufferLike] = None) -> BufferLike: | ||
"""Decode `buf` using CUDA. | ||
This method should support both device and host buffers. | ||
Parameters | ||
---------- | ||
buf | ||
A numpy array like object such as numpy.ndarray, cupy.ndarray, | ||
or any object exporting a buffer interface. | ||
out | ||
A numpy array like object such as numpy.ndarray, cupy.ndarray, | ||
or any object exporting a buffer interface. If provided, this buffer must | ||
be exactly the right size to store the decoded data. | ||
Returns | ||
------- | ||
Decoded data, which is either host or device memory based on the type | ||
of `out`. If `out` is None, the type of `buf` determines the return buffer | ||
type. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters