Matrix Decompositions, Solvers, and GPU Acceleration
Direct Solvers for Linear Systems
Solving via explicit matrix inversion () is both numerically unstable and computationally inefficient. Production solvers factorize into structured triangular, orthogonal, or diagonal matrices.
LU Decomposition with Partial Pivoting
For a general non-singular matrix , Gaussian elimination with row pivoting computes:
- : Permutation matrix tracking row interchanges.
- : Unit lower-triangular matrix ().
- : Upper-triangular matrix.
Computational Cost:
- Factorization: FLOPs ( multiply-adds).
- Forward substitution (): FLOPs.
- Backward substitution (): FLOPs.
Pivoting Strategy: At column , the pivot is chosen as and swapped into the diagonal position. This ensures multiplier magnitudes satisfy , bounding growth factors during Gaussian elimination.
Cholesky Factorization
When is Symmetric Positive Definite ( and ), factors uniquely into:
where is a lower-triangular matrix with strictly positive diagonal elements:
Computational Cost: FLOPs ( multiply-adds), exactly half the cost of LU factorization. Pivoting is not required for numerical stability.
QR Decomposition and Least Squares
For rectangular with :
- (full) or (thin/economy): Orthogonal matrix ().
- (full) or (thin): Upper-triangular matrix.
Numerical Implementations
- Householder Reflections: Applies orthogonal reflectors to annihilate subdiagonal columns. Cost: FLOPs. Numerically backward stable.
- Givens Rotations: Applies orthogonal rotations to eliminate specific non-zero elements. Ideal for banded or sparse structures.
Linear Least Squares
To solve :
Unlike forming the normal equations , which squares the condition number (), QR operates directly on and preserves the original condition number .
Spectral Decompositions
Eigendecomposition
For square , a non-zero vector satisfying is an eigenvector associated with eigenvalue .
If has linearly independent eigenvectors, it is diagonalizable:
where and .
Spectral Theorem: If , then all , and there exists an orthonormal eigenbasis :
Singular Value Decomposition (SVD)
For any matrix with rank :
- : Orthogonal matrix whose columns are eigenvectors of .
- : Diagonal matrix of ordered singular values .
- : Orthogonal matrix whose columns are eigenvectors of .
The vectors satisfy the mapping relations:
Low-Rank Approximation (Eckart-Young-Mirsky Theorem)
The truncated rank- approximation ():
minimizes the approximation error over all matrices of rank at most :
Accelerator Memory Hierarchy and Tiling
On hardware accelerators (e.g., AMD ROCm / CDNA / RDNA, NVIDIA CUDA), high computational throughput relies on structured data reuse across memory levels:
[ Global Memory: HBM / GDDR ] ~1.5 - 5.3 TB/s
│
▼ Tile load into on-chip scratchpad
[ Local Data Share (LDS) / Shared Memory ] ~15 - 30 TB/s
│
▼ Tile load into registers
[ Vector Register File (VGPRs) ] ~100+ TB/s
│
▼ Direct operand feed
[ Matrix Core Engine / Tensor Cores ]
GEMM Tiling Hierarchies
- Workgroup / Thread-Block Tile: Partitions into an submatrix. A workgroup cooperatively loads and slices of and into LDS/shared memory.
- Wavefront / Warp Tile: Subdivides the block tile across waves executing matrix-multiply instructions (e.g., AMD
v_mfmaor NVIDIAmma.sync). - Thread Register Tile: Accumulators stay in vector registers across the entire -dimension accumulation loop, preventing memory spills.
Floating-Point Non-Associativity and Summation
In IEEE-754 floating-point arithmetic, addition is non-associative:
Varying execution scheduling or reduction tree topologies across GPU workgroups changes the summation order and causes non-deterministic results.
Compensated Summation
Kahan compensated summation maintains a running compensation variable to accumulate lost low-order bits:
float kahan_sum(const float* data, size_t n) {
float sum = 0.0f;
float c = 0.0f;
for (size_t i = 0; i < n; ++i) {
float y = data[i] - c;
float t = sum + y;
c = (t - sum) - y;
sum = t;
}
return sum;
}
Compiler Optimization Caveat: Compilers with aggressive floating-point reassociation flags enabled (
-ffast-math,-Ofast, or#pragma STDC FP_CONTRACT ON) can optimize(t - sum) - yalgebraically to zero. In production code, memory fences, volatile reads, or#pragma STDC FP_CONTRACT OFFare required to preserve compensation semantics.
Reproducible Accumulators
When bit-level determinism is required across variable thread counts or distributed nodes, reproducible accumulation techniques include:
- Demmel-Nguyen multi-tier binning: Accumulating floating-point values into fixed-point exponent bins.
- Superaccumulators (Kulisch): Long fixed-point registers (e.g., hundreds of bits) that cover the full dynamic exponent range without intermediate roundoff.