cuBLAS

cuBLAS.jl offers NVIDIA's dense linear algebra library at three levels:

  • LinearAlgebra functions like *, mul!, dot, norm, axpy! and ldiv! with triangular matrices work on CuArrays, and should be the first choice.
  • The functions documented below wrap individual cuBLAS routines, for when more control is needed, or for operations that LinearAlgebra does not have, like batched products and factorizations. They are named after the BLAS routine they compute; the routines of cuBLASXt, which distribute large products over several GPUs and accept host memory, have an xt_ prefix.
  • The generated bindings in libcublas.jl and libcublasLt.jl follow NVIDIA's C API, and change with the CUDA toolkit. Use those in libcublas.jl together with handle; cuBLASLt needs its own handle, created with cublasLtCreate.

The wrappers follow LinearAlgebra.BLAS's conventions. Character arguments select the variant to compute (trans, uplo, side, diag), functions ending in ! overwrite their output argument, and the functions without ! allocate it. Unlike LinearAlgebra.BLAS, the level-1 functions take the number of elements first and read every array with its own stride, and some can write their result to a device-side scalar to avoid synchronizing. cuBLAS chooses between its 32-bit and 64-bit entry points automatically.

Public

cuBLAS.asum — Function
asum(n, x) -> real(T)
asum(n, x, result) -> result

The sum of the absolute values of the first n elements of x (of the real and imaginary parts for complex x). With a device-side result, the sum is written there without synchronizing. Wraps cublas<t>asum.

source
cuBLAS.axpby! — Function
axpby!(n, alpha, x, beta, y) -> y

Compute y = alpha * x + beta * y for the first n elements of x and y, with cublas<t>scal and cublas<t>axpy.

source
cuBLAS.axpy! — Function
axpy!(n, alpha, x, y) -> y

Compute y = alpha * x + y for the first n elements of x and y. Wraps cublas<t>axpy.

source
cuBLAS.copy! — Function
copy!(n, x, y) -> y

Copy the first n elements of x to y. Wraps cublas<t>copy; Float16 and ComplexF16 arrays, which cuBLAS can't copy, are copied by a kernel.

source
cuBLAS.dgmm! — Function
dgmm!(mode, A, X, C) -> C

Compute C = A * Diagonal(X) (mode = 'R') or C = Diagonal(X) * A (mode = 'L'). Wraps cublas<t>dgmm.

source
cuBLAS.dot — Function
dot(n, x, y) -> T

The dot product of the first n elements of the real vectors x and y. Wraps cublas<t>dot.

source
cuBLAS.dotc — Function
dotc(n, x, y) -> T

The dot product of the first n elements of the complex vectors x and y, conjugating x. Wraps cublas<t>dotc.

source
cuBLAS.dotu — Function
dotu(n, x, y) -> T

The dot product of the first n elements of the complex vectors x and y, without conjugating either. Wraps cublas<t>dotu.

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

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

cuBLASLt messages are only forwarded on CUDA 11 or later; older libraries do not export the cuBLASLt logging API.

source
cuBLAS.functional — Method
cuBLAS.functional() -> Bool

Whether cuBLAS was loaded and initialized successfully.

source
cuBLAS.gbmv — Function
gbmv(trans, m, kl, ku[, alpha], A, x) -> y

Compute alpha * op(A) * x for a band matrix. See gbmv!.

source
cuBLAS.gbmv! — Function
gbmv!(trans, m, kl, ku, alpha, A, x, beta, y) -> y

Compute y = alpha * op(A) * x + beta * y for the m×n band matrix A with kl subdiagonals and ku superdiagonals, stored in LAPACK's band format. Wraps cublas<t>gbmv.

source
cuBLAS.geam — Function
geam(transa, transb, alpha, A, beta, B) -> C
geam(transa, transb, A, B) -> C

Compute alpha * op(A) + beta * op(B), with alpha and beta one by default. See geam!.

source
cuBLAS.geam! — Function
geam!(transa, transb, alpha, A, beta, B, C) -> C

Compute C = alpha * op(A) + beta * op(B). Wraps cublas<t>geam.

