QR and orthogonal transforms

Overview

Householder QR, forming and applying Q, and batched orthogonalisation.

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

Functions

◆ ortho() [1/12]

template<Backend B, typename T>
Event batchlas::ortho ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
Transpose transA,
Span< std::byte > workspace,
OrthoAlgorithm algo = OrthoAlgorithm::Chol2 )

Orthonormalises the columns (or rows) of each batch item in place.

With transA == NoTrans each n-column block of A is replaced by an orthonormal basis of its column space, \( A \leftarrow Q \) with \( Q^H Q = I \); with Trans the rows are orthonormalised instead. Asynchronous.

Parameters
ctxqueue the work is enqueued on
Abatch of m x n matrices; overwritten with the orthonormal vectors
transANoTrans for columns, Trans for rows
workspaceat least ortho_buffer_size() bytes for the same algo
algoorthogonalisation algorithm (see OrthoAlgorithm)
Returns
event of the last enqueued kernel
Note
The workspace depends on algo: size it with the algorithm the call runs.

◆ ortho() [2/12]

template<Backend B, typename T>
Event batchlas::ortho ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const MatrixView< T, MatrixFormat::Dense > & M,
Transpose transA,
Transpose transM,
Span< std::byte > workspace,
OrthoAlgorithm algo = OrthoAlgorithm::Chol2,
size_t iterations = 2 )

Orthonormalises A against the columns of an external basis M, in place.

Each of iterations passes projects out the span of M, \( A \leftarrow A - M (M^H A) \), and then orthonormalises A with algo.

Parameters
ctxqueue the work is enqueued on
Abatch of vectors to orthonormalise; overwritten
Mexternal basis, read only
transANoTrans: the vectors are the columns of A; transposed: its rows
transMNoTrans: the basis vectors are the columns of M; transposed: its rows
workspaceat least ortho_buffer_size() bytes for the same arguments
algoorthogonalisation algorithm run after each projection
iterationsnumber of project-then-orthonormalise passes
Returns
event of the last enqueued kernel
Precondition
M's vectors are orthonormal, and the vector counts of A and M sum to at most the vector length.
Exceptions
batchlas::invalid_argumentif the vector counts exceed the vector length

◆ ortho() [3/12]

template<Backend B, typename T>
Event batchlas::ortho ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const OrthoOptions & opts,
Span< std::byte > workspace )
inline

ortho() with an options struct and a caller-provided workspace.

Definition at line 2102 of file extensions.hh.

◆ ortho() [4/12]

template<Backend B, typename T>
Event batchlas::ortho ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const OrthoOptions & opts )
inline

ortho() with an options struct; workspace is leased from the Queue's arena.

The lease is released when the call returns, which on an out-of-order Queue drains the device first: this spelling is synchronous there, the span-taking one is not.

Definition at line 2116 of file extensions.hh.

◆ ortho() [5/12]

template<typename T>
Event batchlas::ortho ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const OrthoOptions & opts,
Span< std::byte > workspace )
inline

Definition at line 2126 of file extensions.hh.

◆ ortho() [6/12]

template<typename T>
Event batchlas::ortho ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const OrthoOptions & opts = {} )
inline

Definition at line 2139 of file extensions.hh.

◆ ortho() [7/12]

template<Backend B, typename T>
Event batchlas::ortho ( Queue & ,
const MatrixView< T, MatrixFormat::Dense > & ,
detail::OrthoEmptyBracesAreAmbiguous ,
Span< std::byte >  )
delete

◆ ortho() [8/12]

template<typename T>
Event batchlas::ortho ( Queue & ,
const MatrixView< T, MatrixFormat::Dense > & ,
detail::OrthoEmptyBracesAreAmbiguous ,
Span< std::byte >  )
delete

◆ ortho() [9/12]

template<Backend B, typename T>
Event batchlas::ortho ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const MatrixView< T, MatrixFormat::Dense > & M,
const OrthoAgainstOptions & opts,
Span< std::byte > workspace )
inline

ortho() against M with an options struct and a caller-provided workspace.

Definition at line 2174 of file extensions.hh.

◆ ortho() [10/12]

template<Backend B, typename T>
Event batchlas::ortho ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const MatrixView< T, MatrixFormat::Dense > & M,
const OrthoAgainstOptions & opts )
inline

ortho() against M with an options struct; workspace leased from the arena.

Definition at line 2185 of file extensions.hh.

◆ ortho() [11/12]

template<typename T>
Event batchlas::ortho ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const MatrixView< T, MatrixFormat::Dense > & M,
const OrthoAgainstOptions & opts,
Span< std::byte > workspace )
inline

Definition at line 2196 of file extensions.hh.

◆ ortho() [12/12]

template<typename T>
Event batchlas::ortho ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const MatrixView< T, MatrixFormat::Dense > & M,
const OrthoAgainstOptions & opts = {} )
inline

Definition at line 2211 of file extensions.hh.

◆ geqrf()

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

Batched Householder QR factorization \( A = Q R \).

