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

Fix block_gmres on GPUs #914

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/block_gmres.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,11 @@ kwargs_block_gmres = (:M, :N, :ldiv, :restart, :reorthogonalization, :atol, :rto

# Initial Γ and V₁
copyto!(V[1], R₀)
householder!(V[1], Z[1], τ[1])
if C isa Matrix
householder!(V[1], Z[1], τ[1])
else
householder!(V[1], Z[1], τ[1], solver.tmp)
end

npass = npass + 1
inner_iter = 0
Expand Down Expand Up @@ -236,7 +240,11 @@ kwargs_block_gmres = (:M, :N, :ldiv, :restart, :reorthogonalization, :atol, :rto
end

# Vₖ₊₁ and Ψₖ₊₁.ₖ are stored in Q and C.
householder!(Q, C, τ[inner_iter])
if C isa Matrix
householder!(Q, C, τ[inner_iter])
else
householder!(Q, C, τ[inner_iter], solver.tmp)
end

# Update the QR factorization of Hₖ₊₁.ₖ.
# Apply previous Householder reflections Ωᵢ.
Expand All @@ -251,7 +259,11 @@ kwargs_block_gmres = (:M, :N, :ldiv, :restart, :reorthogonalization, :atol, :rto
# Compute and apply current Householder reflection Ωₖ.
H[inner_iter][1:p,:] .= R[nr+inner_iter]
H[inner_iter][p+1:2p,:] .= C
householder!(H[inner_iter], R[nr+inner_iter], τ[inner_iter], compact=true)
if C isa Matrix
householder!(H[inner_iter], R[nr+inner_iter], τ[inner_iter], compact=true)
else
householder!(H[inner_iter], R[nr+inner_iter], τ[inner_iter], solver.tmp, compact=true)
end

# Update Zₖ = (Qₖ)ᴴΓE₁ = (Λ₁, ..., Λₖ, Λbarₖ₊₁)
D1 .= Z[inner_iter]
Expand Down
4 changes: 3 additions & 1 deletion src/block_krylov_solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mutable struct BlockGmresSolver{T,FC,SV,SM} <: BlockKrylovSolver{T,FC,SV,SM}
R :: Vector{SM}
H :: Vector{SM}
τ :: Vector{SV}
tmp :: SM
warm_start :: Bool
stats :: SimpleStats{T}
end
Expand All @@ -55,8 +56,9 @@ function BlockGmresSolver(m, n, p, memory, SV, SM)
R = SM[SM(undef, p, p) for i = 1 : div(memory * (memory+1), 2)]
H = SM[SM(undef, 2p, p) for i = 1 : memory]
τ = SV[SV(undef, p) for i = 1 : memory]
tmp = C isa Matrix ? SM(undef, 0, 0) : SM(undef, p, p)
stats = SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown")
solver = BlockGmresSolver{T,FC,SV,SM}(m, n, p, ΔX, X, W, P, Q, C, D, V, Z, R, H, τ, false, stats)
solver = BlockGmresSolver{T,FC,SV,SM}(m, n, p, ΔX, X, W, P, Q, C, D, V, Z, R, H, τ, tmp, false, stats)
return solver
end

Expand Down
10 changes: 10 additions & 0 deletions src/block_krylov_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ function householder(A::AbstractMatrix{FC}; compact::Bool=false) where FC <: Flo
householder!(Q, R, τ; compact)
end

function householder!(Q::AbstractMatrix{FC}, R::AbstractMatrix{FC}, τ::AbstractVector{FC}, tmp::AbstractMatrix{FC}; compact::Bool=false) where FC <: FloatOrComplex
n, k = size(Q)
kfill!(R, zero(FC))
kgeqrf!(Q, τ)
copyto!(tmp, view(Q, 1:k, 1:k))
copy_triangle(tmp, R, k)
!compact && korgqr!(Q, τ)
return Q, R
end

function householder!(Q::AbstractMatrix{FC}, R::AbstractMatrix{FC}, τ::AbstractVector{FC}; compact::Bool=false) where FC <: FloatOrComplex
n, k = size(Q)
kfill!(R, zero(FC))
Expand Down
Loading