Add GPU acceleration subpackage linumpy.gpu (CuPy + CPU fallback) - #140
Open
FIrgolitsch wants to merge 1 commit into
Open
Add GPU acceleration subpackage linumpy.gpu (CuPy + CPU fallback)#140FIrgolitsch wants to merge 1 commit into
FIrgolitsch wants to merge 1 commit into
Conversation
…ne, bias field, image quality, zarr I/O
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
linumpy.gpusubpackage: GPU-accelerated implementations of the compute-heavy operations used elsewhere in the library (FFT phase correlation, affine interpolation, morphology, B-spline fitting, bias-field correction, image-quality metrics, tissue-interface detection, and Zarr I/O), all with automatic fallback to NumPy when CuPy/CUDA is unavailable.Land after #139.
What changed
New package
linumpy/gpu/(13 modules, all new):__init__.pyCUDA_VISIBLE_DEVICES),to_gpu/to_cpu/get_array_modulehelpers,list_gpus/select_gpu/select_best_gpu, env-gated viaLINUMPY_USE_GPUinterface.pylinumpy.geometry.interface)array_ops.pyfft_ops.pyinterpolation.pymorphology.pycorrections.pybspline.pybias_field.pyimage_quality.pyzarr_io.pykvikio_zarr.pynvcomp_zstd.pyPlus
linumpy/tests/test_gpu_bspline.py— B-spline correctness (partition-of-unity, constant/linear recovery, mask handling) and CPU/GPU numerical agreement on the fit + evaluate paths.Design notes
np.ndarray/ArrayLike; callers stay device-agnostic. CuPy is imported lazily and gated on availability, so importing the package never requires CUDA.CUDA_VISIBLE_DEVICES) hosts short-circuit to device 0.Anyvia the[tool.ty]replace-imports-with-anylist (cupy,cupyx,numba,kvikio,nvidia), so the type checker stays green without CUDA installed.Reviewer focus
test_gpu_bspline.pyis the main automated guard for numerical equivalence — worth a close read since real CUDA isn't exercised in CI.__init__.py) uses afcntl-locked counter file in$TMPDIR; check that the locking/unlocking and the single-GPU fast path match your deployment (e.g. Nextflow settingCUDA_VISIBLE_DEVICESper task).kvikio/nvcomppaths are CUDA-only and not covered by CI; they're verified manually on the GPU server.How to verify
uv run ruff check linumpy/gpu/ uv run ty check linumpy/gpu/ uv run pytest linumpy/tests/test_gpu_bspline.py -x -v # runs the CPU path without CUDA