zarr-kvikio 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zarr_kvikio-0.1.0/.gitignore +25 -0
- zarr_kvikio-0.1.0/LICENSE +21 -0
- zarr_kvikio-0.1.0/PKG-INFO +79 -0
- zarr_kvikio-0.1.0/README.md +40 -0
- zarr_kvikio-0.1.0/pyproject.toml +194 -0
- zarr_kvikio-0.1.0/src/_zarr_kvikio_entry.py +45 -0
- zarr_kvikio-0.1.0/src/zarr_kvikio/__init__.py +35 -0
- zarr_kvikio-0.1.0/src/zarr_kvikio/_check.py +193 -0
- zarr_kvikio-0.1.0/src/zarr_kvikio/_config.py +82 -0
- zarr_kvikio-0.1.0/src/zarr_kvikio/_convert.py +231 -0
- zarr_kvikio-0.1.0/src/zarr_kvikio/_pipeline.py +1643 -0
- zarr_kvikio-0.1.0/src/zarr_kvikio/dask.py +138 -0
- zarr_kvikio-0.1.0/src/zarr_kvikio/py.typed +0 -0
- zarr_kvikio-0.1.0/tests/conftest.py +17 -0
- zarr_kvikio-0.1.0/tests/test_convert_check.py +288 -0
- zarr_kvikio-0.1.0/tests/test_dask_config.py +183 -0
- zarr_kvikio-0.1.0/tests/test_pipeline.py +603 -0
- zarr_kvikio-0.1.0/tests/test_robustness.py +711 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Temp files
|
|
2
|
+
.DS_Store
|
|
3
|
+
*~
|
|
4
|
+
buck-out/
|
|
5
|
+
|
|
6
|
+
# Compiled files
|
|
7
|
+
.venv/
|
|
8
|
+
uv.lock
|
|
9
|
+
__pycache__/
|
|
10
|
+
.*cache/
|
|
11
|
+
|
|
12
|
+
# Distribution / packaging
|
|
13
|
+
/dist/
|
|
14
|
+
|
|
15
|
+
# Tests and coverage
|
|
16
|
+
/data/
|
|
17
|
+
/node_modules/
|
|
18
|
+
/.coverage*
|
|
19
|
+
|
|
20
|
+
# docs
|
|
21
|
+
/docs/generated/
|
|
22
|
+
/docs/_build/
|
|
23
|
+
|
|
24
|
+
# KvikIO / cuFile logs
|
|
25
|
+
cufile.log
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, scverse®
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: zarr-kvikio
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A zarr-python codec pipeline that reads chunks straight into GPU memory with KvikIO and decodes them with nvCOMP
|
|
5
|
+
Project-URL: Changelog, https://zarr-kvikio.readthedocs.io/page/release-notes/index.html
|
|
6
|
+
Project-URL: Documentation, https://zarr-kvikio.readthedocs.io/
|
|
7
|
+
Project-URL: Homepage, https://github.com/scverse/zarr-kvikio
|
|
8
|
+
Project-URL: Issues, https://github.com/scverse/zarr-kvikio/issues
|
|
9
|
+
Project-URL: Source, https://github.com/scverse/zarr-kvikio
|
|
10
|
+
Author: Severin Dicks
|
|
11
|
+
Maintainer-email: Severin Dicks <severin.dicks@scverse.org>
|
|
12
|
+
License-Expression: MIT
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Environment :: GPU :: NVIDIA CUDA
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.12
|
|
24
|
+
Requires-Dist: google-crc32c>=1.5
|
|
25
|
+
Requires-Dist: numcodecs>=0.14
|
|
26
|
+
Requires-Dist: numpy>=1.26
|
|
27
|
+
Requires-Dist: zarr>=3.3
|
|
28
|
+
Provides-Extra: cuda12
|
|
29
|
+
Requires-Dist: cupy-cuda12x[ctk]>=14.0.1; extra == 'cuda12'
|
|
30
|
+
Requires-Dist: kvikio-cu12>=26.4; extra == 'cuda12'
|
|
31
|
+
Requires-Dist: nvidia-nvcomp-cu12>=5.2; extra == 'cuda12'
|
|
32
|
+
Provides-Extra: cuda13
|
|
33
|
+
Requires-Dist: cupy-cuda13x[ctk]>=14.0.1; extra == 'cuda13'
|
|
34
|
+
Requires-Dist: kvikio-cu13>=26.4; extra == 'cuda13'
|
|
35
|
+
Requires-Dist: nvidia-nvcomp-cu13>=5.2; extra == 'cuda13'
|
|
36
|
+
Provides-Extra: dask
|
|
37
|
+
Requires-Dist: distributed>=2023.9.2; extra == 'dask'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# zarr-kvikio
|
|
41
|
+
|
|
42
|
+
[![Tests][badge-tests]][tests]
|
|
43
|
+
[![Documentation][badge-docs]][documentation]
|
|
44
|
+
|
|
45
|
+
[badge-tests]: https://img.shields.io/github/actions/workflow/status/scverse/zarr-kvikio/test.yaml?branch=main
|
|
46
|
+
[badge-docs]: https://app.readthedocs.org/projects/zarr-kvikio/badge/
|
|
47
|
+
[tests]: https://github.com/scverse/zarr-kvikio/actions/workflows/test.yaml
|
|
48
|
+
[documentation]: https://zarr-kvikio.readthedocs.io/
|
|
49
|
+
|
|
50
|
+
zarr-kvikio is a [Zarr-Python](https://zarr.readthedocs.io/) codec pipeline for reading local and remote arrays into CuPy arrays.
|
|
51
|
+
It accelerates reads of local Zarr v3 arrays with uncompressed or Zstandard-compressed numeric chunks using
|
|
52
|
+
[KvikIO](https://github.com/rapidsai/kvikio) and [nvCOMP](https://developer.nvidia.com/nvcomp).
|
|
53
|
+
Remote stores use Zarr’s standard GPU-buffer reads.
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
Choose the extra that matches your CUDA installation, either `cuda12` or `cuda13`.
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install 'zarr-kvikio[cuda13]'
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
For Dask support, add the `dask` extra (e.g. `zarr-kvikio[cuda13,dask]`). To inspect or convert stores
|
|
64
|
+
on the CPU, install the base package with `pip install zarr-kvikio`.
|
|
65
|
+
|
|
66
|
+
## Quick start
|
|
67
|
+
|
|
68
|
+
Enable the pipeline before opening a local array. For example, read the first 1,024 rows of `data.zarr` into GPU memory.
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
import zarr
|
|
72
|
+
import zarr_kvikio
|
|
73
|
+
|
|
74
|
+
with zarr_kvikio.enable():
|
|
75
|
+
array = zarr.open_array("data.zarr", mode="r")
|
|
76
|
+
rows = array[:1024] # cupy.ndarray
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
See the [documentation][documentation] for Dask setup, supported store layouts, configuration, and the API reference.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# zarr-kvikio
|
|
2
|
+
|
|
3
|
+
[![Tests][badge-tests]][tests]
|
|
4
|
+
[![Documentation][badge-docs]][documentation]
|
|
5
|
+
|
|
6
|
+
[badge-tests]: https://img.shields.io/github/actions/workflow/status/scverse/zarr-kvikio/test.yaml?branch=main
|
|
7
|
+
[badge-docs]: https://app.readthedocs.org/projects/zarr-kvikio/badge/
|
|
8
|
+
[tests]: https://github.com/scverse/zarr-kvikio/actions/workflows/test.yaml
|
|
9
|
+
[documentation]: https://zarr-kvikio.readthedocs.io/
|
|
10
|
+
|
|
11
|
+
zarr-kvikio is a [Zarr-Python](https://zarr.readthedocs.io/) codec pipeline for reading local and remote arrays into CuPy arrays.
|
|
12
|
+
It accelerates reads of local Zarr v3 arrays with uncompressed or Zstandard-compressed numeric chunks using
|
|
13
|
+
[KvikIO](https://github.com/rapidsai/kvikio) and [nvCOMP](https://developer.nvidia.com/nvcomp).
|
|
14
|
+
Remote stores use Zarr’s standard GPU-buffer reads.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
Choose the extra that matches your CUDA installation, either `cuda12` or `cuda13`.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install 'zarr-kvikio[cuda13]'
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
For Dask support, add the `dask` extra (e.g. `zarr-kvikio[cuda13,dask]`). To inspect or convert stores
|
|
25
|
+
on the CPU, install the base package with `pip install zarr-kvikio`.
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
Enable the pipeline before opening a local array. For example, read the first 1,024 rows of `data.zarr` into GPU memory.
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import zarr
|
|
33
|
+
import zarr_kvikio
|
|
34
|
+
|
|
35
|
+
with zarr_kvikio.enable():
|
|
36
|
+
array = zarr.open_array("data.zarr", mode="r")
|
|
37
|
+
rows = array[:1024] # cupy.ndarray
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
See the [documentation][documentation] for Dask setup, supported store layouts, configuration, and the API reference.
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
build-backend = "hatchling.build"
|
|
3
|
+
requires = [ "hatch-vcs", "hatchling" ]
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "zarr-kvikio"
|
|
7
|
+
description = """\
|
|
8
|
+
A zarr-python codec pipeline that reads chunks straight into GPU memory with KvikIO and decodes them with nvCOMP\
|
|
9
|
+
"""
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = [ "LICENSE" ]
|
|
13
|
+
maintainers = [ { name = "Severin Dicks", email = "severin.dicks@scverse.org" } ]
|
|
14
|
+
authors = [ { name = "Severin Dicks" } ]
|
|
15
|
+
requires-python = ">=3.12"
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Environment :: GPU :: NVIDIA CUDA",
|
|
19
|
+
"Intended Audience :: Science/Research",
|
|
20
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: 3.14",
|
|
24
|
+
"Topic :: Scientific/Engineering",
|
|
25
|
+
"Typing :: Typed",
|
|
26
|
+
]
|
|
27
|
+
dynamic = [ "version" ]
|
|
28
|
+
dependencies = [
|
|
29
|
+
"google-crc32c>=1.5",
|
|
30
|
+
# decodes small reads on the CPU (zarr 3.3 needs >= 0.14 too)
|
|
31
|
+
"numcodecs>=0.14",
|
|
32
|
+
"numpy>=1.26",
|
|
33
|
+
# the pipeline subclasses zarr's BatchedCodecPipeline and uses some of its internals
|
|
34
|
+
"zarr>=3.3",
|
|
35
|
+
]
|
|
36
|
+
# the GPU stack: KvikIO reads, nvCOMP decodes (>= 5.2 for batched decoding into preallocated buffers)
|
|
37
|
+
# (CuPy's `ctk` extra brings the CUDA runtime libraries it compiles kernels with, as KvikIO >= 26.8 does)
|
|
38
|
+
optional-dependencies.cuda12 = [ "cupy-cuda12x[ctk]>=14.0.1", "kvikio-cu12>=26.4", "nvidia-nvcomp-cu12>=5.2" ]
|
|
39
|
+
optional-dependencies.cuda13 = [ "cupy-cuda13x[ctk]>=14.0.1", "kvikio-cu13>=26.4", "nvidia-nvcomp-cu13>=5.2" ]
|
|
40
|
+
# Client.register_plugin(..., name=...) is new in 2023.9.2
|
|
41
|
+
optional-dependencies.dask = [ "distributed>=2023.9.2" ]
|
|
42
|
+
urls.Changelog = "https://zarr-kvikio.readthedocs.io/page/release-notes/index.html"
|
|
43
|
+
urls.Documentation = "https://zarr-kvikio.readthedocs.io/"
|
|
44
|
+
urls.Homepage = "https://github.com/scverse/zarr-kvikio"
|
|
45
|
+
urls.Issues = "https://github.com/scverse/zarr-kvikio/issues"
|
|
46
|
+
urls.Source = "https://github.com/scverse/zarr-kvikio"
|
|
47
|
+
# lets zarr find the pipeline by name in every process, without importing zarr_kvikio first;
|
|
48
|
+
# the guard module keeps zarr working if zarr_kvikio fails to import (e.g. with an untested zarr)
|
|
49
|
+
entry-points."zarr.codec_pipeline"."zarr_kvikio.KvikioCodecPipeline" = "_zarr_kvikio_entry:KvikioCodecPipeline"
|
|
50
|
+
|
|
51
|
+
[dependency-groups]
|
|
52
|
+
dev = [ "twine>=4.0.2" ]
|
|
53
|
+
test = [ "coverage>=7.10", "distributed", "pytest", "pytest-cov", "zarrs" ] # (zarrs as the host pipeline)
|
|
54
|
+
doc = [
|
|
55
|
+
"ipykernel",
|
|
56
|
+
"ipython",
|
|
57
|
+
"scverse-doc[full]>=0.5",
|
|
58
|
+
"sphinx-autodoc-typehints",
|
|
59
|
+
"sphinxcontrib-bibtex>=1",
|
|
60
|
+
]
|
|
61
|
+
typecheck = [ "mypy" ]
|
|
62
|
+
|
|
63
|
+
[tool.hatch]
|
|
64
|
+
version.source = "vcs"
|
|
65
|
+
version.raw-options.local_scheme = "no-local-version"
|
|
66
|
+
version.raw-options.version_scheme = "guess-next-dev"
|
|
67
|
+
build.targets.sdist.include = [ "/src", "/tests", "/LICENSE", "/README.md" ]
|
|
68
|
+
build.targets.wheel.only-include = [ "src/_zarr_kvikio_entry.py", "src/zarr_kvikio" ]
|
|
69
|
+
build.targets.wheel.sources = [ "src" ]
|
|
70
|
+
envs.default.installer = "uv"
|
|
71
|
+
envs.default.dependency-groups = [ "dev" ]
|
|
72
|
+
envs.docs.features = [ "dask" ] # documents zarr_kvikio.dask
|
|
73
|
+
envs.docs.scripts.build = "sphinx-build -M html docs docs/_build -W {args}"
|
|
74
|
+
envs.docs.scripts.clean = "git clean -fdX -- {args:docs}"
|
|
75
|
+
envs.docs.scripts.open = "python -m webbrowser -t docs/_build/html/index.html"
|
|
76
|
+
envs.docs.dependency-groups = [ "doc" ]
|
|
77
|
+
envs.hatch-check-code.dependencies = [ "prek" ]
|
|
78
|
+
envs.hatch-check-code.scripts.lint-check = "echo 'try `hatch check code --fix`'; false"
|
|
79
|
+
envs.hatch-check-code.scripts.lint-fix = "prek run -a --no-group=format --no-group=typecheck"
|
|
80
|
+
envs.hatch-check-fmt.dependencies = [ "prek" ]
|
|
81
|
+
envs.hatch-check-fmt.scripts.format-check = "echo 'try `hatch check fmt --fix`'; false"
|
|
82
|
+
envs.hatch-check-fmt.scripts.format-fix = "prek run -a --group=format --no-group=typecheck"
|
|
83
|
+
envs.hatch-check-types.scripts.check = [ "mypy" ]
|
|
84
|
+
envs.hatch-check-types.dependency-groups = [ "typecheck", "test" ]
|
|
85
|
+
envs.hatch-test.matrix = [
|
|
86
|
+
# Test the lowest and highest supported Python versions with normal deps
|
|
87
|
+
{ deps = [ "stable" ], python = [ "3.12", "3.14" ] },
|
|
88
|
+
# Test the newest supported Python version also with pre-release deps
|
|
89
|
+
{ deps = [ "pre" ], python = [ "3.14" ] },
|
|
90
|
+
]
|
|
91
|
+
# If the matrix variable `deps` is set to "pre",
|
|
92
|
+
# set the environment variable `UV_PRERELEASE` to "allow".
|
|
93
|
+
envs.hatch-test.overrides.matrix.deps.env-vars = [
|
|
94
|
+
{ value = "allow", key = "UV_PRERELEASE", if = [ "pre" ] },
|
|
95
|
+
]
|
|
96
|
+
envs.hatch-test.dependency-groups = [ "dev", "test" ]
|
|
97
|
+
|
|
98
|
+
# kvikio-cu12 and -cu13 need different cuda-toolkit majors: resolved together, uv would hold
|
|
99
|
+
# kvikio back to a release without that requirement
|
|
100
|
+
[tool.uv]
|
|
101
|
+
conflicts = [ [ { extra = "cuda12" }, { extra = "cuda13" } ] ]
|
|
102
|
+
|
|
103
|
+
[tool.ruff]
|
|
104
|
+
line-length = 100
|
|
105
|
+
src = [ "src" ]
|
|
106
|
+
extend-include = [ "*.ipynb" ]
|
|
107
|
+
format.docstring-code-format = true
|
|
108
|
+
lint.select = [
|
|
109
|
+
"B", # flake8-bugbear
|
|
110
|
+
"BLE", # flake8-blind-except
|
|
111
|
+
"C4", # flake8-comprehensions
|
|
112
|
+
"D", # pydocstyle
|
|
113
|
+
"E", # pycodestyle errors
|
|
114
|
+
"F", # pyflakes
|
|
115
|
+
"I", # isort
|
|
116
|
+
"PTH", # pathlib instead of os.path
|
|
117
|
+
"RUF", # ruff-specific rules
|
|
118
|
+
"SIM", # flake8-simplify
|
|
119
|
+
"TC", # type-checking blocks
|
|
120
|
+
"TID", # flake8-tidy-imports
|
|
121
|
+
"UP", # pyupgrade
|
|
122
|
+
"W", # pycodestyle warnings
|
|
123
|
+
]
|
|
124
|
+
lint.ignore = [
|
|
125
|
+
"D100", # missing docstring in public module
|
|
126
|
+
"D104", # missing docstring in public package
|
|
127
|
+
"D105", # missing docstring in magic method
|
|
128
|
+
"D107", # missing docstring in __init__
|
|
129
|
+
"D203", # (conflicts with D211) no blank line before a class docstring
|
|
130
|
+
"D213", # (conflicts with D212) docstrings start right after the opening quotes
|
|
131
|
+
"D401", # first line in imperative mood
|
|
132
|
+
]
|
|
133
|
+
lint.per-file-ignores."benchmarks/*" = [ "D" ]
|
|
134
|
+
lint.per-file-ignores."docs/*" = [ "I" ]
|
|
135
|
+
lint.per-file-ignores."tests/*" = [ "D" ]
|
|
136
|
+
lint.isort.known-first-party = [ "zarr_kvikio" ]
|
|
137
|
+
lint.isort.required-imports = [ "from __future__ import annotations" ]
|
|
138
|
+
lint.pydocstyle.convention = "numpy"
|
|
139
|
+
|
|
140
|
+
[tool.pyproject-fmt]
|
|
141
|
+
max_supported_python = "3.14"
|
|
142
|
+
|
|
143
|
+
[tool.mypy]
|
|
144
|
+
files = [ "src" ]
|
|
145
|
+
python_version = "3.12"
|
|
146
|
+
warn_redundant_casts = true
|
|
147
|
+
warn_unused_ignores = true
|
|
148
|
+
enable_error_code = [ "ignore-without-code" ]
|
|
149
|
+
warn_unused_configs = true
|
|
150
|
+
|
|
151
|
+
# dependencies that ship without type information
|
|
152
|
+
[[tool.mypy.overrides]]
|
|
153
|
+
module = [
|
|
154
|
+
"cupy",
|
|
155
|
+
"distributed",
|
|
156
|
+
"distributed.*",
|
|
157
|
+
"donfig.*",
|
|
158
|
+
"kvikio",
|
|
159
|
+
"kvikio.*",
|
|
160
|
+
"numcodecs",
|
|
161
|
+
"numcodecs.*",
|
|
162
|
+
"nvidia.*",
|
|
163
|
+
"tqdm.*",
|
|
164
|
+
"zarrs",
|
|
165
|
+
]
|
|
166
|
+
ignore_missing_imports = true
|
|
167
|
+
|
|
168
|
+
[tool.pytest]
|
|
169
|
+
addopts = [
|
|
170
|
+
"--import-mode=importlib", # allow using test files with same name
|
|
171
|
+
"-ra", # list the skipped GPU tests
|
|
172
|
+
]
|
|
173
|
+
strict = true
|
|
174
|
+
testpaths = [ "tests" ]
|
|
175
|
+
|
|
176
|
+
[tool.coverage]
|
|
177
|
+
run.source = [ "zarr_kvikio" ]
|
|
178
|
+
run.omit = [
|
|
179
|
+
"**/test_*.py",
|
|
180
|
+
]
|
|
181
|
+
run.patch = [ "subprocess" ]
|
|
182
|
+
|
|
183
|
+
[tool.cruft]
|
|
184
|
+
skip = [
|
|
185
|
+
".git",
|
|
186
|
+
"tests",
|
|
187
|
+
"src/**/__init__.py",
|
|
188
|
+
"src/**/basic.py",
|
|
189
|
+
"docs/api.md",
|
|
190
|
+
"docs/changelog.md",
|
|
191
|
+
"docs/references.bib",
|
|
192
|
+
"docs/references.md",
|
|
193
|
+
"docs/notebooks/example.ipynb",
|
|
194
|
+
]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""The ``zarr.codec_pipeline`` entry point of zarr-kvikio.
|
|
2
|
+
|
|
3
|
+
zarr loads every pipeline entry point whenever it creates a codec pipeline, and one that fails to
|
|
4
|
+
load makes every array open fail. zarr_kvikio uses zarr internals, so a zarr release that moves
|
|
5
|
+
them would break all zarr reads wherever zarr-kvikio is installed. If zarr_kvikio cannot be
|
|
6
|
+
imported, this registers a stand-in that raises the import error only when it is selected.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from typing import NoReturn
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _load() -> type:
|
|
15
|
+
try:
|
|
16
|
+
from zarr_kvikio import KvikioCodecPipeline
|
|
17
|
+
except Exception as err: # noqa: BLE001
|
|
18
|
+
# not only ImportError: zarr_kvikio subclasses zarr internals at import, so moved ones
|
|
19
|
+
# also raise e.g. AttributeError, and this guard must never break zarr
|
|
20
|
+
return _stub(err)
|
|
21
|
+
return KvikioCodecPipeline
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _stub(err: Exception) -> type:
|
|
25
|
+
class KvikioCodecPipeline:
|
|
26
|
+
"""Stands in for :class:`zarr_kvikio.KvikioCodecPipeline` if it can't be imported."""
|
|
27
|
+
|
|
28
|
+
# registered under the same name as the real pipeline
|
|
29
|
+
__module__ = "zarr_kvikio"
|
|
30
|
+
__qualname__ = "KvikioCodecPipeline"
|
|
31
|
+
|
|
32
|
+
@classmethod
|
|
33
|
+
def from_codecs(cls, *args: object, **kwargs: object) -> NoReturn:
|
|
34
|
+
msg = (
|
|
35
|
+
"zarr's codec pipeline is zarr_kvikio.KvikioCodecPipeline, "
|
|
36
|
+
f"but zarr_kvikio failed to import: {err}"
|
|
37
|
+
)
|
|
38
|
+
raise ImportError(msg) from err
|
|
39
|
+
|
|
40
|
+
from_array_metadata_and_store = from_codecs
|
|
41
|
+
|
|
42
|
+
return KvikioCodecPipeline
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
KvikioCodecPipeline = _load()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Read zarr chunks straight into GPU memory with KvikIO and decode them with nvCOMP."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
6
|
+
|
|
7
|
+
from zarr.registry import register_pipeline
|
|
8
|
+
|
|
9
|
+
from ._check import check, describe
|
|
10
|
+
from ._config import available, enable, require
|
|
11
|
+
from ._convert import convert_array, cpu_pipeline, layout
|
|
12
|
+
from ._pipeline import KvikioCodecPipeline, release_memory
|
|
13
|
+
|
|
14
|
+
try:
|
|
15
|
+
__version__ = version("zarr-kvikio")
|
|
16
|
+
except PackageNotFoundError: # imported from a source tree that isn't installed
|
|
17
|
+
__version__ = "0+unknown"
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"KvikioCodecPipeline",
|
|
21
|
+
"__version__",
|
|
22
|
+
"available",
|
|
23
|
+
"check",
|
|
24
|
+
"convert_array",
|
|
25
|
+
"cpu_pipeline",
|
|
26
|
+
"describe",
|
|
27
|
+
"enable",
|
|
28
|
+
"layout",
|
|
29
|
+
"release_memory",
|
|
30
|
+
"require",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
# selected via `codec_pipeline.path` as "zarr_kvikio.KvikioCodecPipeline" (also found through the
|
|
34
|
+
# `zarr.codec_pipeline` entry point, without importing this package first)
|
|
35
|
+
register_pipeline(KvikioCodecPipeline)
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import shutil
|
|
5
|
+
import subprocess
|
|
6
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import TYPE_CHECKING, Any
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
|
|
12
|
+
from ._config import available
|
|
13
|
+
from ._pipeline import (
|
|
14
|
+
_MAX_UINT_64,
|
|
15
|
+
_NVCOMP_MAX_FRAME,
|
|
16
|
+
KvikioCodecPipeline,
|
|
17
|
+
_gpu_dtype,
|
|
18
|
+
_layout_of,
|
|
19
|
+
_read_shard_index,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
import zarr
|
|
24
|
+
|
|
25
|
+
# nvCOMP decodes every zstd frame (= chunk) with one thread block, so large chunks decode slowly.
|
|
26
|
+
_MAX_GOOD_CHUNK_BYTES = 1 << 20
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def check() -> dict[str, Any]:
|
|
30
|
+
"""Whether arrays can be read into GPU memory here: KvikIO, nvCOMP and GPUDirect Storage.
|
|
31
|
+
|
|
32
|
+
Returns ``{"available": ..., "versions": {...}, "gds": {...}}``. GPUDirect Storage is read
|
|
33
|
+
from ``gdscheck -p`` and KvikIO's compatibility mode (as ``gds["kvikio_compat_mode"]``, only
|
|
34
|
+
if :func:`available`; on with ``KVIKIO_COMPAT_MODE=ON`` or without a usable cuFile). Without
|
|
35
|
+
GPUDirect Storage, KvikIO reads through the page cache and a bounce buffer, which still works
|
|
36
|
+
(and is fast for cached data), but isn't direct NVMe to GPU DMA. Contiguous reads of
|
|
37
|
+
zstd-compressed sharded 1-D arrays only use KvikIO with ``kvikio.fetch`` set to ``"kvikio"``.
|
|
38
|
+
"""
|
|
39
|
+
gds = _gds_status()
|
|
40
|
+
if available():
|
|
41
|
+
import kvikio.defaults
|
|
42
|
+
|
|
43
|
+
# e.g. KVIKIO_COMPAT_MODE=ON, or no usable cuFile: KvikIO doesn't use GDS, whatever
|
|
44
|
+
# gdscheck says
|
|
45
|
+
gds["kvikio_compat_mode"] = bool(kvikio.defaults.is_compat_mode_preferred())
|
|
46
|
+
if gds["kvikio_compat_mode"]:
|
|
47
|
+
gds["status"] = "compatibility mode"
|
|
48
|
+
return {
|
|
49
|
+
"available": available(),
|
|
50
|
+
"versions": {pkg: _version(pkg) for pkg in ("kvikio", "nvidia-nvcomp", "zarr", "cupy")},
|
|
51
|
+
"gds": gds,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def describe(arr: zarr.Array) -> dict[str, Any]:
|
|
56
|
+
"""Describe the layout of `arr` and list what keeps it from being read fast on the GPU.
|
|
57
|
+
|
|
58
|
+
Returns its dtype, zarr format, codecs, chunk size and whether it is sharded, plus
|
|
59
|
+
``gpu_readable`` (whether the GPU can decode its chunks) and ``problems``
|
|
60
|
+
(see :func:`convert_array` for a layout without them).
|
|
61
|
+
"""
|
|
62
|
+
from zarr.storage import LocalStore
|
|
63
|
+
|
|
64
|
+
desc: dict[str, Any] = {
|
|
65
|
+
"dtype": str(arr.dtype),
|
|
66
|
+
"zarr_format": arr.metadata.zarr_format,
|
|
67
|
+
"codecs": [type(c).__name__ for c in _codecs(arr)],
|
|
68
|
+
"chunk_bytes": int(np.prod(arr.chunks)) * arr.dtype.itemsize,
|
|
69
|
+
"sharded": arr.shards is not None,
|
|
70
|
+
}
|
|
71
|
+
problems = []
|
|
72
|
+
layout = None
|
|
73
|
+
if arr.metadata.zarr_format == 3:
|
|
74
|
+
layout = _layout_of(KvikioCodecPipeline.from_codecs(arr.metadata.codecs))
|
|
75
|
+
if layout is None:
|
|
76
|
+
problems.append(
|
|
77
|
+
f"codecs {desc['codecs']} cannot be decoded on the GPU (needs zarr v3 with "
|
|
78
|
+
"little-endian bytes, zstd without checksum or no compression, and no other codecs)"
|
|
79
|
+
)
|
|
80
|
+
dtype_ok = _gpu_dtype(np.dtype(arr.dtype))
|
|
81
|
+
if not dtype_ok:
|
|
82
|
+
problems.append(
|
|
83
|
+
f"data type {arr.dtype} is decoded on the CPU (the GPU decodes fixed-size numeric ones)"
|
|
84
|
+
)
|
|
85
|
+
too_large = layout is not None and layout.compressed and desc["chunk_bytes"] > _NVCOMP_MAX_FRAME
|
|
86
|
+
if too_large:
|
|
87
|
+
problems.append("chunks of 2 GiB or more are decoded on the CPU (nvCOMP's limit)")
|
|
88
|
+
if type(arr.store) is not LocalStore: # (the exact type, as in `_local_path`)
|
|
89
|
+
problems.append(
|
|
90
|
+
f"stored in a {type(arr.store).__name__}, not a LocalStore: "
|
|
91
|
+
"its chunks are decoded on the CPU"
|
|
92
|
+
)
|
|
93
|
+
if desc["chunk_bytes"] > _MAX_GOOD_CHUNK_BYTES:
|
|
94
|
+
problems.append(
|
|
95
|
+
f"chunks of {desc['chunk_bytes'] / 2**20:.1f} MiB decode slowly on the GPU "
|
|
96
|
+
"(~256 KiB is best)"
|
|
97
|
+
)
|
|
98
|
+
if not desc["sharded"] and arr.nchunks > 1:
|
|
99
|
+
problems.append("not sharded: every chunk is a separate file, which slows down small reads")
|
|
100
|
+
if layout is not None and _shard_unordered(arr, layout):
|
|
101
|
+
problems.append(
|
|
102
|
+
"the chunks inside its shards are stored out of order (as zarrs writes them), "
|
|
103
|
+
"so a contiguous range needs many small reads"
|
|
104
|
+
)
|
|
105
|
+
desc["gpu_readable"] = layout is not None and dtype_ok and not too_large
|
|
106
|
+
desc["problems"] = problems
|
|
107
|
+
return desc
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _shard_unordered(arr: zarr.Array, layout: Any) -> bool:
|
|
111
|
+
"""Whether the inner chunks of the first shard of a 1-D array are stored out of order.
|
|
112
|
+
|
|
113
|
+
Only for local stores. (zarr stores the chunks of N-D shards in Morton order.)
|
|
114
|
+
"""
|
|
115
|
+
from zarr.storage import LocalStore
|
|
116
|
+
|
|
117
|
+
if (
|
|
118
|
+
arr.ndim != 1
|
|
119
|
+
or arr.shards is None
|
|
120
|
+
or layout.inner_chunk_shape is None
|
|
121
|
+
or not isinstance(arr.store, LocalStore)
|
|
122
|
+
):
|
|
123
|
+
return False
|
|
124
|
+
path = Path(arr.store.root) / arr.path / arr.metadata.encode_chunk_key((0,) * arr.ndim)
|
|
125
|
+
if not path.exists():
|
|
126
|
+
return False
|
|
127
|
+
per_shard = tuple(s // c for s, c in zip(arr.shards, layout.inner_chunk_shape, strict=True))
|
|
128
|
+
index = _read_shard_index(layout, path, path.stat().st_size, per_shard)
|
|
129
|
+
offsets = index[..., 0].ravel()
|
|
130
|
+
offsets = offsets[offsets != _MAX_UINT_64].astype(np.int64)
|
|
131
|
+
return bool((np.diff(offsets) < 0).any())
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _codecs(arr: zarr.Array) -> list[Any]:
|
|
135
|
+
if arr.metadata.zarr_format == 3:
|
|
136
|
+
from zarr.codecs import ShardingCodec
|
|
137
|
+
|
|
138
|
+
# describe what is inside the shards
|
|
139
|
+
return [
|
|
140
|
+
c
|
|
141
|
+
for codec in arr.metadata.codecs
|
|
142
|
+
for c in (codec.codecs if isinstance(codec, ShardingCodec) else [codec])
|
|
143
|
+
]
|
|
144
|
+
return [c for c in (*arr.filters, *arr.compressors) if c is not None]
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _version(pkg: str) -> str | None:
|
|
148
|
+
try:
|
|
149
|
+
return version(pkg)
|
|
150
|
+
except PackageNotFoundError:
|
|
151
|
+
# pip names e.g. nvCOMP's bindings and CuPy by CUDA version
|
|
152
|
+
for suffix in ("-cu13", "-cu12", "-cuda13x", "-cuda12x"):
|
|
153
|
+
try:
|
|
154
|
+
return version(pkg + suffix)
|
|
155
|
+
except PackageNotFoundError:
|
|
156
|
+
pass
|
|
157
|
+
return None
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _gds_status() -> dict[str, Any]:
|
|
161
|
+
exe = shutil.which("gdscheck") or next(
|
|
162
|
+
(
|
|
163
|
+
p
|
|
164
|
+
for p in (
|
|
165
|
+
Path(os.environ.get("CUDA_HOME", "/usr/local/cuda")) / "gds/tools/gdscheck",
|
|
166
|
+
Path("/usr/local/cuda/gds/tools/gdscheck"),
|
|
167
|
+
)
|
|
168
|
+
if p.exists()
|
|
169
|
+
),
|
|
170
|
+
None,
|
|
171
|
+
)
|
|
172
|
+
if exe is None:
|
|
173
|
+
return {"status": "unknown (gdscheck not found)"}
|
|
174
|
+
try:
|
|
175
|
+
out = subprocess.run(
|
|
176
|
+
[str(exe), "-p"], capture_output=True, text=True, timeout=60, check=False
|
|
177
|
+
).stdout
|
|
178
|
+
except (OSError, subprocess.SubprocessError) as e:
|
|
179
|
+
return {"status": f"unknown ({e})"}
|
|
180
|
+
fields = {}
|
|
181
|
+
for line in out.splitlines():
|
|
182
|
+
key, sep, value = line.partition(":")
|
|
183
|
+
if sep:
|
|
184
|
+
fields[key.strip()] = value.strip()
|
|
185
|
+
nvme = fields.get("NVMe", "")
|
|
186
|
+
p2pdma = fields.get("properties.use_pci_p2pdma", "").lower() == "true"
|
|
187
|
+
# (not `in`: gdscheck also reports "Unsupported")
|
|
188
|
+
direct = nvme.lower().startswith("supported") or p2pdma
|
|
189
|
+
return {
|
|
190
|
+
"status": "direct" if direct else "compatibility mode",
|
|
191
|
+
"nvme": nvme or None,
|
|
192
|
+
"use_pci_p2pdma": p2pdma,
|
|
193
|
+
}
|