Skip to content

Add GPU backend selection with load_cuda(), load_metal(), load_amdgpu(), load_oneapi() - #23

Merged
cncastillo merged 9 commits into
JuliaHealth:mainfrom
anvika-singhal:gpu-backend-selection
Jul 31, 2026
Merged

Add GPU backend selection with load_cuda(), load_metal(), load_amdgpu(), load_oneapi()#23
cncastillo merged 9 commits into
JuliaHealth:mainfrom
anvika-singhal:gpu-backend-selection

Conversation

@anvika-singhal

@anvika-singhal anvika-singhal commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Enables GPU backend selection in komamripy, mirroring KomaMRI.jl's package extension system exactly. Users can now load CUDA, Metal, AMDGPU, or oneAPI backends to enable GPU acceleration with a single function call. Addresses JuliaHealth/KomaMRI.jl#736.

Included

src/komamripy/_backends.py (new)

  • Julia: using CUDA -> Python: km.load_cuda()
  • Julia: using Metal -> Python: km.load_metal()
  • Julia: using AMDGPU -> Python: km.load_amdgpu()
  • Julia: using oneAPI -> Python: km.load_oneapi()

Each function calls jl.seval() to load the corresponding Julia GPU package into the Julia session.

src/komamripy/__init__.py (modified)

  • Imports and exports the four backend loading functions
  • Updated docstring with GPU backend usage examples

examples/gpu_backend_selection_example.py (new)

  • Demonstrates optional GPU backend loading
  • Shows that simulations run on CPU by default (no backend required)
  • Includes commented examples for each backend
  • Automatically tested by test_integration_examples.py

Details

No Python-side state management needed, Julia handles backend detection and defaulting.

@cncastillo cncastillo 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.

Just minor comments.

Do you have some "evidence" that this works? maybe add a screenshot of a succesful run using your pc or ultron.

I would also add one line showing km.load_cuda() to the README.

Comment thread examples/gpu_backend_selection.py
Comment thread src/komamripy/__init__.py
@anvika-singhal

Copy link
Copy Markdown
Collaborator Author
image Installed necessary backends on first run. image No duplicate installations on second run.

@cncastillo
cncastillo merged commit fba01a9 into JuliaHealth:main Jul 31, 2026
7 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.

2 participants