Sparse (CSR) operations

Overview

Sparse-dense products, ILU(k) and CSR test-matrix generators.

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

Functions

◆ iluk_factorize() [1/2]

template<Backend B, typename T>
ILUKPreconditioner< T > batchlas::iluk_factorize ( Queue & ctx,
const MatrixView< T, MatrixFormat::CSR > & A,
const ILUKParams< T > & params = ILUKParams< T >() )

Computes the ILU(k) factor of a batch of CSR matrices into owned storage.

Every item of A must share one sparsity pattern; the factor's pattern is the union of what each item kept, so the batch keeps sharing one pattern. Blocking: returns once the factor is complete. The numeric phase runs on the device for large batches and on the host otherwise (BATCHLAS_ILUK_DEVICE forces either).

Template Parameters
Bbackend the call is compiled for
Tscalar type
Parameters
ctxqueue used for the device phase and allocations
Abatch of square CSR matrices; not modified
paramsfill, drop and pivot controls
Returns
the owning factor, ready for iluk_apply
Exceptions
batchlas::invalid_argumentif A is not square, a parameter is out of range, or the batch items do not share one pattern
batchlas::convergence_errorif a pivot is zero and diagonal_shift cannot stabilise it

◆ iluk_factorize() [2/2]

template<Backend B, typename T>
ILUKView< T > batchlas::iluk_factorize ( Queue & ctx,
const MatrixView< T, MatrixFormat::CSR > & A,
Span< std::byte > workspace,
const ILUKParams< T > & params,
size_t * bytes_used = nullptr )

Computes the ILU(k) factor into caller-supplied memory instead of allocating.

Same factorization as the owning overload. Lets an iterative solver carve the preconditioner out of a workspace it already holds. The exact footprint is only known after the numeric phase, so it is reported through bytes_used rather than predicted.

Parameters
ctxqueue used for the device phase
Abatch of square CSR matrices sharing one pattern; not modified
workspaceat least iluk_buffer_size bytes of USM the host can write (the level schedule is copied in from the host)
paramsfill, drop and pivot controls
bytes_usedif non-null, receives the bytes of workspace the factor occupies
Returns
a view that aliases workspace and is valid only while it is
Exceptions
batchlas::invalid_argument,batchlas::convergence_erroras the owning overload

◆ iluk_apply() [1/2]

template<Backend B, typename T>
Event batchlas::iluk_apply ( Queue & ctx,
const ILUKView< T > & M,
const MatrixView< T, MatrixFormat::Dense > & rhs,
const MatrixView< T, MatrixFormat::Dense > & out,
Span< std::byte > workspace = Span< std::byte >() )

Applies the ILU(k) preconditioner: out := \((LU)^{-1}\) rhs.

For every batch item and every column of rhs, solves \(L y = r\) (unit diagonal) and then \(U x = y\) by level-scheduled sparse triangular solves, and writes \(x\) to out. Asynchronous: nothing is waited on, so repeated applications inside an iterative solver stay pipelined.

Parameters
ctxqueue the kernel is enqueued on
Mfactor from iluk_factorize
rhsbatch of n x nrhs right-hand sides; not modified
outbatch of n x nrhs results
workspaceunused; iluk_apply_buffer_size is 0
Returns
event of the solve kernel
Exceptions
batchlas::invalid_argumentif rhs / out rows differ from M.n, their column counts differ, their batch size differs from M.batch_size, or M has no level schedule
batchlas::convergence_errorif M.u_diagonals_usable is false

◆ iluk_apply() [2/2]

template<Backend B, typename T>
Event batchlas::iluk_apply ( Queue & ctx,
const ILUKPreconditioner< T > & M,
const MatrixView< T, MatrixFormat::Dense > & rhs,
const MatrixView< T, MatrixFormat::Dense > & out,
Span< std::byte > workspace = Span<std::byte>() )

iluk_apply on an owning factor; forwards M.view().

Definition at line 222 of file iluk.hh.

◆ spmm()

template<Backend B, typename T, MatrixFormat MFormat>
Event batchlas::spmm ( Queue & ctx,
const MatrixView< T, MFormat > & A,
const MatrixView< T, MatrixFormat::Dense > & descrB,
const MatrixView< T, MatrixFormat::Dense > & descrC,
T alpha,
T beta,
Transpose transA,
Transpose transB,
Span< std::byte > workspace )

Batched sparse-times-dense matrix multiply.

For every batch item computes

\[ C := \alpha \, \mathrm{op}(A) \, \mathrm{op}(B) + \beta \, C \]

with A sparse (CSR) and B, C dense; \(\mathrm{op}(X)\) is \(X\), \(X^T\) or \(X^H\) according to transA / transB. With \(\mathrm{op}(A)\) m x k and \(\mathrm{op}(B)\) k x n, C is m x n.

Takes a caller-supplied workspace, sized by spmm_buffer_size with the same arguments. Lease it from the queue's arena with ctx.workspace(bytes). Also callable with owning Matrix arguments and without B (taken from ctx.backend()); spell a partial explicit call spmm<Backend::CUDA>(...) and let T and MFormat deduce.

Template Parameters
Bbackend the call is compiled for; must match ctx's device
Tscalar type: float, double, std::complex<float> or std::complex<double>
MFormatstorage format of A; only MatrixFormat::CSR is instantiated
Parameters
ctxqueue the work is enqueued on
Abatch of sparse matrices; not modified
descrBbatch of dense k x n (NoTrans) or n x k matrices; not modified
descrCbatch of dense m x n matrices; input scaled by beta, overwritten with the result
alphascale of the product
betascale of the input C
transAop() applied to A
transBop() applied to B
workspacedevice-accessible scratch of at least spmm_buffer_size bytes
Returns
event of the last enqueued kernel; C is valid once it completes
Precondition
All operands have the same batch size and conforming shapes per item.
Exceptions
batchlas::NoRouteErrorin a build without the vendor sparse library for B when the native kernel does not support the call (a heterogeneous batch, or negative extents).
Note
No argument validation is done up front: a shape the native kernel refuses goes to the vendor library, which reports it.
On Backend::ROCM a real T with ConjTrans is suspected to give wrong results (known defect 4, docs/design/known-defects.md); use Trans.
See also
spmm_buffer_size, docs/perf/spmm.md

Topics

 Sparse: lower-level API
 ILU(k) level scheduling, test-matrix generation and workspace queries.

Classes

struct  batchlas::ILUKParams< T >
 Parameters of an incomplete LU factorization with level-of-fill k, ILU(k). More...
struct  batchlas::ILUKView< T >
 Non-owning description of a factored ILU(k) preconditioner. More...
struct  batchlas::ILUKPreconditioner< T >
 Owning ILU(k) factor of a batch of CSR matrices sharing one pattern. More...