For every m x n batch item, as LAPACK ?geqrf: on return the upper triangle (upper trapezoid if m < n) of A holds R, and the part below the diagonal holds the Householder vectors \( v_i \) with an implied unit leading entry. With \( k = \min(m, n) \), \( Q = H_1 H_2 \cdots H_k \), \( H_i = I - \tau_i v_i v_i^H \). Pass A and tau unchanged to orgqr() to form Q or to ormqr() to apply it.

Asynchronous: A and tau 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 m x n matrices; overwritten with R and the reflectors
taureflector scalars, k * batch elements; item b's \( \tau_i \) is tau[b * k + i]
work_spacedevice-accessible scratch of at least geqrf_buffer_size() bytes
Returns
event of the last enqueued kernel
Precondition
tau.size() >= min(m, n) * A.batch_size() (checked by the option overloads only)
Exceptions
batchlas::invalid_argumenton negative extents
batchlas::NoRouteErrorif no native kernel can run the shape (the native kernels need m >= n) and the vendor library was not built in

◆ orgqr()

template<Backend B, typename T>
Event batchlas::orgqr ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
Span< T > tau,
Span< std::byte > workspace )

Batched formation of the first n columns of Q from geqrf() output.

As LAPACK ?orgqr / ?ungqr with \( k = n \): A holds, below its diagonal, the reflectors written by geqrf() on an m x n matrix, and on return A holds the m x n matrix \( Q = H_1 H_2 \cdots H_n \) restricted to its first n columns, with orthonormal columns ( \( Q^H Q = I \)).

Asynchronous: A is 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 m x n geqrf() outputs, m >= n; overwritten with Q
taureflector scalars from geqrf(), n * batch elements
workspacedevice-accessible scratch of at least orgqr_buffer_size() bytes
Returns
event of the last enqueued kernel
Precondition
A.cols() <= A.rows(); not checked by any overload
tau.size() >= min(m, n) * batch (checked by the option overloads only)
Exceptions
batchlas::invalid_argumenton negative extents
batchlas::NoRouteErrorif no native kernel can run the shape (the blocked kernel needs a GPU queue, a homogeneous batch and n <= m) and the vendor library was not built in

◆ ormqr()

template<Backend B, typename T>
Event batchlas::ormqr ( Queue & ctx,
const MatrixView< T, MatrixFormat::Dense > & A,
const MatrixView< T, MatrixFormat::Dense > & C,
Side side,
Transpose trans,
Span< T > tau,
Span< std::byte > workspace,
int32_t block_size_hint = 0 )

Batched multiplication by the orthogonal/unitary Q from geqrf().

As LAPACK ?ormqr / ?unmqr. A holds, below its diagonal, the \( k = \min(A_{rows}, A_{cols}) \) reflectors that geqrf() wrote, with \( Q = H_1 \cdots H_k \) of order A.rows(). For every batch item C is overwritten with \( \mathrm{op}(Q)\, C \) (Side::Left) or \( C\, \mathrm{op}(Q) \) (Side::Right), where \( \mathrm{op}(Q) \) is Q for NoTrans and \( Q^H \) for ConjTrans ( \( Q^T \) for real T, where Trans means the same). Q is never formed.

The kernel (the blocked WY apply on a GPU queue, or the vendor library) is chosen per call from the device's tuned table (src/ops/ormqr/ormqr.cc) and can be pinned with BATCHLAS_ORMQR_ROUTE.

Asynchronous: C is readable after the returned event is waited on. On an out-of-order ctx the work runs on an internal in-order queue that first waits for everything already submitted to ctx.

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 geqrf() outputs holding the reflectors; not modified
Cbatch of matrices to multiply; overwritten with the product
sideapply Q from the left or the right
transapply Q (NoTrans) or its (conjugate) transpose
taureflector scalars from geqrf(), k * batch elements
workspacedevice-accessible scratch of at least ormqr_buffer_size() bytes, sized with the same block_size_hint
block_size_hintWY panel width for the blocked kernel; 0 lets the tuning table choose. Clamped to [1, k]; ignored by the vendor kernel.
Returns
event of the last enqueued kernel
Precondition
A.rows() == C.rows() for Side::Left, A.rows() == C.cols() for Side::Right, and A and C share a batch size
tau.size() >= k * batch (checked by the option overloads)
Exceptions
batchlas::workspace_errorif workspace is smaller than the chosen kernel needs
batchlas::invalid_argumentfor Transpose::Trans with complex T (use ConjTrans), and on non-conforming operands (blocked kernel)
batchlas::NoRouteErrorif no native kernel can run (e.g. a CPU queue) and the vendor library was not built in
See also
OrmqrOptions

Topics

 QR: lower-level API
 Workspace queries, argument validation and the CTA ormqr kernel behind the QR entry points.

Files

file  include/batchlas/blas/functions/geqrf.hh
 Batched Householder QR factorization (geqrf) and its workspace query.
file  include/batchlas/blas/functions/orgqr.hh
 Batched formation of Q from geqrf reflectors (orgqr/ungqr) and its workspace query.
file  include/batchlas/blas/functions/ormqr.hh
 Batched application of Q from geqrf reflectors (ormqr/unmqr) and its workspace query.

Classes

struct  batchlas::OrthoOptions
 Options for the option-struct ortho(); fields as the positional arguments. More...
struct  batchlas::OrthoAgainstOptions
 Options for the option-struct ortho() against an external basis M. More...