source
cuBLAS.gels_batched! — Function
gels_batched!(trans, A, C) -> A, C, info

Solve the overdetermined least-squares problems min ‖C[i] - A[i] * X‖ in place, for each m×n matrix A[i] with m ≥ n and full rank; X overwrites the first n rows of C[i]. Only trans = 'N' is supported by cuBLAS. info[i] > 0 means that A[i] is rank deficient. Wraps cublas<t>gelsBatched.

source
cuBLAS.gemm — Function
gemm(transA, transB[, alpha], A, B; compute_type=nothing, algo=CUBLAS_GEMM_DEFAULT) -> C

Compute alpha * op(A) * op(B), with alpha one by default. See gemm!.

source
cuBLAS.gemm! — Method
gemm!(transA, transB, alpha, A, B, beta, C; compute_type=nothing, algo=CUBLAS_GEMM_DEFAULT)

Compute C = alpha * op(A) * op(B) + beta * C, where op is selected by transA and transB ('N', 'T' or 'C'). The element types of A, B and C can differ, as long as cuBLAS supports the combination.

The compute type is selected based on these element types, e.g., computing products of Float16 matrices in Float16. Pass compute_type=Float32 to compute them in Float32 instead; Float16, Float64 and Int32 are supported as well. The math mode (see CUDA.math_mode!) then determines which variant of the compute type is used, e.g., computing Float32 products with TF32 tensor cores in fast math mode.

alpha and beta are numbers, or device-side scalars (e.g. a CuRef or a one-element CuArray) of the type cuBLAS expects for the selected compute type.

source
cuBLAS.gemm_batched! — Method
gemm_batched!(transA, transB, alpha, A, B, beta, C; compute_type=nothing,
              algo=CUBLAS_GEMM_DEFAULT)

Compute C[i] = alpha * op(A[i]) * op(B[i]) + beta * C[i] for every matrix in the vectors A, B and C. All products need to have the same size; see gemm_grouped_batched! for products of different sizes. Element types, scalars and the compute type are handled like for gemm!.

source
cuBLAS.gemm_grouped_batched! — Method
gemm_grouped_batched!(transA, transB, alpha, A, B, beta, C; compute_type=nothing)

Compute C[i][j] = alpha[i] * op(A[i][j]) * op(B[i][j]) + beta[i] * C[i][j] for every group i of matrices in the vectors of vectors A, B and C. The products in a group need to have the same size, but those in different groups don't. transA, transB, alpha and beta hold a value per group, or a single value for all of them.

With vectors of matrices for A, B and C, every product is a group of its own.

The element types of A, B and C need to be the same: Float16, BFloat16, Float32 or Float64. Products of 16-bit matrices are computed in Float32, and so are alpha and beta, which reside on the host. compute_type can only select that precision: Float32, or Float64 for Float64 matrices. Float16 and BFloat16 need cuBLAS 12.5, the other types cuBLAS 12.4.

source
cuBLAS.gemm_strided_batched! — Method
gemm_strided_batched!(transA, transB, alpha, A, B, beta, C; compute_type=nothing,
                      algo=CUBLAS_GEMM_DEFAULT)

Compute C[:, :, i] = alpha * op(A[:, :, i]) * op(B[:, :, i]) + beta * C[:, :, i] for every slice of the 3-dimensional arrays A, B and C. A or B can have a single slice, which is then used for every product. Element types, scalars and the compute type are handled like for gemm!.

source
cuBLAS.gemv — Function
gemv(trans[, alpha], A, x) -> y

Compute alpha * op(A) * x, with alpha one by default. See gemv!.

source
cuBLAS.gemv! — Function
gemv!(trans, alpha, A, x, beta, y) -> y

Compute y = alpha * op(A) * x + beta * y, where trans selects op ('N', 'T' or 'C'). Wraps cublas<t>gemv.

source
cuBLAS.gemv_batched! — Function
gemv_batched!(trans, alpha, A, x, beta, y) -> y

gemv! for each A[i], x[i] and y[i] of vectors of matrices and vectors of the same sizes. Requires cuBLAS 11.9.2. Wraps cublas<t>gemvBatched.

source
cuBLAS.gemv_strided_batched! — Function
gemv_strided_batched!(trans, alpha, A, x, beta, y) -> y

gemv! for each A[:, :, i], x[:, i] and y[:, i]. Requires cuBLAS 11.9.2. Wraps cublas<t>gemvStridedBatched.

source
cuBLAS.geqrf_batched! — Function
geqrf_batched!(A) -> tau, A

Compute the QR factorization of each matrix in the vector A in place, as LAPACK's geqrf does, returning the reflectors' scalar factors as a vector tau of vectors. Wraps cublas<t>geqrfBatched.

source
cuBLAS.ger! — Function
ger!(alpha, x, y, A) -> A

Compute the rank-1 update A = alpha * x * y' + A. For complex matrices, y is conjugated. Wraps cublas<t>ger (gerc for complex matrices).

source
cuBLAS.getrf_batched! — Function
getrf_batched!(A, pivot[, info]) -> pivot, info, A

Compute the LU factorization of each square matrix in the vector A, in place. pivot is true for partial pivoting, false for none, or an n×batch CuMatrix{Cint} to store the pivots in. The pivots are returned as such a matrix, with one column per matrix; without pivoting it holds zeros, which getrs_batched! and getri_batched! can't use. info[i] > 0 means that A[i] is singular. Wraps cublas<t>getrfBatched.

source
cuBLAS.getri_batched! — Function
getri_batched!(A, C, pivot) -> info

Write the inverse of each matrix to C[i], from the LU factorizations in A and pivots computed by getrf_batched! with pivoting. info[i] > 0 means that A[i] is singular. Wraps cublas<t>getriBatched.

source
cuBLAS.getrs_batched! — Function
getrs_batched!(trans, A, B[, pivot]) -> info, B

Solve op(A[i]) * X = B[i] in place in each B[i], using the LU factorizations and pivots computed by getrf_batched! (leave pivot out for factorizations without pivoting). info is a host Ref{Cint}, nonzero for an invalid argument. Wraps cublas<t>getrsBatched.

source
cuBLAS.handle — Function
cuBLAS.handle()

The cuBLAS handle of the current task, for its active context and stream, for calling the C API of cuBLAS (cuBLAS.cublas*) directly. It converts to a cublasHandle_t. The handle is borrowed: don't destroy it, or change its stream, math mode or other settings.

source
cuBLAS.hbmv — Function
hbmv(uplo, k[, alpha], A, x) -> y

Compute alpha * A * x for a Hermitian band matrix. See hbmv!.

source
cuBLAS.hbmv! — Function
hbmv!(uplo, k, alpha, A, x, beta, y) -> y

Compute y = alpha * A * x + beta * y for the Hermitian band matrix A with k super- or subdiagonals, stored in band format. Only for complex arrays. Wraps cublas<t>hbmv.

source
cuBLAS.hemm — Function
hemm(side, uplo[, alpha], A, B) -> C

Compute alpha * A * B or alpha * B * A for a Hermitian matrix A. See hemm!.

source
cuBLAS.hemm! — Function
hemm!(side, uplo, alpha, A, B, beta, C) -> C

Compute C = alpha * A * B + beta * C (side = 'L') or C = alpha * B * A + beta * C (side = 'R') for the Hermitian matrix A, reading the triangle selected by uplo. Only for complex arrays. Wraps cublas<t>hemm.

source
cuBLAS.hemv — Function
hemv(uplo[, alpha], A, x) -> y

Compute alpha * A * x for a Hermitian matrix. See hemv!.

source
cuBLAS.hemv! — Function
hemv!(uplo, alpha, A, x, beta, y) -> y

Compute y = alpha * A * x + beta * y for the Hermitian matrix A, reading the triangle selected by uplo. Only for complex arrays. Wraps cublas<t>hemv.

source
cuBLAS.her! — Function
her!(uplo, alpha, x, A) -> A

Compute the rank-1 update A = alpha * x * x' + A of the triangle of the Hermitian matrix A selected by uplo, with real alpha. Only for complex arrays. Wraps cublas<t>her.

source
cuBLAS.her2! — Function
her2!(uplo, alpha, x, y, A) -> A

Compute the rank-2 update A = alpha * x * y' + conj(alpha) * y * x' + A of the triangle of the Hermitian matrix A selected by uplo. Only for complex arrays. Wraps cublas<t>her2.

source
cuBLAS.her2k! — Function
her2k!(uplo, trans, alpha, A, B, beta, C) -> C

Compute the rank-2k update C = alpha * A * B' + conj(alpha) * B * A' + beta * C (trans = 'N'), or with the adjoints on the left (trans = 'C'), of the triangle of the Hermitian matrix C selected by uplo, with real beta. Only for complex arrays. Wraps cublas<t>her2k.

source
cuBLAS.herk — Function
herk(uplo, trans[, alpha], A) -> C

Compute the triangle of alpha * A * A' or alpha * A' * A selected by uplo. See herk!.

source
cuBLAS.herk! — Function
herk!(uplo, trans, alpha, A, beta, C) -> C

Compute the rank-k update C = alpha * A * A' + beta * C (trans = 'N') or C = alpha * A' * A + beta * C (trans = 'C') of the triangle of the Hermitian matrix C selected by uplo, with real alpha and beta. Only for complex arrays. Wraps cublas<t>herk.

source
cuBLAS.iamax — Function
iamax([n,] x) -> Integer
iamax([n,] x, result) -> result

The 1-based index of the first element of x, among its first n, with the largest absolute value (sum of absolute real and imaginary parts for complex x). The index is an Int64 from cuBLAS 12, and a Cint before. With a device-side result, it is written there without synchronizing. Wraps cublasI<t>amax.

source
cuBLAS.iamin — Function
iamin([n,] x) -> Integer
iamin([n,] x, result) -> result

Like iamax, but the index of the element with the smallest absolute value. Wraps cublasI<t>amin.

source
cuBLAS.matinv_batched — Function
matinv_batched(A) -> info, C

Invert each matrix in the vector A, which must be smaller than 32×32, without a separate factorization. info[i] > 0 means that A[i] is singular. Wraps cublas<t>matinvBatched.

source
cuBLAS.nrm2 — Function
nrm2([n,] x) -> real(T)
nrm2([n,] x, result) -> result

The Euclidean norm of the first n elements of x, by default all of them. With a device-side result (e.g. a CuRef), the norm is written there without synchronizing; this form does not support ComplexF16. Wraps cublas<t>nrm2.

source
cuBLAS.rot! — Function
rot!(n, x, y, c, s) -> x, y

Apply the plane rotation with cosine c and sine s to the first n elements of x and y, in place. Wraps cublas<t>rot.

source
cuBLAS.rotg! — Method
rotg!(a, b) -> a, b, c, s
rotg!(a, b, c, s) -> a, b, c, s

Construct the Givens rotation [c s; -conj(s) c] that zeroes out b, overwriting a with the rotated value (and, for real inputs, b with the reconstruction parameter).

When a and b are numbers, the results are returned as numbers. When they are device-side scalars (a CuRef or a one-element CuArray), they are updated in place and c and s are returned as device-side scalars as well, without synchronizing with the GPU. These outputs can be passed directly to rot!. Preallocated device-side c and s can be passed too.

source
cuBLAS.rotm! — Function
rotm!(n, x, y, param) -> x, y

Apply the modified Givens rotation described by the 5-element vector param (see rotmg!) to the first n elements of x and y, in place. Only for real arrays. Wraps cublas<t>rotm.

source
cuBLAS.rotmg! — Method
rotmg!(d1, d2, x, y, param) -> d1, d2, x, y, param

Construct the modified Givens rotation that zeroes out the second component of (sqrt(d1)*x, sqrt(d2)*y), storing its flag and matrix in the 5-element param.

When d1, d2 and x are numbers, their updated values are returned as numbers. When they are device-side scalars (a CuRef or a one-element CuArray), they are updated in place without synchronizing with the GPU; y is only read and can be either.

source
cuBLAS.sbmv — Function
sbmv(uplo, k[, alpha], A, x) -> y

Compute alpha * A * x for a symmetric band matrix. See sbmv!.

source
cuBLAS.sbmv! — Function
sbmv!(uplo, k, alpha, A, x, beta, y) -> y

Compute y = alpha * A * x + beta * y for the symmetric band matrix A with k super- or subdiagonals, stored in band format. Only for real arrays. Wraps cublas<t>sbmv.

source
cuBLAS.scal! — Function
scal!(n, alpha, x) -> x

Scale the first n elements of x by alpha in place. alpha can also be a device-side scalar (a CuRef or one-element CuArray). Wraps cublas<t>scal.

source
cuBLAS.spmv — Function
spmv(uplo[, alpha], AP, x) -> y

Compute alpha * A * x for a packed symmetric matrix. See spmv!.

source
cuBLAS.spmv! — Function
spmv!(uplo, alpha, AP, x, beta, y) -> y

Compute y = alpha * A * x + beta * y for the symmetric matrix A whose triangle selected by uplo is stored packed in the vector AP. Only for real arrays. Wraps cublas<t>spmv.

source
cuBLAS.spr! — Function
spr!(uplo, alpha, x, AP) -> AP

Compute the rank-1 update A = alpha * x * transpose(x) + A of the symmetric matrix A whose triangle selected by uplo is stored packed in the vector AP. Only for real arrays. Wraps cublas<t>spr.

source
cuBLAS.swap! — Function
swap!(n, x, y) -> x, y

Swap the first n elements of x and y. Wraps cublas<t>swap.

source
cuBLAS.symm — Function
symm(side, uplo[, alpha], A, B) -> C

Compute alpha * A * B or alpha * B * A for a symmetric matrix A. See symm!.

source
cuBLAS.symm! — Function
symm!(side, uplo, alpha, A, B, beta, C) -> C

Compute C = alpha * A * B + beta * C (side = 'L') or C = alpha * B * A + beta * C (side = 'R') for the symmetric matrix A, reading the triangle selected by uplo. Wraps cublas<t>symm.

source
cuBLAS.symv — Function
symv(uplo[, alpha], A, x) -> y

Compute alpha * A * x for a symmetric matrix. See symv!.

source
cuBLAS.symv! — Function
symv!(uplo, alpha, A, x, beta, y) -> y

Compute y = alpha * A * x + beta * y for the symmetric matrix A, reading the triangle selected by uplo. Wraps cublas<t>symv.

source
cuBLAS.syr! — Function
syr!(uplo, alpha, x, A) -> A

Compute the rank-1 update A = alpha * x * transpose(x) + A of the triangle of the symmetric matrix A selected by uplo. Wraps cublas<t>syr.

source
cuBLAS.syr2k! — Function
syr2k!(uplo, trans, alpha, A, B, beta, C) -> C

Compute the rank-2k update C = alpha * (A * transpose(B) + B * transpose(A)) + beta * C (trans = 'N'), or with the transposes on the left (trans = 'T'), of the triangle of the symmetric matrix C selected by uplo. Wraps cublas<t>syr2k.

source
cuBLAS.syrk — Function
syrk(uplo, trans[, alpha], A) -> C

Compute the triangle of alpha * A * transpose(A) or alpha * transpose(A) * A selected by uplo. See syrk!.

source
cuBLAS.syrk! — Function
syrk!(uplo, trans, alpha, A, beta, C) -> C

Compute the rank-k update C = alpha * A * transpose(A) + beta * C (trans = 'N') or C = alpha * transpose(A) * A + beta * C (trans = 'T') of the triangle of the symmetric matrix C selected by uplo. Wraps cublas<t>syrk.

source
cuBLAS.syrkx — Function
syrkx(uplo, trans, alpha, A, beta, B) -> C
syrkx(uplo, trans, A, B) -> C

Compute alpha * op(A) * transpose(op(B)), with alpha one by default. See syrkx!. beta must be zero: the result is accumulated into uninitialized memory.

