Factorizations and linear solvers

Overview

Cholesky and LU factorizations, their solves and inverses.

Lower-level functions (algorithm-specific variants, workspace queries, validation and helpers): Factorizations: lower-level API.

Functions

◆ gesv() [1/2]

template<Backend Back, typename T>
Event batchlas::gesv ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const MatrixView< T, MatrixFormat::Dense > & B,
Span< int64_t > pivots,
Span< std::byte > work_space,
Span< int32_t > info )

Batched solve of \( A X = B \) by LU with partial pivoting.

Semantically getrf() followed by getrs() with Transpose::NoTrans: on return A holds L and U as getrf() leaves them, pivots the same packed 1-based interchange list getrf() writes (so the factors can be reused with getrs() or getri()), B holds X and info carries getrf's per-item status. No vendor library call sits behind this op; it is served by a native fused tier or by the routed getrf + getrs composition.

Asynchronous: A, B, pivots and info are readable after the returned event is waited on.

Template Parameters
Backbackend; the backend-deducing overload takes it from ctx.backend()
Tscalar type (float, double, std::complex<float>, std::complex<double>)
Parameters
ctxqueue the kernels are enqueued on
Abatch of n x n matrices; overwritten with L and U
Bbatch of n x nrhs right-hand sides; overwritten with X
pivotspivot output, n * batch entries in getrf()'s format
work_spacedevice-accessible scratch of at least gesv_buffer_size() bytes
infoper-item status as for getrf(): 0 on success, i > 0 if U(i,i) is exactly zero (that item's X is meaningless). Empty span = not requested.
Returns
event of the last enqueued kernel
Exceptions
batchlas::invalid_argumentif gesv_validate_params() rejects the call
batchlas::workspace_errorif the composed getrf + getrs route is chosen and work_space is shorter than its getrf leg needs

◆ gesv() [2/2]

template<Backend Back, typename T>
Event batchlas::gesv ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const MatrixView< T, MatrixFormat::Dense > & B,
Span< int64_t > pivots,
Span< std::byte > work_space )
inline

gesv() without per-item status (info not requested).

Definition at line 122 of file gesv.hh.

◆ getrf() [1/2]

template<Backend B, typename T>
Event batchlas::getrf ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
Span< int64_t > pivots,
Span< std::byte > work_space,
Span< int32_t > info )

Batched LU factorization with partial pivoting.

For every batch item computes \( A = P L U \) with L unit lower triangular and U upper triangular, and overwrites A with L (below the diagonal, unit diagonal implied) and U (on and above it), as LAPACK ?getrf.

Pivot format. pivots is typed int64_t, but on the GPU backends and every native kernel it holds packed 1-based int32 indices: item b's row interchange i (row i was swapped with row ipiv[i]) is the int32 at index b * n + i of the span's bytes reinterpreted as int32_t. The NETLIB backend writes genuine 1-based int64 instead. Pass the span unchanged to getrs() / getri() on the same backend; do not read or compare the entries across backends. Complex pivots are chosen on |Re| + |Im| natively and on the modulus by cuBLAS, so pivot sequences can differ between kernels while both factorizations are valid.

Asynchronous: A, pivots and info are readable after the returned event is waited on.

Template Parameters
Bbackend; the backend-deducing overload takes it from ctx.backend()
Tscalar type (float, double, std::complex<float>, std::complex<double>)
Parameters
ctxqueue the kernels are enqueued on
Abatch of n x n matrices; overwritten with L and U. An m x n batch is factored whole by the NETLIB and ROCm vendors (min(m, n) pivots per item, packed); CUDA has no route for it
pivotspivot output, at least n * batch int64_t elements
work_spacedevice-accessible scratch of at least getrf_buffer_size() bytes
infoper-item LAPACK status, one int32 per batch item: 0 on success, i > 0 if U(i,i) is exactly zero (1-based; the factorization completed but U is singular). Empty span = not requested.
Returns
event of the last enqueued kernel
Precondition
A.rows() == A.cols() (checked by the option overloads only)
pivots.size() >= A.rows() * A.batch_size() (checked by the option overloads only)
a non-empty info holds at least A.batch_size() elements; a shorter one is silently ignored by this overload
Exceptions
batchlas::invalid_argumenton negative extents
batchlas::NoRouteErrorif no native kernel can run the shape and the vendor library was not built in
Note
The workspace size does not depend on whether info is requested.

◆ getrf() [2/2]

template<Backend B, typename T>
Event batchlas::getrf ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
Span< int64_t > pivots,
Span< std::byte > work_space )
inline

getrf() without per-item status (info not requested).

Definition at line 120 of file getrf.hh.

◆ getri() [1/2]

template<Backend B, typename T>
Event batchlas::getri ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const MatrixView< T, MatrixFormat::Dense > & C,
Span< int64_t > pivots,
Span< std::byte > work_space,
Span< int32_t > info )

Batched inverse \( C = A^{-1} \) from the LU factors produced by getrf().

A and pivots must be exactly what getrf() produced on the same backend (see getrf() for the packed 1-based int32 pivot format). The inverse is written to C, out of place; A is not part of the output.

Asynchronous: C and info are readable after the returned event is waited on.

Template Parameters
Bbackend; the backend-deducing overload takes it from ctx.backend()
Tscalar type (float, double, std::complex<float>, std::complex<double>)
Parameters
ctxqueue the kernels are enqueued on
Abatch of n x n LU factors from getrf()
Cbatch of n x n outputs, receives \( A^{-1} \)
pivotspivots from getrf(), n * batch entries
work_spacedevice-accessible scratch of at least getri_buffer_size() bytes
infoper-item LAPACK status, one int32 per batch item: 0 on success, i > 0 if U(i,i) is exactly zero, so the item has no inverse (its C is not meaningful). Empty span = not requested.
Returns
event of the last enqueued kernel
Precondition
A and C square of the same order and batch, and pivots.size() >= n * batch (checked by the option overloads only)
Exceptions
batchlas::invalid_argumenton negative extents, or if C aliases A
batchlas::NoRouteErrorif no native kernel can run the shape and the vendor library was not built in
Note
The workspace size does not depend on whether info is requested.

◆ getri() [2/2]

template<Backend B, typename T>
Event batchlas::getri ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const MatrixView< T, MatrixFormat::Dense > & C,
Span< int64_t > pivots,
Span< std::byte > work_space )
inline

getri() without per-item status (info not requested).

Definition at line 122 of file getri.hh.

◆ getrs()

template<Backend Back, typename T>
Event batchlas::getrs ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const MatrixView< T, MatrixFormat::Dense > & B,
Transpose transA,
Span< int64_t > pivots,
Span< std::byte > work_space )

Batched solve of \( \mathrm{op}(A) X = B \) using the LU factors from getrf().

A and pivots must be exactly what getrf() produced on the same backend (see getrf() for the packed 1-based int32 pivot format). \( \mathrm{op}(A) \) is A, \( A^T \) or \( A^H \) for NoTrans, Trans, ConjTrans. B is overwritten with X. No singularity check is made: a zero U(i,i) (reported by getrf's info) produces infinities or NaNs in that item.

Asynchronous: B is readable after the returned event is waited on.

Template Parameters
Backbackend; the backend-deducing overload takes it from ctx.backend()
Tscalar type (float, double, std::complex<float>, std::complex<double>)
Parameters
ctxqueue the kernels are enqueued on
Abatch of n x n LU factors from getrf(); not modified
Bbatch of n x nrhs right-hand sides; overwritten with X
transAwhich of A, A^T, A^H to solve with
pivotspivots from getrf(), n * batch entries
work_spacedevice-accessible scratch of at least getrs_buffer_size() bytes
Returns
event of the last enqueued kernel
Precondition
A.rows() == A.cols() == B.rows(), equal batch sizes, and pivots.size() >= n * batch (checked by the option overloads only)
Exceptions
batchlas::invalid_argumenton negative extents
batchlas::NoRouteErrorif no native kernel can run the shape and the vendor library was not built in
See also
GetrsOptions

◆ posv() [1/2]

template<Backend Back, typename T>
Event batchlas::posv ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const MatrixView< T, MatrixFormat::Dense > & B,
Uplo uplo,
Span< std::byte > work_space,
Span< int32_t > info )

Batched solve of \( A X = B \) for Hermitian positive-definite A.

