-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NDTensorsCUDAExt] Fix QR-based SVD for some rectangular matrices (#1229
- Loading branch information
Showing
5 changed files
with
41 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NDTensors.default_svd_alg(::Type{<:CuArray}, a) = "qr_algorithm" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,43 @@ | ||
function NDTensors.svd_catch_error(A::CuMatrix; alg="JacobiAlgorithm") | ||
if alg == "JacobiAlgorithm" | ||
function NDTensors.svd_catch_error(A::CuMatrix; alg::String="jacobi_algorithm") | ||
if alg == "jacobi_algorithm" | ||
alg = CUDA.CUSOLVER.JacobiAlgorithm() | ||
else | ||
elseif alg == "qr_algorithm" | ||
alg = CUDA.CUSOLVER.QRAlgorithm() | ||
else | ||
error( | ||
"svd algorithm $alg is not currently supported. Please see the documentation for currently supported algorithms.", | ||
) | ||
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 = (MU, MS, MV) | ||
else | ||
USV = try | ||
svd(A; alg=CUDA.CUSOLVER.QRAlgorithm()) | ||
catch | ||
return nothing | ||
end | ||
end | ||
return USV | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters