linumpy.gpu.nvcomp_zstd#
GPU-accelerated zstd codec for zarr-python, backed by nvCOMP.
This is a vendored stand-in for upstream zarr-python PR #2863 (zarr.codecs.gpu.NvcompZstdCodec), which is approved but not yet released. The codec implementation matches that PR closely so we can swap to the upstream class once it lands without changing call sites.
Why this exists#
With zarr.config.enable_gpu(), zarr-python (≤3.2) reads zstd-compressed chunks by:
GDSStore(or any store) yields a CPU buffer.The default
zarr.codecs.zstd.ZstdCodecdecodes on the CPU (numcodecs).The decoded chunk is copied H→D into a
cupybuffer.
That CPU decode + H→D copy is the bottleneck for compressed tiles. This module replaces step 2:
chunks are uploaded to the GPU and decoded with nvidia.nvcomp.Codec("Zstd"), so the result
already lives on device.
Usage#
The codec is registered under the name "zstd" (same as the default), so any existing zarr
file with zstd-compressed chunks will use it once registered. Registration happens lazily from
linumpy.gpu.zarr_io whenever a GPU read path is taken, so CPU-only workflows are
unaffected.
References
Classes#
zstd codec that decodes/encodes on an NVIDIA GPU via nvCOMP. |
Functions#
Register |
|
Return the zarr config overrides that route the |
Module Contents#
- class linumpy.gpu.nvcomp_zstd.NvcompZstdCodec(*, level=0, checksum=False)[source]#
Bases:
zarr.abc.codec.BytesBytesCodeczstd codec that decodes/encodes on an NVIDIA GPU via nvCOMP.
- async decode(chunks_and_specs)[source]#
Decode a batch of zstd-compressed chunks on the GPU via nvCOMP.
- Parameters:
chunks_and_specs (collections.abc.Iterable[tuple[zarr.core.buffer.Buffer | None, zarr.core.array_spec.ArraySpec]])
- Return type:
- async encode(chunks_and_specs)[source]#
Encode a batch of chunks with zstd on the GPU via nvCOMP.
- Parameters:
chunks_and_specs (collections.abc.Iterable[tuple[zarr.core.buffer.Buffer | None, zarr.core.array_spec.ArraySpec]])
- Return type:
- linumpy.gpu.nvcomp_zstd.register_nvcomp_zstd()[source]#
Register
NvcompZstdCodecunder the namezstd.Idempotent. Returns True if registration succeeded (or was already done), False if the required GPU dependencies (
cupy,nvidia.nvcomp) are not importable.Note that registration alone is not enough to make zarr use the GPU codec — zarr 3.2 selects the concrete class via
zarr.config["codecs.zstd"]and the default points at the CPU codec. Usegpu_zstd_config()(or rely onlinumpy.gpu.zarr_io.gpu_zarr_context()) to flip the config for a scoped block.- Return type:
- linumpy.gpu.nvcomp_zstd.gpu_zstd_config()[source]#
Return the zarr config overrides that route the
zstdcodec through nvCOMP.Pass the result to
zarr.config.set(...)to enable GPU-side zstd decoding for the duration of thesetcontext. Caller is responsible for callingregister_nvcomp_zstd()first (otherwise zarr cannot resolve the class name).