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

[NDTensorsCUDAExt] Fix QR-based SVD for some rectangular matrices #1229

Merged
merged 9 commits into from
Nov 2, 2023
30 changes: 28 additions & 2 deletions NDTensors/ext/NDTensorsCUDAExt/linearalgebra.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
function NDTensors.svd_catch_error(A::CuMatrix; alg="JacobiAlgorithm")
function NDTensors.svd_catch_error(A::CuMatrix; alg::String="JacobiAlgorithm")
if alg == "JacobiAlgorithm"
kmp5VT marked this conversation as resolved.
Show resolved Hide resolved
alg = CUDA.CUSOLVER.JacobiAlgorithm()
else
alg = CUDA.CUSOLVER.QRAlgorithm()
end
return NDTensors.svd_catch_error(A, alg)
end

function NDTensors.svd_catch_error(A::CuMatrix, ::CUDA.CUSOLVER.JacobiAlgorithm)
USV = try
svd(expose(A); alg=alg)
svd(A; alg=CUDA.CUSOLVER.JacobiAlgorithm())
catch
return nothing
end
return USV
end

function NDTensors.svd_catch_error(A::CuMatrix, ::CUDA.CUSOLVER.QRAlgorithm)
s = size(A)
if s[1] < s[2]
At = copy(Adjoint(A))

USV = try
svd(At; alg=CUDA.CUSOLVER.QRAlgorithm())
catch
return nothing
end
MV, MS, MU = USV
USV = SVD(copy(MU), MS, Adjoint(MV))
else
kmp5VT marked this conversation as resolved.
Show resolved Hide resolved
USV = try
svd(A; alg=CUDA.CUSOLVER.QRAlgorithm())
catch
return nothing
end
end
return USV
end
Loading