Skip to content

Skip GPU excitation relaxation for infinite T1 and T2 - #919

Open
KookiesNKareem wants to merge 3 commits into
JuliaHealth:masterfrom
KookiesNKareem:branch/infinite-relaxation-excitation-fast-path
Open

Skip GPU excitation relaxation for infinite T1 and T2#919
KookiesNKareem wants to merge 3 commits into
JuliaHealth:masterfrom
KookiesNKareem:branch/infinite-relaxation-excitation-fast-path

Conversation

@KookiesNKareem

Copy link
Copy Markdown
Collaborator

Summary

  • detect phantoms whose T1 and T2 values are all infinite before GPU transfer
  • carry that result through GPU preallocation as a Val type parameter
  • specialize the excitation kernel so the infinite-relaxation path omits T1/T2/rho loads and both exponential evaluations

Why

For infinite T1 and T2, E1 and E2 are exactly one. The GPU excitation kernel was still loading relaxation data and evaluating two exponentials for every spin and time step. Encoding the condition in the kernel type gives the GPU compiler separate finite- and infinite-relaxation kernels while keeping a single kernel implementation.

Finite-relaxation behavior is unchanged.

Validation

  • Pkg.test("KomaMRICore"): 432/432 passed
  • Metal A/B, 10,000 spins x 13 steps, synchronized, 100 samples x 100 launches:
    • regular: 70.78 us/launch
    • infinite-relaxation fast path: 57.05 us/launch
    • speedup: 1.24x
    • maximum Mxy/Mz error: 0
  • git diff --check

The run-gpu-ci label is attached for CUDA coverage.

@KookiesNKareem KookiesNKareem added the run-gpu-ci To run .buildkite CI label Jul 23, 2026
@cncastillo

Copy link
Copy Markdown
Member

Actually we might be able to make it even faster for the excitation kernel. For the non-relaxation case, the excitation is equivalent to Spinor reduction.

$$ (\alpha_1, \beta_1) \times \dots \times (\alpha_N, \beta_N) = (\alpha_{eq}, \beta_{eq}) $$

So we don't need repeated rotations of $\vec{M}$, we just do a parallel reduction on the spinors and then apply $(\alpha_{eq}, \beta_{eq})$ once, or at least once per ADC sample (generally there are no ADCs during excitation).

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.78%. Comparing base (206593e) to head (5a37205).

Files with missing lines Patch % Lines
...re/src/simulation/SimMethods/Bloch/gpu/BlochGPU.jl 66.66% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #919      +/-   ##
==========================================
- Coverage   91.83%   91.78%   -0.06%     
==========================================
  Files         137      137              
  Lines        7188     7192       +4     
==========================================
  Hits         6601     6601              
- Misses        587      591       +4     
Flag Coverage Δ
base 90.76% <ø> (ø)
core 91.13% <83.33%> (-0.30%) ⬇️
files 95.15% <ø> (ø)
komamri 90.51% <ø> (ø)
plots 91.76% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...Core/src/simulation/SimMethods/SimulationMethod.jl 100.00% <100.00%> (ø)
KomaMRICore/src/simulation/SimulatorCore.jl 92.52% <100.00%> (+0.04%) ⬆️
...re/src/simulation/SimMethods/Bloch/gpu/BlochGPU.jl 67.92% <66.66%> (-6.59%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-gpu-ci To run .buildkite CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants