Skip to content

Commit 1d142bf

Browse files
Katharine Hyattkshyatt
authored andcommitted
A few more fixes for Bisection
1 parent 2a6b821 commit 1d142bf

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

‎ext/MatrixAlgebraKitAMDGPUExt/MatrixAlgebraKitAMDGPUExt.jl‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,13 @@ MatrixAlgebraKit.default_driver(::Type{TA}) where {TA <: StridedROCArray{<:BlasF
2020
MatrixAlgebraKit.default_driver(::Type{TA}) where {TA <: AbstractVector{<:StridedROCMatrix{<:BlasFloat}}} = ROCSOLVER()
2121

2222
function MatrixAlgebraKit.default_svd_algorithm(::Type{T}; kwargs...) where {T <: StridedROCMatrix{<:BlasFloat}}
23-
return Bisection(; kwargs...)
23+
return QRIteration(; kwargs...)
2424
end
2525
function MatrixAlgebraKit.default_svd_algorithm(::Type{T}; kwargs...) where {T <: StridedROCArray{<:BlasFloat, 3}}
26-
return Bisection(; kwargs...)
26+
return QRIteration(; kwargs...)
2727
end
2828
function MatrixAlgebraKit.default_svd_algorithm(::Type{T}; kwargs...) where {T <: AbstractVector{<:StridedROCMatrix{<:BlasFloat}}}
29-
return Bisection(; kwargs...)
30-
end
31-
32-
for f in (:svd_full!, :batched_svd_full!)
33-
@eval function MatrixAlgebraKit.default_algorithm(
34-
::typeof(MatrixAlgebraKit.$f), ::Type{T}; kwargs...
35-
) where {T <: Union{StridedROCMatrix{<:BlasFloat}, StridedROCArray{<:BlasFloat, 3}, AbstractVector{<:StridedROCMatrix{<:BlasFloat}}}}
36-
return Bisection(; kwargs...)
37-
end
29+
return QRIteration(; kwargs...)
3830
end
3931
function MatrixAlgebraKit.default_eigh_algorithm(::Type{T}; kwargs...) where {T <: StridedROCVecOrMat{<:BlasFloat}}
4032
return DivideAndConquer(; kwargs...)

‎ext/MatrixAlgebraKitAMDGPUExt/yarocsolver.jl‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,26 @@ function _gesvdx_jobs(U, Vᴴ, m::Integer, n::Integer, maxnsv::Integer)
786786
return jobu, jobvt
787787
end
788788

789+
"""
790+
_gesvdx_zero_unconverged!(S, nsv)
791+
792+
Zero the entries of `S` that `gesvdx` did not write.
793+
"""
794+
function _gesvdx_zero_unconverged!(S::StridedROCVector, nsv::ROCVector{Cint})
795+
nv = @allowscalar Int(nsv[1])
796+
nv < length(S) && fill!(view(S, (nv + 1):length(S)), zero(eltype(S)))
797+
return S
798+
end
799+
function _gesvdx_zero_unconverged!(S::StridedROCMatrix, nsv::ROCVector{Cint})
800+
minmn = size(S, 1)
801+
nvs = Array(nsv)
802+
all(==(minmn), nvs) && return S # nothing omitted, skip the per-batch fills
803+
for (b, nv) in pairs(nvs)
804+
nv < minmn && fill!(view(S, (nv + 1):minmn, b), zero(eltype(S)))
805+
end
806+
return S
807+
end
808+
789809
# Wrapper for SVD via Bisection
790810
for (fname, elty, relty) in
791811
(
@@ -826,9 +846,7 @@ for (fname, elty, relty) in
826846
)
827847
info = @allowscalar dev_info[1]
828848
rocSOLVER.chkargsok(BlasInt(info))
829-
# Zero the entries of `S` that `gesvdx` did not write.
830-
nv = @allowscalar Int(nsv[1])
831-
nv < length(S) && fill!(view(S, (nv + 1):length(S)), zero(eltype(S)))
849+
_gesvdx_zero_unconverged!(S, nsv)
832850

833851
AMDGPU.unsafe_free!(nsv)
834852
AMDGPU.unsafe_free!(ifail)
@@ -888,6 +906,7 @@ for (fname, elty, relty) in
888906
AMDGPU.unsafe_free!(pA)
889907

890908
rocSOLVER.chkargsok.(BlasInt.(collect(dev_info)))
909+
_gesvdx_zero_unconverged!(S, nsv)
891910

892911
AMDGPU.unsafe_free!(nsv)
893912
AMDGPU.unsafe_free!(ifail)
@@ -942,6 +961,7 @@ for (fname, elty, relty) in
942961
)
943962

944963
rocSOLVER.chkargsok.(BlasInt.(collect(dev_info)))
964+
_gesvdx_zero_unconverged!(S, nsv)
945965

946966
AMDGPU.unsafe_free!(nsv)
947967
AMDGPU.unsafe_free!(ifail)

0 commit comments

Comments
 (0)