feat: Add GPU-accelerated operations via PyTorch#21
Closed
maragall wants to merge 18 commits intoCephla-Lab:mainfrom
Closed
feat: Add GPU-accelerated operations via PyTorch#21maragall wants to merge 18 commits intoCephla-Lab:mainfrom
maragall wants to merge 18 commits intoCephla-Lab:mainfrom
Conversation
Consolidates PRs Cephla-Lab#4-8 into a single feature branch: - phase_cross_correlation: GPU FFT via torch.fft (~46x speedup) - shift_array: GPU grid_sample for subpixel shifts (~6.7x speedup) - match_histograms: GPU sort/quantile mapping (~13.3x speedup) - block_reduce: GPU avg_pool2d (~4x speedup) - compute_ssim: GPU conv2d for local statistics (~6.4x speedup) All functions include automatic CPU fallback when CUDA is unavailable. Replaces cupy/cucim dependency with PyTorch for broader compatibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add type hints to phase_cross_correlation, shift_array, match_histograms, block_reduce, compute_ssim - Add return type hints to to_numpy and to_device - Import Callable, Any, Union from typing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix incorrect pixel assignment in _match_histograms_torch The previous code used unnecessary indexing that permuted results incorrectly - Simplify to_device return type from Union[Any, np.ndarray] to Any - Remove unused Union import - Add pixel-by-pixel test comparing GPU vs skimage results 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove redundant `torch is not None` check in to_numpy - Add type hint to _shift_array_torch shift_vec parameter - Fix shift_array CPU path to compute in float64 for API consistency (preserve_dtype=False now returns float on both GPU and CPU paths) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The GPU implementation returns 0.0 for error and phasediff values since these are not computed. Added notes to docstring to clarify. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Author
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
phase_cross_correlation,shift_array,match_histograms,block_reduce,compute_ssim) using PyTorch CUDA, with automatic CPU fallback when no GPU is available_FFT_EPS,_SSIM_K1,_SSIM_K2,_PARABOLIC_EPS)Benchmark results (S5_reg1, 184 tiles)
GPU speedup is most visible in the registration phase. The full pipeline is dominated by I/O-bound fusion, where GPU provides minimal benefit.
Test plan
pytest tests/test_block_reduce.py tests/test_fft.py tests/test_histogram_match.py tests/test_shift_array.py tests/test_ssim.py tests/test_cpu_fallback.py— all new GPU tests pass🤖 Generated with Claude Code