Semantically potrf(A, uplo) followed by the two triangular solves with the factor: on return A holds the Cholesky factor in the uplo triangle (the other triangle is not read, and, as for potrf(), a vendor potrf leg may overwrite it), B holds X, and info carries potrf's status. There is no vendor library call behind this op on any backend; it is served by native fused tiers or by the routed potrf + trsm composition.

Asynchronous: A, B and info are readable after the returned event is waited on.

Template Parameters
Backbackend; the backend-deducing overload takes it from ctx.backend()
Tscalar type (float, double, std::complex<float>, std::complex<double>)
Parameters
ctxqueue the kernels are enqueued on
Abatch of n x n matrices; overwritten with the Cholesky factor
Bbatch of n x nrhs right-hand sides; overwritten with X
uplotriangle of A that is read and receives the factor
work_spacedevice-accessible scratch of at least posv_buffer_size() bytes
infoper-item status as for potrf(): 0 on success, i > 0 if the leading minor of order i is not positive definite (that item's X is meaningless). Empty span = not requested.
Returns
event of the last enqueued kernel
Exceptions
batchlas::invalid_argumentif posv_validate_params() rejects the call

◆ posv() [2/2]

template<Backend Back, typename T>
Event batchlas::posv ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const MatrixView< T, MatrixFormat::Dense > & B,
Uplo uplo,
Span< std::byte > work_space )
inline

posv() without per-item status (info not requested).

Definition at line 126 of file posv.hh.

◆ potrf() [1/2]

template<Backend B, typename T>
Event batchlas::potrf ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & descrA,
Uplo uplo,
Span< std::byte > workspace,
Span< int32_t > info )

Batched Cholesky factorization of Hermitian positive-definite matrices.

For every batch item computes \( A = L L^H \) (Uplo::Lower) or \( A = U^H U \) (Uplo::Upper) and overwrites the uplo triangle of A with the factor. Only that triangle is read. The opposite triangle is not part of the result: some vendor paths (cuSOLVER's Upper potrf) overwrite it.

The call is asynchronous: it enqueues on ctx and returns; A and info are readable only after the returned event (or the queue) has been waited on.

Template Parameters
Bbackend; the backend-deducing overload takes it from ctx.backend()
Tscalar type (float, double, std::complex<float>, std::complex<double>)
Parameters
ctxqueue the kernels are enqueued on
descrAbatch of n x n matrices (any ld >= n, any batch stride); overwritten with the Cholesky factor
uplotriangle of A that holds the input and receives the factor
workspacedevice-accessible scratch of at least potrf_buffer_size() bytes
infoper-item LAPACK status, one int32 per batch item: 0 on success, i > 0 if the leading minor of order i is not positive definite (that item's factor is incomplete). An empty span means "not requested".
Returns
event of the last enqueued kernel
Precondition
descrA.rows() == descrA.cols()
a non-empty info holds at least descrA.batch_size() elements; a shorter non-empty span is silently ignored by this overload (the checked option overloads throw).
Exceptions
batchlas::invalid_argumenton negative extents, a non-square A or an invalid uplo
batchlas::NoRouteErrorif no native kernel can run the shape and the vendor library was not built in
See also
PotrfOptions for the option-struct spelling; its checked overloads validate the info span, and its arena overloads lease the workspace.

◆ potrf() [2/2]

template<Backend B, typename T>
Event batchlas::potrf ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & descrA,
Uplo uplo,
Span< std::byte > workspace )
inline

potrf() without per-item status (info not requested).

Definition at line 138 of file potrf.hh.

Topics

 Factorizations: lower-level API
 Workspace queries and argument validation behind potrf, getrf, getrs, getri, gesv and posv.

Files

file  include/batchlas/blas/functions/gesv.hh
 Batched general linear solve (gesv) by LU with partial pivoting.
file  include/batchlas/blas/functions/getrf.hh
 Batched LU factorization with partial pivoting (getrf) and its workspace query.
file  include/batchlas/blas/functions/getri.hh
 Batched matrix inverse from LU factors (getri) and its workspace query.
file  include/batchlas/blas/functions/getrs.hh
 Batched solve with LU factors from getrf (getrs) and its workspace query.
file  include/batchlas/blas/functions/posv.hh
 Batched Hermitian positive-definite solve (posv) by Cholesky.
file  include/batchlas/blas/functions/potrf.hh
 Batched Cholesky factorization (potrf) and its workspace query.