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

[CUSOLVER] Add generic routines #2074

Merged
merged 3 commits into from
Oct 17, 2023
Merged
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
3 changes: 3 additions & 0 deletions lib/cusolver/CUSOLVER.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ using ..CUSPARSE: cusparseMatDescr_t

using CEnum: @cenum

using LinearAlgebra
using LinearAlgebra: BlasFloat

export has_cusolvermg

Expand All @@ -35,6 +37,7 @@ include("error.jl")
include("base.jl")
include("sparse.jl")
include("dense.jl")
include("dense_generic.jl")
include("multigpu.jl")

# high-level integrations
Expand Down
12 changes: 12 additions & 0 deletions lib/cusolver/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,15 @@ function Base.convert(::Type{cusolverEigMode_t}, jobz::Char)
throw(ArgumentError("Unknown eigenvalue solver mode $jobz."))
end
end

function Base.convert(::Type{cusolverEigRange_t}, range::Char)
if range == 'A'
CUSOLVER_EIG_RANGE_ALL
elseif range == 'V'
CUSOLVER_EIG_RANGE_V
elseif range == 'I'
CUSOLVER_EIG_RANGE_I
else
throw(ArgumentError("Unknown eigenvalue solver range $range."))
end
end
23 changes: 14 additions & 9 deletions lib/cusolver/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ for (bname, fname,elty) in ((:cusolverDnSsytrf_bufferSize, :cusolverDnSsytrf, :F
(:cusolverDnZsytrf_bufferSize, :cusolverDnZsytrf, :ComplexF64))
@eval begin
function sytrf!(uplo::Char,
A::StridedCuMatrix{$elty})
A::StridedCuMatrix{$elty},
ipiv::CuVector{Cint})
chkuplo(uplo)
n = checksquare(A)
lda = max(1, stride(A, 2))
Expand All @@ -197,7 +198,6 @@ for (bname, fname,elty) in ((:cusolverDnSsytrf_bufferSize, :cusolverDnSsytrf, :F
return out[]
end

ipiv = CuArray{Cint}(undef, n)
devinfo = CuArray{Cint}(undef, 1)
with_workspace($elty, bufferSize) do buffer
$fname(dense_handle(), uplo, n, A, lda, ipiv, buffer, length(buffer), devinfo)
Expand All @@ -209,6 +209,12 @@ for (bname, fname,elty) in ((:cusolverDnSsytrf_bufferSize, :cusolverDnSsytrf, :F

A, ipiv, info
end

function sytrf!(uplo::Char, A::StridedCuMatrix{$elty})
n = checksquare(A)
ipiv = CuArray{Cint}(undef, n)
sytrf!(uplo, A, ipiv)
end
end
end

Expand Down Expand Up @@ -258,9 +264,9 @@ for (bname, fname, elty) in ((:cusolverDnSormqr_bufferSize, :cusolverDnSormqr, :
@eval begin
function ormqr!(side::Char,
trans::Char,
A::CuMatrix{$elty},
A::StridedCuMatrix{$elty},
tau::CuVector{$elty},
C::CuVecOrMat{$elty})
C::StridedCuVecOrMat{$elty})

# Support transa = 'C' for real matrices
trans = $elty <: Real && trans == 'C' ? 'T' : trans
Expand Down Expand Up @@ -387,11 +393,8 @@ for (bname, fname, elty, relty) in ((:cusolverDnSgesvd_bufferSize, :cusolverDnSg
jobvt::Char,
A::StridedCuMatrix{$elty})
m, n = size(A)
if m < n
throw(ArgumentError("CUSOLVER's gesvd currently requires m >= n"))
# XXX: is this documented?
end
lda = max(1, stride(A, 2))
(m < n) && throw(ArgumentError("CUSOLVER's gesvd requires m ≥ n"))
lda = max(1, stride(A, 2))

U = if jobu === 'A'
CuArray{$elty}(undef, m, m)
Expand Down Expand Up @@ -900,11 +903,13 @@ for elty in (:Float32, :Float64, :ComplexF32, :ComplexF64)
LinearAlgebra.LAPACK.geqrf!(A::StridedCuMatrix{$elty}) = CUSOLVER.geqrf!(A)
LinearAlgebra.LAPACK.geqrf!(A::StridedCuMatrix{$elty}, tau::CuVector{$elty}) = CUSOLVER.geqrf!(A, tau)
LinearAlgebra.LAPACK.sytrf!(uplo::Char, A::StridedCuMatrix{$elty}) = sytrf!(uplo, A)
LinearAlgebra.LAPACK.sytrf!(uplo::Char, A::StridedCuMatrix{$elty}, ipiv::CuVector{Cint}) = CUSOLVER.sytrf!(uplo, A, ipiv)
LinearAlgebra.LAPACK.getrs!(trans::Char, A::StridedCuMatrix{$elty}, ipiv::CuVector{Cint}, B::StridedCuVecOrMat{$elty}) = CUSOLVER.getrs!(trans, A, ipiv, B)
LinearAlgebra.LAPACK.ormqr!(side::Char, trans::Char, A::CuMatrix{$elty}, tau::CuVector{$elty}, C::CuVecOrMat{$elty}) = CUSOLVER.ormqr!(side, trans, A, tau, C)
LinearAlgebra.LAPACK.orgqr!(A::StridedCuMatrix{$elty}, tau::CuVector{$elty}) = CUSOLVER.orgqr!(A, tau)
LinearAlgebra.LAPACK.gebrd!(A::StridedCuMatrix{$elty}) = CUSOLVER.gebrd!(A)
LinearAlgebra.LAPACK.gesvd!(jobu::Char, jobvt::Char, A::StridedCuMatrix{$elty}) = CUSOLVER.gesvd!(jobu, jobvt, A)
LinearAlgebra.LAPACK.syev!(jobz::Char, uplo::Char, A::StridedCuMatrix{$elty}) = CUSOLVER.syevd!(jobz, uplo, A)
end
end

Expand Down
Loading