Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of Multi-GPU simulation #355

Open
Tracked by #350
rkierulf opened this issue Apr 2, 2024 · 0 comments
Open
Tracked by #350

Add example of Multi-GPU simulation #355

rkierulf opened this issue Apr 2, 2024 · 0 comments
Labels

Comments

@rkierulf
Copy link
Collaborator

rkierulf commented Apr 2, 2024

Feature Request

In some cases, it may be beneficial to run MRI simulations on multiple GPUs if the problem is too large for single-GPU memory. KomaMRI does not have built-in support for this, but due to the independent spin property, it would not be too hard for a programmer to manually split the simulation into parts, run each part on a different GPU, then add the results at the end.

Based on this section of the CUDA.jl documentation, here is one example I think would work without needing to update code within the package (NOTE: I have not tested this!):

using Distributed, CUDA

addprocs(length(devices()))
@everywhere using CUDA, KomaMRI

sys = Scanner()
obj = Phantom()
parts = kfoldperm(length(obj), length(devices))
seq = read_seq("SequenceFileName.seq")
signal_arr = []

asyncmap((zip(workers(), devices()))) do (p, d)
    remotecall_wait(p) do
        device!(d)
        push!(signal_arr, simulate(@view(obj[p]), seq, sys))
    end
end

signal = reduce(.+, signal_arr)

If this does work, it would be helpful to add to the examples folder of the repository and package documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants