Skip to content
Open
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
6 changes: 5 additions & 1 deletion ext/MatrixAlgebraKitCUDAExt/MatrixAlgebraKitCUDAExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using MatrixAlgebraKit: CUSOLVER, LQViaTransposedQR, TruncationByValue, Abstract
using MatrixAlgebraKit: default_qr_algorithm, default_lq_algorithm, default_svd_algorithm, default_eig_algorithm, default_eigh_algorithm
import MatrixAlgebraKit: geqrf!, ungqr!, unmqr!, gesvd!, gesvdp!, gesvdr!, gesvdj!
import MatrixAlgebraKit: heevj!, heevd!, geev!
import MatrixAlgebraKit: _gpu_Xgesvdr!, _sylvester, svd_rank, svd_pullback!, eigh_pullback!
import MatrixAlgebraKit: _gpu_Xgesvdr!, _sylvester, svd_rank, svd_pullback!, eigh_pullback!, eig_pullback!
using CUDA, CUDA.cuBLAS
using CUDA: i32
using LinearAlgebra
Expand Down Expand Up @@ -209,4 +209,8 @@ function eigh_pullback!(ΔA::AnyCuMatrix, A, DV, ΔDV, ind::AnyCuVector; kwargs.
return eigh_pullback!(ΔA, A, DV, ΔDV, collect(ind); kwargs...)
end

function eig_pullback!(ΔA::AnyCuMatrix, A, DV, ΔDV, ind::AnyCuVector; kwargs...)
return eig_pullback!(ΔA, A, DV, ΔDV, collect(ind); kwargs...)
end

end
2 changes: 1 addition & 1 deletion src/MatrixAlgebraKit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using LinearAlgebra: norm # TODO: eleminate if we use VectorInterface.jl?
using LinearAlgebra: mul!, rmul!, lmul!, adjoint!, rdiv!, ldiv!
using LinearAlgebra: sylvester, lu!, diagm
using LinearAlgebra: isposdef, issymmetric
using LinearAlgebra: Diagonal, diag, diagind, isdiag
using LinearAlgebra: Diagonal, Hermitian, diag, diagind, isdiag
using LinearAlgebra: UpperTriangular, LowerTriangular
using LinearAlgebra: BlasFloat, BlasReal, BlasComplex, BlasInt

Expand Down
7 changes: 4 additions & 3 deletions src/pullbacks/eig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function check_and_prepare_eig_cotangents(
bc = Base.broadcasted(transpose(D), D, VᴴΔV₁) do d₁, d₂, v
return abs(d₁ - d₂) < degeneracy_atol ? v : zero(v)
end
Δgauge = norm(bc, Inf)
Δgauge = maximum(abs, bc; init = abs(zero(eltype(D))))

Δgauge ≤ gauge_atol ||
@warn "`eig` cotangents sensitive to gauge choice: (|Δgauge| = $Δgauge)"
Expand All @@ -41,7 +41,8 @@ function check_and_prepare_eig_cotangents(
if !iszerotangent(ΔDmat)
ΔD = diagview(ΔDmat)
length(indD) == length(ΔD) || throw(DimensionMismatch())
view(diagview(VᴴAΔV), indD) .+= ΔD
# needed to avoid GPUCompiler errors
VᴴAΔV[diagind(VᴴAΔV)[indD]] .+= ΔD
else
ΔD = nothing
end
Expand Down Expand Up @@ -243,7 +244,7 @@ function remove_eig_gauge_dependence!(
Ddiag = diagview(D)
gaugepart = V' * ΔV
gaugepart[abs.(transpose(Ddiag) .- Ddiag) .>= degeneracy_atol] .= 0
ViG = V / LinearAlgebra.cholesky!(V' * V)
ViG = V / LinearAlgebra.cholesky!(Hermitian(V' * V))
mul!(ΔV, ViG, gaugepart, -1, 1)
return ΔV
end
7 changes: 6 additions & 1 deletion test/mooncake/eig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ is_buildkite = get(ENV, "BUILDKITE", "false") == "true"

m = 19
for T in (BLASFloats..., GenericFloats...)
TestSuite.seed_rng!(1234)
TestSuite.seed_rng!(12345)
if !is_buildkite
TestSuite.test_mooncake_eig(T, (m, m); atol = m * m * TestSuite.precision(T), rtol = m * m * TestSuite.precision(T))
AT = Diagonal{T, Vector{T}}
TestSuite.test_mooncake_eig(AT, (m, m); atol = m * m * TestSuite.precision(T), rtol = m * m * TestSuite.precision(T))
end
if T ∈ BLASFloats && CUDA.functional()
TestSuite.test_mooncake_eig(CuMatrix{T}, (m, m); atol = m * m * TestSuite.precision(T), rtol = m * m * TestSuite.precision(T))
AT = Diagonal{T, CuVector{T}}
TestSuite.test_mooncake_eig(AT, m; atol = m * m * TestSuite.precision(T), rtol = m * m * TestSuite.precision(T))
end
end
Loading