cuSOLVER

cuSOLVER.jl offers NVIDIA's dense and sparse solvers at three levels:

  • LinearAlgebra functions like \, lu, qr, cholesky, eigen and svd work on CuArrays, and should be the first choice. The algorithm used by svd can be chosen with the types below.
  • The functions documented below wrap individual cuSOLVER routines, for when more control is needed. They are named after the LAPACK routine they compute, and many also extend the corresponding function in LinearAlgebra.LAPACK.
  • The generated bindings in libcusolver.jl follow NVIDIA's C API, and change with the CUDA toolkit. Use them together with dense_handle and CuSolverParameters.

The wrappers follow LinearAlgebra.LAPACK's conventions. Character arguments select the variant to compute (uplo, trans, jobz, ...), and arguments are overwritten in place. Errors in the arguments are thrown, while the info value of a factorization is returned, so that you can decide what a singular or indefinite matrix means.

Checking the info value copies it from the GPU, which waits for all work queued on the stream. Wrappers that only check it, and don't return it, take a check keyword: check=false skips the copy, and the failures that info reports go unreported. When the keyword is omitted, its value comes from check_info!, which changes it for a block of code, and defaults to true.

cuSOLVER offers many routines twice, in its legacy API and its 64-bit generic API. The wrappers use the generic API when the installed cuSOLVER provides it, and the legacy API otherwise. getrf! and getrs! choose by the type of the pivot vector instead: 32-bit pivots use the legacy API, 64-bit pivots the generic one.

Public

cuSOLVER.ApproximateAlgorithm — Type
QRAlgorithm()
JacobiAlgorithm()
ApproximateAlgorithm()

Algorithms for svd(A; alg), svd!(A; alg), svdvals(A; alg) and svdvals!(A; alg) with a CuMatrix or a 3-D CuArray holding a batch of matrices:

  • QRAlgorithm(), the default for a matrix, uses QR iteration (gesvd!). It does not support batches.
  • JacobiAlgorithm(), the default for a batch, uses the one-sided Jacobi method (gesvdj! and, for a batch, gesvdjBatched!). Matrices too large for gesvdj! use gesvd! instead.
  • ApproximateAlgorithm() uses gesvdaStridedBatched! and only supports batches.

For a single matrix, QR iteration is faster than cuSOLVER's Jacobi method in double precision, and its singular vectors are closer to orthonormal in every precision. In single precision, the Jacobi method can be faster at computing singular vectors, mainly of tall or wide matrices. On some graded matrices, whose columns differ in scale by orders of magnitude, it also determines the smallest singular values to a higher relative accuracy.

For a batch, the result is a CuSVDBatched.

source
cuSOLVER.CuSVDBatched — Type
CuSVDBatched

The singular value decompositions of a batch of matrices, returned by svd(A) for a 3-D CuArray A. The fields U and V are 3-D arrays and S is a matrix, holding the factors of each matrix A[:, :, i] in U[:, :, i], S[:, i] and V[:, :, i]. Destructures into U, S, V.

source
cuSOLVER.CuSolverParameters — Type
CuSolverParameters()

Create the options object (cusolverDnParams_t) that the routines of cuSOLVER's generic API (cusolverDnX* in the C API) take. It converts to a cusolverDnParams_t and is destroyed when it is garbage collected. Requires cuSOLVER 11.

source
cuSOLVER.JacobiAlgorithm — Type
QRAlgorithm()
JacobiAlgorithm()
ApproximateAlgorithm()

Algorithms for svd(A; alg), svd!(A; alg), svdvals(A; alg) and svdvals!(A; alg) with a CuMatrix or a 3-D CuArray holding a batch of matrices:

  • QRAlgorithm(), the default for a matrix, uses QR iteration (gesvd!). It does not support batches.
  • JacobiAlgorithm(), the default for a batch, uses the one-sided Jacobi method (gesvdj! and, for a batch, gesvdjBatched!). Matrices too large for gesvdj! use gesvd! instead.
  • ApproximateAlgorithm() uses gesvdaStridedBatched! and only supports batches.

For a single matrix, QR iteration is faster than cuSOLVER's Jacobi method in double precision, and its singular vectors are closer to orthonormal in every precision. In single precision, the Jacobi method can be faster at computing singular vectors, mainly of tall or wide matrices. On some graded matrices, whose columns differ in scale by orders of magnitude, it also determines the smallest singular values to a higher relative accuracy.

