Add optional gpu acceleration #100
Open
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.
Add Optional GPU Acceleration using CuPy
Summary
This PR adds optional GPU acceleration to museval's BSS evaluation metrics using CuPy, providing significant performance improvements (10-20x speedup) while maintaining full backward compatibility.
Motivation
BSS evaluation metrics can be computationally expensive, especially for:
GPU acceleration makes these workloads significantly faster without changing the API or requiring users to modify existing code.
Changes
Core Implementation
1. Backend Abstraction Layer (
museval/backends/)__init__.py: Backend selection and initialization with graceful fallbackbase.py: Abstract base class defining the backend interfacenumpy_backend.py: CPU implementation (default, no changes for existing users)cupy_backend.py: GPU implementation using CuPy2. Refactored Core Metrics (
museval/metrics.py)backend='auto'parameter to all main functions3. Dependencies (
setup.py)gpuextra:pip install museval[gpu]cupy-cuda12xwhich bundles CUDA libraries (users only need GPU drivers)4. Comprehensive Testing
tests/test_backends.py: Backend abstraction tests (11 tests)tests/test_gpu_consistency.py: CPU/GPU numerical consistency tests (18 tests)tests/benchmark_gpu.py: Performance benchmarking script5. Documentation & Examples
README.mdwith GPU installation and usage instructionsexamples/gpu_example.pydemonstrating GPU usageAPI Changes
Backward Compatible - No Breaking Changes!
All existing code continues to work without modification:
New Optional GPU Support
All main functions support the
backendparameter:bss_eval()bss_eval_sources()bss_eval_images()bss_eval_sources_framewise()bss_eval_images_framewise()Performance Results
Benchmarked on NVIDIA RTX A6000 with CUDA 12.4:
Numerical Consistency
CPU and GPU backends produce identical results within floating-point precision:
Installation
CPU Only (Default - No Changes)
With GPU Support
Requirements for GPU:
Testing
All tests pass:
pytest tests/ # 51 passed, 1 skipped (GPU test when CuPy unavailable)Test Coverage
Design Decisions
Checklist
Future Enhancements (Not in this PR)
Potential future additions:
Notes
-cuda12xwheel which bundles CUDA runtime librariesTesting Instructions for Reviewers
CPU-only (should work everywhere):
pip install -e . pytest tests/ -vWith GPU (requires NVIDIA GPU):