-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from MagneticResonanceImaging/nh/gpuSupport
Add GPU support to MRIReco.jl
- Loading branch information
Showing
38 changed files
with
800 additions
and
635 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
steps: | ||
- label: "Nvidia GPUs -- MRIReco.jl" | ||
plugins: | ||
- JuliaCI/julia#v1: | ||
version: "1.10" | ||
agents: | ||
queue: "juliagpu" | ||
cuda: "*" | ||
command: | | ||
julia --color=yes --project -e ' | ||
using Pkg | ||
Pkg.develop([PackageSpec(path=pwd(), subdir="MRIBase") | ||
, PackageSpec(path=pwd(), subdir="MRIFiles") | ||
, PackageSpec(path=pwd(), subdir="MRISampling") | ||
, PackageSpec(path=pwd(), subdir="MRISimulation") | ||
, PackageSpec(path=pwd(), subdir="MRIOperators") | ||
, PackageSpec(path=pwd(), subdir="MRICoilSensitivities")]) | ||
Pkg.add("TestEnv") | ||
using TestEnv | ||
TestEnv.activate(); | ||
Pkg.add("CUDA") | ||
Pkg.instantiate() | ||
include("test/gpu/cuda.jl")' | ||
timeout_in_minutes: 30 | ||
|
||
#- label: "AMD GPUs -- MRIReco.jl" | ||
# plugins: | ||
# - JuliaCI/julia#v1: | ||
# version: "1.10" | ||
# agents: | ||
# queue: "juliagpu" | ||
# rocm: "*" | ||
# rocmgpu: "*" | ||
# command: | | ||
# julia --color=yes --project -e ' | ||
# using Pkg | ||
# Pkg.develop([PackageSpec(path=pwd(), subdir="MRIBase") | ||
# , PackageSpec(path=pwd(), subdir="MRIFiles") | ||
# , PackageSpec(path=pwd(), subdir="MRISampling") | ||
# , PackageSpec(path=pwd(), subdir="MRISimulation") | ||
# , PackageSpec(path=pwd(), subdir="MRIOperators") | ||
# , PackageSpec(path=pwd(), subdir="MRICoilSensitivities")]) | ||
# Pkg.add("TestEnv") | ||
# using TestEnv | ||
# TestEnv.activate(); | ||
# Pkg.add("AMDGPU") | ||
# Pkg.instantiate() | ||
# include("test/gpu/rocm.jl")' | ||
# timeout_in_minutes: 30 | ||
|
||
- label: "Nvidia GPUs -- MRIOperators.jl" | ||
plugins: | ||
- JuliaCI/julia#v1: | ||
version: "1.10" | ||
agents: | ||
queue: "juliagpu" | ||
cuda: "*" | ||
command: | | ||
julia --color=yes --project -e ' | ||
using Pkg | ||
Pkg.develop([PackageSpec(path=pwd(), subdir="MRIBase") | ||
, PackageSpec(path=pwd(), subdir="MRIFiles") | ||
, PackageSpec(path=pwd(), subdir="MRISampling") | ||
, PackageSpec(path=pwd(), subdir="MRISimulation") | ||
, PackageSpec(path=pwd(), subdir="MRIOperators") | ||
, PackageSpec(path=pwd(), subdir="MRICoilSensitivities")]) | ||
Pkg.add("TestEnv") | ||
using TestEnv | ||
TestEnv.activate("MRIOperators"); | ||
Pkg.add("CUDA") | ||
Pkg.instantiate() | ||
include("MRIOperators/test/gpu/cuda.jl")' | ||
timeout_in_minutes: 30 | ||
|
||
|
||
- label: "AMD GPUs -- MRIOperators.jl" | ||
plugins: | ||
- JuliaCI/julia#v1: | ||
version: "1.10" | ||
agents: | ||
queue: "juliagpu" | ||
rocm: "*" | ||
rocmgpu: "*" | ||
command: | | ||
julia --color=yes --project -e ' | ||
using Pkg | ||
Pkg.develop([PackageSpec(path=pwd(), subdir="MRIBase") | ||
, PackageSpec(path=pwd(), subdir="MRIFiles") | ||
, PackageSpec(path=pwd(), subdir="MRISampling") | ||
, PackageSpec(path=pwd(), subdir="MRISimulation") | ||
, PackageSpec(path=pwd(), subdir="MRIOperators") | ||
, PackageSpec(path=pwd(), subdir="MRICoilSensitivities")]) | ||
Pkg.add("TestEnv") | ||
using TestEnv | ||
TestEnv.activate("MRIOperators"); | ||
Pkg.add("AMDGPU") | ||
Pkg.instantiate() | ||
include("MRIOperators/test/gpu/rocm.jl")' | ||
timeout_in_minutes: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "MRIBase" | ||
uuid = "f7771a9a-6e57-4e71-863b-6e4b6a2f17df" | ||
author = ["Tobias Knopp <[email protected]>"] | ||
version = "0.4.3" | ||
version = "0.4.4" | ||
|
||
[deps] | ||
AbstractNFFTs = "7f219486-4aa7-41d6-80a7-e08ef20ceed7" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
name = "MRIOperators" | ||
uuid = "fb1137e3-90a6-46ce-a672-6e1e53d120f2" | ||
author = ["Tobias Knopp <[email protected]>"] | ||
version = "0.2.1" | ||
version = "0.3.0" | ||
|
||
[deps] | ||
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" | ||
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" | ||
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" | ||
MRIBase = "f7771a9a-6e57-4e71-863b-6e4b6a2f17df" | ||
|
@@ -17,15 +18,20 @@ LinearOperators = "5c8ed15e-5a4c-59e4-a42b-c7e8811fb125" | |
LinearOperatorCollection = "a4a2c56f-fead-462a-a3ab-85921a5f2575" | ||
Wavelets = "29a6e085-ba6d-5f35-a997-948ac2efa89a" | ||
|
||
[weakdeps] | ||
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7" | ||
|
||
[compat] | ||
Adapt = "3, 4" | ||
StatsBase = "0.33, 0.34" | ||
Distributions = "0.25" | ||
GPUArrays = "8, 9, 10" | ||
JLArrays = "0.1" | ||
julia = "1.6" | ||
MRIBase = "0.4" | ||
Reexport = "1" | ||
LinearOperators = "2.3.3" | ||
LinearOperatorCollection = "1.1" | ||
LinearOperatorCollection = "2" | ||
NFFT = "0.13" | ||
FLoops = "0.2" | ||
LowRankApprox = "0.5" | ||
|
@@ -34,11 +40,10 @@ Wavelets = "0.9, 0.10" | |
[extras] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
MRISimulation = "8988da37-ea20-4fa6-9af7-8a6f6f9a8970" | ||
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb" | ||
|
||
[targets] | ||
test = ["Test", "MRISimulation"] | ||
|
||
|
||
|
||
|
||
test = ["Test", "MRISimulation", "JLArrays"] | ||
|
||
[extensions] | ||
MRIOperatorsGPUArraysExt = "GPUArrays" |
110 changes: 110 additions & 0 deletions
110
MRIOperators/ext/MRIOperatorsGPUArraysExt/ExplicitOp.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
function MRIOperators.produ!(out::vecTc, x::vecTc, shape::NTuple{2,Int64}, | ||
nodes::matT, times::vecT, echoOffset::T, | ||
disturbanceTerm::matTc) where {T, Tc <: Union{T, Complex{T}}, vecTc <: AbstractGPUArray{Tc}, matT <: AbstractGPUArray{T}, vecT <: AbstractGPUArray{T}, matTc <: AbstractGPUArray{Tc}} | ||
|
||
factor = Tc(-2 * 1im * pi) | ||
limit = prod(shape) | ||
fill!(out, zero(Tc)) | ||
gpu_call(out, reshape(x, shape), shape, nodes, times, echoOffset, disturbanceTerm; elements = size(nodes, 2)) do ctx, out_, x_, shape_, nodes_, times_, echoOffset_, disturbanceTerm_ | ||
k = linear_index(ctx) | ||
if !(1 <= k <= limit) | ||
return nothing | ||
end | ||
|
||
for nx = 1:shape_[1] | ||
for ny = 1:shape_[2] | ||
phi = (nodes_[1, k] * (nx - shape_[1] / 2 - 1) + nodes_[2, k] * (ny - shape_[2] / 2 - 1)) | ||
e = exp(factor * phi - (times_[k] - echoOffset_) * disturbanceTerm_[nx, ny]) | ||
out_[k] += x_[nx, ny] * e | ||
end | ||
end | ||
return nothing | ||
end | ||
|
||
return out | ||
end | ||
|
||
function MRIOperators.produ!(out::vecTc, x::vecTc, shape::NTuple{3,Int64}, | ||
nodes::matT, times::vecT, echoOffset::T, | ||
disturbanceTerm::arrTc) where {T, Tc <: Union{T, Complex{T}}, vecTc <: AbstractGPUArray{Tc}, matT <: AbstractGPUArray{T}, vecT <: AbstractGPUArray{T}, arrTc <: AbstractGPUArray{Tc, 3}} | ||
|
||
factor = Tc(-2 * 1im * pi) | ||
limit = prod(shape) | ||
fill!(out, zero(Tc)) | ||
gpu_call(out, reshape(x, shape), shape, nodes, times, echoOffset, disturbanceTerm; elements = size(nodes, 2)) do ctx, out_, x_, shape_, nodes_, times_, echoOffset_, disturbanceTerm_ | ||
k = linear_index(ctx) | ||
if !(1 <= k <= limit) | ||
return nothing | ||
end | ||
|
||
for nx = 1:shape_[1] | ||
for ny = 1:shape_[2] | ||
for nz = 1:shape_[3] | ||
phi = (nodes_[1, k] * (nx - shape_[1] / 2 - 1) + nodes_[2, k] * (ny - shape_[2] / 2 - 1) + nodes_[3, k] * (nz - shape_[3] / 2 - 1)) | ||
e = exp(factor * phi - (times_[k] - echoOffset_) * disturbanceTerm_[nx, ny, nz]) | ||
out_[k] += x_[nx, ny, nz] * e | ||
end | ||
end | ||
end | ||
return nothing | ||
end | ||
|
||
return out | ||
end | ||
|
||
function MRIOperators.ctprodu!(out::vecTc, x::vecTc, shape::NTuple{2,Int64}, | ||
nodes::matT, times::vecT, echoOffset::T, | ||
disturbanceTerm::matTc) where {T, Tc <: Union{T, Complex{T}}, vecTc <: AbstractGPUArray{Tc}, matT <: AbstractGPUArray{T}, vecT <: AbstractGPUArray{T}, matTc <: AbstractGPUArray{Tc}} | ||
|
||
factor = Tc(-2 * 1im * pi) | ||
limit = prod(shape) | ||
fill!(out, zero(Tc)) | ||
gpu_call(reshape(out, shape), x, shape, nodes, times, echoOffset, disturbanceTerm; elements = limit) do ctx, out_, x_, shape_, nodes_, times_, echoOffset_, disturbanceTerm_ | ||
linearIndex = linear_index(ctx) | ||
if !(1 <= linearIndex <= limit) | ||
return nothing | ||
end | ||
|
||
cartIndex = CartesianIndices(shape)[linearIndex] | ||
|
||
nx = cartIndex[1] | ||
ny = cartIndex[2] | ||
for k = 1:size(nodes_, 2) | ||
phi = (nodes_[1,k]*(nx-shape_[1]/2-1)+nodes_[2,k]*(ny-shape_[2]/2-1)) | ||
e = exp(factor * phi - (times_[k]-echoOffset_)*disturbanceTerm_[cartIndex]) | ||
out_[cartIndex] += x_[k] * conj(e) | ||
end | ||
return nothing | ||
end | ||
|
||
return out | ||
end | ||
|
||
function MRIOperators.ctprodu!(out::vecTc, x::vecTc, shape::NTuple{3,Int64}, | ||
nodes::matT, times::vecT, echoOffset::T, | ||
disturbanceTerm::arrTc) where {T, Tc <: Union{T, Complex{T}}, vecTc <: AbstractGPUArray{Tc}, matT <: AbstractGPUArray{T}, vecT <: AbstractGPUArray{T}, arrTc <: AbstractGPUArray{Tc, 3}} | ||
|
||
factor = Tc(-2 * 1im * pi) | ||
limit = prod(shape) | ||
fill!(out, zero(Tc)) | ||
gpu_call(reshape(out, shape), x, shape, nodes, times, echoOffset, disturbanceTerm; elements = limit) do ctx, out_, x_, shape_, nodes_, times_, echoOffset_, disturbanceTerm_ | ||
linearIndex = linear_index(ctx) | ||
if !(1 <= linearIndex <= limit) | ||
return nothing | ||
end | ||
|
||
cartIndex = CartesianIndices(shape)[linearIndex] | ||
|
||
nx = cartIndex[1] | ||
ny = cartIndex[2] | ||
nz = cartIndex[3] | ||
for k = 1:size(nodes_, 2) | ||
phi = (nodes_[1,k]*(nx-shape_[1]/2-1)+nodes_[2,k]*(ny-shape_[2]/2-1)+nodes_[3,k]*(nz-shape_[3]/2-1)) | ||
e = exp(factor * phi - (times_[k]-echoOffset_)*disturbanceTerm_[cartIndex]) | ||
out_[cartIndex] += x_[k] * conj(e) | ||
end | ||
return nothing | ||
end | ||
|
||
return out | ||
end |
41 changes: 41 additions & 0 deletions
41
MRIOperators/ext/MRIOperatorsGPUArraysExt/FieldmapNFFTOp.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
function MRIOperators.produ_inner!(K, C::matT, A::matT, shape, d::Vector{vecT}, s::vecT, sp, plan, idx, x_::vecT, p::Vector{arrT}) where {T, vecT <: AbstractGPUVector{T}, matT <: AbstractGPUMatrix{T}, arrT <: AbstractGPUArray{T}} | ||
for κ=1:K | ||
if !isempty(idx[κ]) | ||
p[κ][:] .= C[κ,:] .* x_ | ||
mul!(d[κ], plan[κ], p[κ]) | ||
# Assumption: l is unique per idx[κ] | ||
gpu_call(idx[κ], d[κ], view(A, :, κ), s) do ctx, indices, d_, A_, s_ | ||
k = @linearidx(indices) | ||
l = indices[k] | ||
s_[l] += d_[k]*A_[l] | ||
return nothing | ||
end | ||
end | ||
end | ||
|
||
return | ||
end | ||
|
||
|
||
function MRIOperators.ctprodu_inner!(K, C::matT, A::matT, shape, d::Vector{vecT}, y::vecT, sp, plan, idx, x::vecT, p::Vector{arrT}) where {T, vecT <: AbstractGPUVector{T}, matT <: AbstractGPUMatrix{T}, arrT <: AbstractGPUArray{T}} | ||
|
||
for κ=1:K | ||
if !isempty(idx[κ]) | ||
gpu_call(idx[κ], d[κ], view(A, :, κ), x) do ctx, indices, d_, A_, x_ | ||
k = @linearidx(indices) | ||
l = indices[k] | ||
d_[k] = conj(A_[l]) * x_[l] | ||
return nothing | ||
end | ||
mul!(p[κ], adjoint(plan[κ]), d[κ]) | ||
|
||
gpu_call(p[κ], view(C, κ, :), y) do ctx, p_, C_, y_ | ||
k = @linearidx(p_) | ||
y_[k] += conj(C_[k]) * p_[k] | ||
return nothing | ||
end | ||
end | ||
end | ||
|
||
return | ||
end |
13 changes: 13 additions & 0 deletions
13
MRIOperators/ext/MRIOperatorsGPUArraysExt/MRIOperatorsGPUArraysExt.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module MRIOperatorsGPUArraysExt | ||
|
||
using MRIOperators, GPUArrays, MRIOperators.FFTW, MRIOperators.LinearAlgebra | ||
|
||
include("ExplicitOp.jl") | ||
include("Shutter.jl") | ||
include("SensitivityOp.jl") | ||
include("FieldmapNFFTOp.jl") | ||
|
||
MRIOperators.fftParams(::Type{<:AbstractGPUArray}) = (;) | ||
|
||
|
||
end # module |
Oops, something went wrong.
a37d0ac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator release subdir=MRIBase
a37d0ac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error while trying to register: Action not recognized: release
a37d0ac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register subdir=MRIBase
a37d0ac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/113065
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:
a37d0ac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register subdir=MRIOperators
a37d0ac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/113066
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:
a37d0ac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
a37d0ac
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/113070
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: