-
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.
Add logic to fix CUDA qr with rectangular matrices
- Loading branch information
Showing
1 changed file
with
28 additions
and
2 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
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" | ||
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)) | ||
|
||
Check warning on line 23 in NDTensors/ext/NDTensorsCUDAExt/linearalgebra.jl GitHub Actions / format
|
||
USV = try | ||
svd(At; alg=CUDA.CUSOLVER.QRAlgorithm()) | ||
catch | ||
return nothing | ||
end | ||
MV ,MS, MU = USV; | ||
Check warning on line 29 in NDTensors/ext/NDTensorsCUDAExt/linearalgebra.jl GitHub Actions / format
|
||
USV = SVD(copy(MU), MS, Adjoint(MV)) | ||
else | ||
USV = try | ||
Check warning on line 32 in NDTensors/ext/NDTensorsCUDAExt/linearalgebra.jl GitHub Actions / format
|
||
svd(A; alg=CUDA.CUSOLVER.QRAlgorithm()) | ||
catch | ||
return nothing | ||
end | ||
end | ||
return USV | ||
end | ||
Check warning on line 39 in NDTensors/ext/NDTensorsCUDAExt/linearalgebra.jl GitHub Actions / format
|