source
cuBLAS.syrkx! — Function
syrkx!(uplo, trans, alpha, A, B, beta, C) -> C

Like syrk!, but computing alpha * op(A) * transpose(op(B)) + beta * C, for when that product is known to be symmetric. Wraps cublas<t>syrkx.

source
cuBLAS.tbmv — Function
tbmv(uplo, trans, diag, k, A, x) -> y

Compute op(A) * x for a triangular band matrix. See tbmv!.

source
cuBLAS.tbmv! — Function
tbmv!(uplo, trans, diag, k, A, x) -> x

Compute x = op(A) * x for the triangular band matrix A with k super- or subdiagonals, stored in band format. diag = 'U' means A has a unit diagonal. Wraps cublas<t>tbmv.

source
cuBLAS.tbsv — Function
tbsv(uplo, trans, diag, k, A, x) -> y

Solve op(A) * y = x for a triangular band matrix. See tbsv!.

source
cuBLAS.tbsv! — Function
tbsv!(uplo, trans, diag, k, A, x) -> x

Solve op(A) * y = x in place in x, for the triangular band matrix A with k super- or subdiagonals. Wraps cublas<t>tbsv.

source
cuBLAS.trmm! — Function
trmm!(side, uplo, transa, diag, alpha, A, B, C) -> C

Compute C = alpha * op(A) * B (side = 'L') or C = alpha * B * op(A) (side = 'R') for the triangular matrix A. Unlike LinearAlgebra.BLAS.trmm!, the result is written to C, which can be B itself. Wraps cublas<t>trmm.

source
cuBLAS.trmv — Function
trmv(uplo, trans, diag, A, x) -> y

Compute op(A) * x for a triangular matrix. See trmv!.

source
cuBLAS.trmv! — Function
trmv!(uplo, trans, diag, A, x) -> x

Compute x = op(A) * x for the triangular matrix A, reading the triangle selected by uplo. diag = 'U' means A has a unit diagonal. Wraps cublas<t>trmv.

source
cuBLAS.trsm! — Function
trsm!(side, uplo, transa, diag, alpha, A, B) -> B

Solve op(A) * X = alpha * B (side = 'L') or X * op(A) = alpha * B (side = 'R') for the triangular matrix A, overwriting B with X. Wraps cublas<t>trsm.

source
cuBLAS.trsm_batched! — Function
trsm_batched!(side, uplo, transa, diag, alpha, A, B) -> B

trsm! for each A[i] and B[i] of vectors of matrices of the same sizes. Wraps cublas<t>trsmBatched.

source
cuBLAS.trsv — Function
trsv(uplo, trans, diag, A, x) -> y

Solve op(A) * y = x for a triangular matrix. See trsv!.

source
cuBLAS.trsv! — Function
trsv!(uplo, trans, diag, A, x) -> x

Solve op(A) * y = x in place in x, for the triangular matrix A. Wraps cublas<t>trsv.

source
cuBLAS.version — Function
cuBLAS.version() -> VersionNumber

The version of the cuBLAS library in use.

source
cuBLAS.xt_devices — Function
xt_devices() -> Vector{CuDevice}

The devices that the xt_* wrappers (cuBLASXt) of the current task distribute their work over; all devices by default.

source
cuBLAS.xt_devices! — Function
xt_devices!(devs::Vector{CuDevice})

Set the devices that the xt_* wrappers (cuBLASXt) of the current task distribute their work over.

source
cuBLAS.xt_gemm! — Function
xt_gemm!(transA, transB, alpha, A, B, beta, C) -> C

gemm! through cuBLASXt, which splits the product over the devices in xt_devices. The arrays can be in host or device memory, and the call returns when the result is ready. cuBLASXt does not follow stream ordering: device arrays must be ready when it is called, e.g. by synchronizing after the operations that compute them. Wraps cublasXt<t>gemm.

source
cuBLAS.xt_syrkx — Function
xt_syrkx(uplo, trans, alpha, A, B, beta) -> C

Allocating version of xt_syrkx!. beta must be zero: the result is accumulated into uninitialized memory.

source

Private