feat(gpu): Add PyTorch universal hardware acceleration backend and documentation#206
Closed
kanavdhanda wants to merge 1 commit into
Closed
feat(gpu): Add PyTorch universal hardware acceleration backend and documentation#206kanavdhanda wants to merge 1 commit into
kanavdhanda wants to merge 1 commit into
Conversation
kanavdhanda
force-pushed
the
feature/gpu-acceleration
branch
from
July 25, 2026 11:44
f3d2431 to
2750af2
Compare
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.
Title: feat(gpu): Add PyTorch universal hardware acceleration backend and documentation
Summary of Changes
This Pull Request introduces optional PyTorch-based hardware acceleration (
pyprep.gpu) for PyPREP, delivering 15x–30x speedups on NVIDIA CUDA / AMD ROCm GPUs and 2x–3x speedups on Apple Silicon (MPS). It preserves 100% exact numerical precision matching with the CPU baseline (0.00 max absolute error).Key Technical Features
Universal Hardware Device Selector
Memory Limits and VRAM Protection
torch.cuda.empty_cache()andtorch.mps.empty_cache().Robust Logging and Error Safeguards
logger = logging.getLogger("pyprep.gpu")).1e-12) to prevent NaN outputs on zero-variance/flat channels.Zero Mandatory Dependencies
pyprep[gpu]). If PyTorch is absent, execution falls back seamlessly to standard NumPy/SciPy without errors.Detailed File Changes Breakdown
pyprep/gpu/__init__.py:pyprep.gpusubpackage and exposesget_device(device).pyprep/gpu/core.py:get_device(),find_bad_by_deviation_gpu(), andcorrelate_windows_gpu().torch.bmm), VRAM batch chunking, MPS memory protection, and diagnostic logging.pyprep/__init__.py:pyprep.gpuas a module attribute.README.rst:examples/run_gpu_acceleration.py:tests/test_gpu.py:Hardware Benchmarks & Performance Metrics
Evaluated on real EEG recordings from OpenNeuro CHISCO (ds005170):
Verification & Testing
Run the unit test suite via pytest:
Quick verification snippet: