Skip to content

Commit

Permalink
Merge pull request #496 from JuliaHealth/update-cis
Browse files Browse the repository at this point in the history
Update to use cis instead of cos + i sin
  • Loading branch information
cncastillo authored Oct 31, 2024
2 parents 2884674 + 894f196 commit d1feda7
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 11 deletions.
1 change: 0 additions & 1 deletion KomaMRICore/ext/KomaAMDGPUExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ KomaMRICore.isfunctional(::ROCBackend) = AMDGPU.functional()
KomaMRICore.set_device!(::ROCBackend, dev_idx::Integer) = AMDGPU.device_id!(dev_idx)
KomaMRICore.set_device!(::ROCBackend, dev::AMDGPU.HIPDevice) = AMDGPU.device!(dev)
KomaMRICore.device_name(::ROCBackend) = AMDGPU.HIP.name(AMDGPU.device())
@inline KomaMRICore._cis(x) = cis(x)

function KomaMRICore._print_devices(::ROCBackend)
devices = [
Expand Down
1 change: 0 additions & 1 deletion KomaMRICore/ext/KomaCUDAExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ KomaMRICore.name(::CUDABackend) = "CUDA"
KomaMRICore.isfunctional(::CUDABackend) = CUDA.functional()
KomaMRICore.set_device!(::CUDABackend, val) = CUDA.device!(val)
KomaMRICore.device_name(::CUDABackend) = CUDA.name(CUDA.device())
@inline KomaMRICore._cis(x) = cis(x)

function KomaMRICore._print_devices(::CUDABackend)
devices = [
Expand Down
1 change: 0 additions & 1 deletion KomaMRICore/ext/KomaMetalExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ KomaMRICore.isfunctional(::MetalBackend) = Metal.functional()
KomaMRICore.set_device!(::MetalBackend, device_index::Integer) = device_index == 1 || @warn "Metal does not support multiple gpu devices. Ignoring the device setting."
KomaMRICore.set_device!(::MetalBackend, dev::Metal.MTLDevice) = Metal.device!(dev)
KomaMRICore.device_name(::MetalBackend) = String(Metal.current_device().name)
@inline KomaMRICore._cis(x) = cis(x)

function KomaMRICore._print_devices(::MetalBackend)
@info "Metal device type: $(KomaMRICore.device_name(MetalBackend()))"
Expand Down
1 change: 0 additions & 1 deletion KomaMRICore/ext/KomaoneAPIExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ KomaMRICore.name(::oneAPIBackend) = "oneAPI"
KomaMRICore.isfunctional(::oneAPIBackend) = oneAPI.functional()
KomaMRICore.set_device!(::oneAPIBackend, val) = oneAPI.device!(val)
KomaMRICore.device_name(::oneAPIBackend) = oneAPI.properties(oneAPI.device()).name
@inline KomaMRICore._cis(x) = cos(x) + im * sin(x)

function KomaMRICore._print_devices(::oneAPIBackend)
devices = [
Expand Down
6 changes: 3 additions & 3 deletions KomaMRICore/src/simulation/SimMethods/Bloch/BlochGPU.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ function run_spin_precession!(
ϕ_ADC = @view pre.ϕ[:,seq_block.ADC_indices]
if seq_block.first_ADC
pre.Mxy[:,1] .= M.xy
pre.Mxy[:,2:end] .= M.xy .* exp.(-seq_block.tp_ADC' ./ p.T2) .* _cis.(ϕ_ADC)
pre.Mxy[:,2:end] .= M.xy .* exp.(-seq_block.tp_ADC' ./ p.T2) .* cis.(ϕ_ADC)
#Reset Spin-State (Magnetization). Only for FlowPath
outflow_spin_reset!(pre.Mxy, seq_block.tp_ADC', p.motion; seq_t=seq.t, add_t0=true)
else
pre.Mxy .= M.xy .* exp.(-seq_block.tp_ADC' ./ p.T2) .* _cis.(ϕ_ADC)
pre.Mxy .= M.xy .* exp.(-seq_block.tp_ADC' ./ p.T2) .* cis.(ϕ_ADC)
#Reset Spin-State (Magnetization). Only for FlowPath
outflow_spin_reset!(pre.Mxy, seq_block.tp_ADC', p.motion; seq_t=seq.t)
end
Expand All @@ -164,7 +164,7 @@ function run_spin_precession!(

#Mxy precession and relaxation, and Mz relaxation
M.z .= M.z .* exp.(-seq_block.dur ./ p.T1) .+ p.ρ .* (T(1) .- exp.(-seq_block.dur ./ p.T1))
M.xy .= M.xy .* exp.(-seq_block.dur ./ p.T2) .* _cis.(pre.ϕ[:,end])
M.xy .= M.xy .* exp.(-seq_block.dur ./ p.T2) .* cis.(pre.ϕ[:,end])

#Reset Spin-State (Magnetization). Only for FlowPath
outflow_spin_reset!(M, seq.t', p.motion; replace_by=p.ρ)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ using KernelAbstractions: @kernel, @Const, @index, @uniform, @groupsize, @localm
@inbounds s_ρ[i_l] = ρ[i_g]

@inbounds for t = 1 : N_Δt
sin_φ = sin(φ[i_g, t]) #TO-DO: use sincos once oneAPI releases version with https://github.com/JuliaGPU/oneAPI.jl/commit/260a4dda0ea223dbf0893de7b4a13d994ae27bd1
cos_φ = cos(φ[i_g, t])
sin_φ, cos_φ = sincos(φ[i_g, t])
s_α_r[i_l] = cos_φ
if (iszero(B[i_g, t]))
s_α_i[i_l] = -(Bz[i_g, t] / (B[i_g, t] + eps(T))) * sin_φ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function run_spin_precession!(
#Mxy precession and relaxation, and Mz relaxation
tp = cumsum(seq.Δt) # t' = t - t0
dur = sum(seq.Δt) # Total length, used for signal relaxation
Mxy = [M.xy M.xy .* exp.(-tp' ./ p.T2) .* (cos.(ϕ) .+ im .* sin.(ϕ))] #This assumes Δw and T2 are constant in time
Mxy = [M.xy M.xy .* exp.(-tp' ./ p.T2) .* cis.(ϕ)] #This assumes Δw and T2 are constant in time
M.xy .= Mxy[:, end]
#Reset Spin-State (Magnetization). Only for FlowPath
outflow_spin_reset!(Mxy, seq.t', p.motion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function run_spin_precession!(
#Mxy precession and relaxation, and Mz relaxation
tp = cumsum(seq.Δt) # t' = t - t0
dur = sum(seq.Δt) # Total length, used for signal relaxation
Mxy = [M.xy M.xy .* exp.(-tp' ./ p.T2) .* (cos.(ϕ) .+ im .* sin.(ϕ))] #This assumes Δw and T2 are constant in time
Mxy = [M.xy M.xy .* exp.(-tp' ./ p.T2) .* cis.(ϕ)] #This assumes Δw and T2 are constant in time
M.xy .= Mxy[:, end]
M.z .= M.z .* exp.(-dur ./ p.T1) .+ p.ρ .* (1 .- exp.(-dur ./ p.T1))
#Reset Spin-State (Magnetization). Only for FlowPath
Expand Down

0 comments on commit d1feda7

Please sign in to comment.