For a batch, the result is a CuSVDBatched.

source
cuSOLVER.QRAlgorithm — Type
QRAlgorithm()
JacobiAlgorithm()
ApproximateAlgorithm()

Algorithms for svd(A; alg), svd!(A; alg), svdvals(A; alg) and svdvals!(A; alg) with a CuMatrix or a 3-D CuArray holding a batch of matrices:

  • QRAlgorithm(), the default for a matrix, uses QR iteration (gesvd!). It does not support batches.
  • JacobiAlgorithm(), the default for a batch, uses the one-sided Jacobi method (gesvdj! and, for a batch, gesvdjBatched!). Matrices too large for gesvdj! use gesvd! instead.
  • ApproximateAlgorithm() uses gesvdaStridedBatched! and only supports batches.

For a single matrix, QR iteration is faster than cuSOLVER's Jacobi method in double precision, and its singular vectors are closer to orthonormal in every precision. In single precision, the Jacobi method can be faster at computing singular vectors, mainly of tall or wide matrices. On some graded matrices, whose columns differ in scale by orders of magnitude, it also determines the smallest singular values to a higher relative accuracy.

For a batch, the result is a CuSVDBatched.

source
cuSOLVER.check_info! — Method
check_info!(f, enabled::Bool)

Run f with the wrappers' check of the info value enabled or disabled.

After a call, most wrappers copy the info value that cuSOLVER wrote to GPU memory back to the host, and throw if it reports an invalid argument or, for some routines, a failure to converge. That copy waits for all work queued on the stream. Code that queues many solver calls can skip it with check_info!(false) do ... end, which sets the default of the wrappers' check keyword, so it also covers LinearAlgebra functions like qr that call the wrappers. A call that passes check explicitly is not affected.

Without the check, a failure that cuSOLVER reports through info goes unreported, and the outputs may be invalid. Arguments are still validated before the call. Wrappers that return info to the caller, like potrf! and getrf!, always read it. Some routines, among which gesvd!, gesvdj! and syevd!, wait for queued work inside cuSOLVER, so they wait with or without the check.

The setting applies to the tasks that f runs and spawns, but not to tasks that were started outside of it.

Note

On Julia 1.10, Logging.with_logger hides the setting from the code it runs. Use ScopedValues.with_logger instead.

source
cuSOLVER.dense_handle — Method
cuSOLVER.dense_handle()

The cuSOLVER dense handle of the current task, for its active context and stream, for calling the C API of cuSOLVER (cuSOLVER.cusolverDn*) directly. It converts to a cusolverDnHandle_t. The handle is borrowed: don't destroy it, or change its stream or other settings. Its fields are not part of the API.

source
cuSOLVER.enable_logging — Function
cuSOLVER.enable_logging(enable::Bool=true)

Forward log messages from cuSOLVER to Julia's logging system. API and kernel traces are reported at Debug level, performance hints at Info level, and problems at Error level. Starting Julia with JULIA_DEBUG=cuSOLVER enables this automatically, and also shows the Debug-level messages.

If the installed shared library does not export the logging API, enabling emits a warning. Set CUSOLVERDN_LOG_LEVEL before starting Julia to use cuSOLVER's own output instead.

source
cuSOLVER.gebrd! — Function
gebrd!(A; check=true) -> A, D, E, tauq, taup

Reduce A to bidiagonal form B = Qᴴ A P in place. The diagonal and off-diagonal of B are returned in D and E; Q and P are stored in A as Householder reflectors with scalar factors tauq and taup.

Wraps cusolverDn<t>gebrd.

source
cuSOLVER.geev! — Method
geev!(jobvl, jobvr, A; check=true) -> W, VL, VR

Compute the eigenvalues W of the square matrix A, which are complex also for real A, and with jobvl and jobvr set to 'V' its left and right eigenvectors ('N' returns CU_NULL in their place). For real A, the eigenvectors are real and stored as LAPACK's geev does: a complex conjugate pair occupies two columns, holding the real and imaginary part of the first vector. A is destroyed.

Wraps cusolverDnXgeev. Requires cuSOLVER 11.7.1 (CUDA 12.6.2).

source
cuSOLVER.geqrf! — Method
geqrf!(A[, tau]; check=true) -> A, tau

Compute the QR factorization of A in place: R in the upper triangle, and Q as Householder reflectors below it with their scalar factors in tau. Use orgqr! to form Q and ormqr! to multiply by it.

Wraps cusolverDnXgeqrf, or cusolverDn<t>geqrf before cuSOLVER 11.

source
cuSOLVER.gesvd! — Method
gesvd!(jobu, jobvt, A; check=true) -> U, S, Vt

Compute the singular value decomposition A = U * Diagonal(S) * Vt of an m×n matrix with m ≥ n, using the QR algorithm. jobu and jobvt select which columns of U and rows of Vt to compute: 'A' for all, 'S' for the first min(m, n), 'O' to overwrite A with them, and 'N' for none. For 'O' and 'N', CU_NULL is returned in their place. A is destroyed. Throws a LAPACKException if the algorithm does not converge.

Wraps cusolverDnXgesvd, or cusolverDn<t>gesvd before cuSOLVER 11.

source
cuSOLVER.gesvdaStridedBatched! — Function
gesvdaStridedBatched!(jobz, A; rank=min(size(A, 1), size(A, 2)), check=true) -> U, S, V

Approximate the rank largest singular values and corresponding singular vectors of each m×n matrix A[:, :, i] of a 3-D array, with m ≥ n. U is m×rank×batch, S is rank×batch and V is n×rank×batch; with jobz = 'N' only S is computed. Throws a LAPACKException if the decomposition fails for one of the matrices, as it does when computing the singular vectors of a matrix whose rank is lower than rank. cuSOLVER only reports this failure from version 11.7.3 (CUDA 12.8); older versions return NaNs.

Wraps cusolverDn<t>gesvdaStridedBatched.

source
cuSOLVER.gesvdj! — Function
gesvdj!(jobz, econ, A; tol=2*sqrt(max(size(A)...))*eps(real(eltype(A))), max_sweeps=100, check=true) -> U, S, V

Compute the singular value decomposition A = U * Diagonal(S) * V' with the Jacobi method, to tolerance tol in at most max_sweeps sweeps. With jobz = 'N' only S is computed. With econ = true, U or V has only min(size(A)...) columns. A is destroyed.

Throws a LAPACKException if the method does not converge within max_sweeps sweeps. A smaller tolerance, such as eps(real(eltype(A))), can determine the small singular values of a graded matrix to a higher relative accuracy, but larger matrices with (numerically) zero singular values can fail to converge to it. Throws an ArgumentError for matrices too large for the 32-bit API; use gesvd! for those.

Wraps cusolverDn<t>gesvdj.

source
cuSOLVER.gesvdjBatched! — Function
gesvdjBatched!(jobz, A; tol=2*sqrt(max(size(A, 1), size(A, 2)))*eps(real(eltype(A))), max_sweeps=100, check=true) -> U, S, V

Compute the singular value decomposition of each matrix A[:, :, i] of a 3-D array, as gesvdj! does. The matrices can be at most 32×32. U, S and V are 3-D and 2-D arrays holding the results for each matrix.

Wraps cusolverDn<t>gesvdjBatched.

source
cuSOLVER.gesvdp! — Method
gesvdp!(jobz, econ, A; check=true) -> U, S, V, err     # jobz = 'V'
gesvdp!(jobz, econ, A; check=true) -> S, err           # jobz = 'N'

Compute the singular value decomposition A = U * Diagonal(S) * V' using the polar decomposition. With econ = true, U and V have min(size(A)...) columns. err is an estimate of the error in the singular values. A is destroyed.

Wraps cusolverDnXgesvdp. Requires cuSOLVER 11.

source
cuSOLVER.gesvdr! — Method
gesvdr!(jobu, jobv, A, k; niters=2, p=2k, check=true) -> U, S, V

Compute a rank-k approximation A ≈ U[:, 1:k] * Diagonal(S[1:k]) * V[:, 1:k]' of A with a randomized algorithm that uses p oversampling vectors and niters power iterations. The singular vectors in U and V are only computed when jobu and jobv are 'S', not when they are 'N'. A is destroyed.

Wraps cusolverDnXgesvdr. Requires cuSOLVER 11.1 (CUDA 11.2).

source
cuSOLVER.getrf! — Method
getrf!(A[, ipiv]) -> A, ipiv, info

Compute the LU factorization of A with partial pivoting in place, storing the pivot indices in ipiv, a CuVector{Int64} or CuVector{Cint} of length min(size(A)...). When ipiv is not given, a CuVector{Cint} is allocated. info > 0 means that U[info, info] is exactly zero.

Wraps cusolverDnXgetrf for 64-bit pivots, and cusolverDn<t>getrf for 32-bit pivots or before cuSOLVER 11.

source
cuSOLVER.getrs! — Method
getrs!(trans, A, ipiv, B; check=true) -> B

Solve op(A) X = B in place in B, where trans selects op ('N', 'T' or 'C'), using the LU factorization A and pivots ipiv computed by getrf!.

Wraps cusolverDnXgetrs for 64-bit pivots, and cusolverDn<t>getrs for 32-bit pivots or before cuSOLVER 11.

source
cuSOLVER.has_cusolvermg — Function
cuSOLVER.has_cusolvermg(show_reason=false) -> Bool

Whether the CUDA toolkit provides cusolverMg, the multi-GPU solver library. With show_reason = true, an error explains why it is missing.

source
cuSOLVER.larft! — Method
larft!(direct, storev, V, tau, T) -> T

Form the triangular factor T of the block reflector H = I - V T Vᴴ of the k elementary reflectors stored in the columns of the n×k matrix V, with scalar factors tau, as LAPACK's larft does. direct is 'F' for H = H(1)⋯H(k) and 'B' for H = H(k)⋯H(1); storev must be 'C'.

Wraps cusolverDnXlarft. Requires cuSOLVER 11.6.

source
cuSOLVER.orgqr! — Function
orgqr!(A, tau; check=true) -> A

Overwrite A with the first size(A, 2) columns of the Q that geqrf! stored in A and tau.

Wraps cusolverDn<t>orgqr (ungqr for complex matrices).

source
cuSOLVER.ormqr! — Function
ormqr!(side, trans, A, tau, C; check=true) -> C

Multiply C in place by Q, Qᵀ or Qᴴ (trans is 'N', 'T' or 'C'; 'T' only for real matrices), from the left (side = 'L') or the right ('R'), where Q is stored in A and tau as computed by geqrf!.

Wraps cusolverDn<t>ormqr (unmqr for complex matrices).

source
cuSOLVER.potrf! — Method
potrf!(uplo, A) -> A, info

Compute the Cholesky factorization of the Hermitian positive definite matrix A in place, in the triangle selected by uplo ('U' or 'L'). info > 0 means that the leading minor of that order is not positive definite.

Wraps cusolverDnXpotrf, or cusolverDn<t>potrf before cuSOLVER 11.

source
cuSOLVER.potrfBatched! — Function
potrfBatched!(uplo, A::Vector{<:CuMatrix}) -> A, info

Compute the Cholesky factorization of each matrix in A, as potrf! does. info[i] > 0 means that the leading minor of that order of A[i] is not positive definite.

Wraps cusolverDn<t>potrfBatched.

source
cuSOLVER.potri! — Function
potri!(uplo, A; check=true) -> A

Invert the Hermitian positive definite matrix whose Cholesky factorization potrf! stored in A, in place, in the triangle selected by uplo.

Wraps cusolverDn<t>potri.

source
cuSOLVER.potrs! — Method
potrs!(uplo, A, B; check=true) -> B

Solve A X = B in place in B, using the Cholesky factorization of A computed by potrf! with the same uplo.

Wraps cusolverDnXpotrs, or cusolverDn<t>potrs before cuSOLVER 11.

source
cuSOLVER.potrsBatched! — Function
potrsBatched!(uplo, A::Vector{<:CuMatrix}, B::Vector{<:CuVecOrMat}; check=true) -> B

Solve A[i] X = B[i] in place in each B[i], using the Cholesky factorizations computed by potrfBatched!. Each B[i] can have only one column.

Wraps cusolverDn<t>potrsBatched.

source
cuSOLVER.syevBatched! — Method
syevBatched!(jobz, uplo, A; check=true) -> W         # jobz = 'N'
syevBatched!(jobz, uplo, A; check=true) -> W, A      # jobz = 'V'

Compute the eigenvalues, and with jobz = 'V' the eigenvectors, of each symmetric or Hermitian matrix A[:, :, i] of a 3-D array, as syevd! does. Column i of W holds the eigenvalues of matrix i.

Wraps cusolverDnXsyevBatched. Requires cuSOLVER 11.7.1.

source
cuSOLVER.syevd! — Method
syevd!(jobz, uplo, A; check=true) -> W         # jobz = 'N'
syevd!(jobz, uplo, A; check=true) -> W, A      # jobz = 'V'

