Skip to content

ENH Add CUDA support for Hilbert transforms - #14164

Merged
larsoner merged 6 commits into
mne-tools:mainfrom
viranovskaya:perf/cuda-hilbert-current
Aug 23, 2026
Merged

ENH Add CUDA support for Hilbert transforms#14164
larsoner merged 6 commits into
mne-tools:mainfrom
viranovskaya:perf/cuda-hilbert-current

Conversation

@viranovskaya

@viranovskaya viranovskaya commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Related to #13993 and #13994.

This implements the alternative suggested in the discussion: CUDA support in apply_hilbert instead of a second public job-control parameter in annotate_muscle_zscore.

When n_jobs="cuda" is requested, the analytic signal is computed with CuPy FFT and transferred back to NumPy. If CUDA cannot be initialized, the existing CPU implementation is used with one job. This allows annotate_muscle_zscore(..., n_jobs="cuda") to use the same setting for filtering and the Hilbert transform without exposing an implementation-specific parameter.

The numerical tests compare the FFT implementation with scipy.signal.hilbert for odd and even lengths, zero padding, analytic signals, and envelopes. A regression test covers the full muscle-annotation call.

Local checks:

  • 290 passed, 12 skipped in the filter and artifact-detection test modules
  • ruff check and format
  • ty
  • codespell
  • rstcheck

This was tested on a machine without CUDA hardware. The CPU fallback and numerical implementation are covered locally, but the actual CuPy device path still needs CUDA-backed verification.

Closes #13993
Closes #13994

@viranovskaya
viranovskaya marked this pull request as ready for review August 17, 2026 06:02

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the slow response -- looks good to me and I tested locally with cupy-13x and it worked (when I set MNE_USE_CUDA=true properly). I'll make these minor edits then merge, thanks in advance @viranovskaya !

Comment thread mne/filter.py
Comment thread mne/preprocessing/artifact_detection.py
Comment thread mne/preprocessing/artifact_detection.py Outdated
Comment thread mne/filter.py Outdated
Comment thread mne/preprocessing/artifact_detection.py Outdated
larsoner and others added 2 commits August 22, 2026 23:15
Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
@larsoner
larsoner merged commit 1bf2e39 into mne-tools:main Aug 23, 2026
28 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

annotate_muscle_zscore does not work with n_jobs = 'cuda'

2 participants