Compute the eigenvalues W, in ascending order, of the symmetric or Hermitian matrix A from the triangle selected by uplo, using a divide-and-conquer algorithm. With jobz = 'V', the eigenvectors overwrite A.

Wraps cusolverDnXsyevd, or cusolverDn<t>syevd/cusolverDn<t>heevd before cuSOLVER 11.

source
cuSOLVER.syevdx! — Method
syevdx!(jobz, range, uplo, A; vl=0.0, vu=Inf, il=1, iu=n, check=true) -> W, m        # jobz = 'N'
syevdx!(jobz, range, uplo, A; vl=0.0, vu=Inf, il=1, iu=n, check=true) -> W, A, m     # jobz = 'V'

Like syevd!, but compute only some of the eigenvalues: all of them with range = 'A', those in the interval (vl, vu] with range = 'V', and the il-th through iu-th with range = 'I'. The first m entries of W, and columns of A, hold the result.

Wraps cusolverDnXsyevdx. Requires cuSOLVER 11.

source
cuSOLVER.syevjBatched! — Function
syevjBatched!(jobz, uplo, A; tol=eps(real(eltype(A))), max_sweeps=100, check=true) -> W         # jobz = 'N'
syevjBatched!(jobz, uplo, A; tol=eps(real(eltype(A))), max_sweeps=100, check=true) -> W, A      # jobz = 'V'

Compute the eigenvalues, and with jobz = 'V' the eigenvectors, of each symmetric or Hermitian matrix A[:, :, i] of a 3-D array with the Jacobi method. The matrices can be at most 32×32. Column i of W holds the eigenvalues of matrix i.

Wraps cusolverDn<t>syevjBatched (heevjBatched for complex matrices).

source
cuSOLVER.sygvd! — Function
sygvd!(itype, jobz, uplo, A, B; check=true) -> W            # jobz = 'N'
sygvd!(itype, jobz, uplo, A, B; check=true) -> W, A, B      # jobz = 'V'

Solve a generalized symmetric-definite eigenproblem. It is A x = λ B x for itype = 1, A B x = λ x for itype = 2 and B A x = λ x for itype = 3, where A is symmetric or Hermitian and B positive definite, reading the triangles selected by uplo. With jobz = 'V' the eigenvectors overwrite A. B is overwritten by its Cholesky factor.

Wraps cusolverDn<t>sygvd (hegvd for complex matrices).

source
cuSOLVER.sygvj! — Function
sygvj!(itype, jobz, uplo, A, B; tol=eps(real(eltype(A))), max_sweeps=100, check=true) -> W[, A, B]

Like sygvd!, but with the Jacobi method.

Wraps cusolverDn<t>sygvj (hegvj for complex matrices).

source
cuSOLVER.sytrf! — Function
sytrf!(uplo, A[, ipiv]) -> A, ipiv, info
sytrf!(uplo, A; pivoting=false) -> A, info

Compute the Bunch-Kaufman factorization A = L D Lᵀ (or U D Uᵀ) of the symmetric matrix A in place, in the triangle selected by uplo, storing the pivots in the CuVector{Cint} ipiv. Also for complex A the factorization is symmetric, not Hermitian. With pivoting=false, no pivoting is done (cuSOLVER 11.7.2 or later). Use sytrs! to solve with the result.

Wraps cusolverDn<t>sytrf.

source
cuSOLVER.sytrs! — Method
sytrs!(uplo, A, [ipiv,] B; check=true) -> B

Solve A X = B in place in B, using the factorization of the symmetric matrix A computed by sytrf! with the same uplo. ipiv is a CuVector{Int64}: convert the pivots sytrf! returns with CuVector{Int64}(ipiv). Leave it out for a factorization computed with pivoting=false.

Wraps cusolverDnXsytrs. Requires cuSOLVER 11.2 (CUDA 11.4).

source
cuSOLVER.trtri! — Method
trtri!(uplo, diag, A; check=true) -> A

Invert the triangular matrix A in place. uplo selects the triangle, and diag is 'U' for a unit diagonal, which is not read, or 'N'.

Wraps cusolverDnXtrtri. Requires cuSOLVER 11.2 (CUDA 11.4).

source
cuSOLVER.version — Method
cuSOLVER.version() -> VersionNumber

The version of the cuSOLVER library in use.

source

Private