Fused pipeline
FusedSolver runs the fused factorization and partitioned-inverse solve of SparseDirectSolver.Fused (src/fused.jl) behind the verbs of DirectSolver: the same execute! phases, setparam!, getparam and SparseDirectSolver.update!, for one right-hand side, on a GPU backend, for "SPD" and "S" real matrices (L D Lᵀ with static pivoting: pivot replacement under pivot_epsilon and pivot_sign, optionally with a matching; with pivot_type = 'D' also 1×1 diagonal pivoting inside the regime-A subtrees and the fronts of width ≤ 64, the wider fronts without interchanges), with plain iterative refinement of the solve (ir_n_steps). It is the inner solver that KKTSolver selects on GPU backends with forward progress (KKT solver), and so the default path of MadNLP's binding (MadNLP); Performance says when to use it.
using SparseDirectSolver, CUDA, CUDA.CUSPARSE
Ad = CuSparseMatrixCSR(tril(A)) # A: SPD, on the host
F = FusedSolver(Ad, "SPD", 'L')
analyze!(F) # ordering, symbolic analysis, the fused plans
factorize!(F) # the fused factorization
bd = CuVector(b)
x = F \ bd # partitioned-inverse solve
getparam(F, "info") # 0 on success
Ad.nzVal .*= 2 # new values in the same buffer (the IPM loop)
refactorize!(F)
solve!(F, x, bd)SparseDirectSolver.Fused.FusedSolver — Type
FusedSolver(A, structure, view; tuning = nothing, index = 'O')
FusedSolver(rowptr, colval, nzval, structure, view; tuning = nothing, index = 'O')The fused pipeline of SparseDirectSolver.Fused (dependency-counter factorization mega-kernel and partitioned-inverse solve, the fused pipeline of KKTSolver) as an AbstractDirectSolver, driven by the same verbs as DirectSolver: execute!, analyze!, factorize!, refactorize!, solve!, setparam!, getparam, update!, ldiv! and \ for one right-hand side. A is anything DirectSolver accepts with these arguments (a CSR, CuSparseMatrixCSR/CuSparseMatrixCSC, ROCSparseMatrixCSR, …) on a GPU backend; the values alias the caller's nzval, so writing new values into it and calling refactorize! is the interior-point loop (update! with the same pattern is forwarded).
structure is "SPD" (fused Cholesky) or "S" (fused LDLᵀ with static pivoting: pivot_type = 'N', a pivot d with |d| < pivot_epsilon replaced by ±pivot_epsilon as in the stock no-pivot LDLᵀ, optionally with a matching; pivot_pairs = "none" without a matching or with "algo1"–"algo4", "default" with "algo5"/"algo6", so that the pairs of its cycles shape the ordering). "S" also takes pivot_type = 'D', 1×1 diagonal pivoting inside the fronts, with the pivot choice of the stock LDLᵀ (DirectSolver, pivot_threshold acceptance against the whole remaining front column, the acceptable diagonal of largest modulus otherwise, interchanges inside the fully-summed block, a tiny pivot replaced by ±pivot_epsilon with pivot_sign), in the regime-A subtrees and in the fronts of width ≤ 64; the fronts wider than 64 (factored in 64-column panels by the fused kernel) are factored without interchanges, with the static replacement of pivot_type = 'N'. On a matrix whose fronts are all at most 64 wide the pivot order and D are those of the stock 'D' factorization of the same analysis (up to rounding); with wide fronts they differ there and in the fronts above them (the inertia, counted from D, agrees unless pivots are replaced). The fused solve applies the pivot order of the factor. tuning is an SDSTuning, nothing meaning default_tuning(backend), resolved by resolve_tuning; the constructor applies it to the inner DirectSolver (amalgamation, regime-C width and rows, subtree parallelism and budgets, reordering_alg = "algo4", nd_nseps, nd_seed). The inner solver is the field inner.
Phases (execute!(phase, F, X, B; asynchronous = true)):
"reordering","symbolic_factorization","analysis": the inner solver's phase; the symbolic part then factorizes and solves once with the inner solver (stock kernels, it sizes the solve workspace) and builds the fused factorization plan, the per-front inverses and the fused solve segments.XandBare not used."factorization","refactorization"(needs a previous"factorization"): the fused factorization of the current values, then the inverses of the diagonal blocks; sets"info"(0, or the original column of the first failed pivot: a non-positive Cholesky pivot, or for"S"a zero pivot underpivot_epsilon = 0, or a non-finite pivot). A failed factorization does not throw. Unlike the stock kernel, which replaces a NaN pivot and accepts an infinite one, the fused LDLᵀ fails the factorization on both under anypivot_epsilon, so a NaN or Inf in the matrix is reported rather than factored (withpivot_type = 'D'only in the fronts wider than 64: the subtrees and the narrow fronts then run the stock pivot rule, NaN and Inf included)."S"factors its wide fronts in the fused kernel under eitherwidesstrategy (a front's pivots may take both signs), so the in-kernel wide-front limit applies to it on every part: a front with more than1023 · 32rows below a panel raisesNotSupportedErrorat analysis."solve":X = A⁻¹ Bwith the partitioned-inverse solve, for a vector (or ann × 1matrix) on the solver's backend;X === Bis allowed. The solve is the one ofDirectSolver'ssolve_alg = "algo1"(one driver, T36). Withir_n_steps = k > 0it is followed byksteps of plain iterative refinement, as onDirectSolver: the residualB - A Xof the matrix values the caller passed (neither scaled by the matching nor with the replaced pivots), its correction through the fused solve, added toX. The steps run without a host synchronization (noir_tolearly exit); the refinement workspace is allocated by the analysis, or bysetparam!(F, "ir_n_steps", k)after it.
setparam! accepts "user_perm", "reordering_alg", "nd_nseps", "nd_seed", "pivot_epsilon" (the pivot epsilon of both modes, default 1e-13 for Float64 and 1e-5 for Float32; 0 replaces no "S" pivot), and for "S" "pivot_sign" (the sign a replaced pivot takes, per row of the matrix), "pivot_type" ('N', the default, or 'D'), "pivot_threshold" (the acceptance threshold of 'D', default 0.01) and "matching_alg" ("algo1"–"algo6"; the values are scaled before the fused factorization and the solve undoes the scaling), all read by the next analysis (the fused plans capture pivot_epsilon, pivot_sign, pivot_type and pivot_threshold there; a refactorization with new values chooses a new pivot sequence with the same plans), and "deterministic_mode" and "ir_n_steps" (default 0: no refinement), read at every solve. The factorization is deterministic under either mode: the children of a parent add in child_list order and the panels of an in-kernel wide front apply in order, with plain adds, so factor and D are bitwise reproducible for the same values. deterministic_mode = 0 (the default) scatters the forward-solve updates with atomic adds, so the solution can differ in the last bits from run to run; deterministic_mode = 1 runs the forward sweep without atomics (every front writes its update to its own buffer, the parent pulls its children's buffers in order), and the solution is bitwise reproducible too. getparam returns "info", "inertia" ((npos, nneg); "SPD": the positive pivots and 0; "S": the counts of positive and negative entries of D, a replaced pivot counted with the sign it was given), "npivots" ("S": the number of replaced pivots, valid when "info" is 0), the analysis data "perm_reorder_row", "perm_reorder_col", "perm_row", "perm_col", "lu_nnz", "flops", "nsuperpanels" of the inner solver, "ir_n_steps" (the refinement steps of the last solve, the configured value before the first solve, as on DirectSolver), with a matching "perm_matching", "scale_row" and "scale_col", "memory_estimates" (the inner solver's, plus after the analysis the fused plans' device buffers: slot 13 the private contribution blocks of the fused factorization, slot 14 every other buffer of the plans, both added to slots 1, 2 and 5), and the configuration parameters.
Everything the pipeline does not do raises NotSupportedError, at construction or in the phase, never a silent switch to the stock path: the KernelAbstractions CPU() backend (the dependency-counter kernels spin on resident workgroups, which the CPU backend runs one after another) and any other backend without inter-workgroup forward progress (Metal), complex element types, the structures "HPD", "H" and "G", a uniform batch (nbatch > 1), nrhs > 1, a transposed solve (solve_mode ≠ 0), the solve sub-phases ("solve_fwd_perm" … "solve_refinement", the Schur phases), Schur mode, "SPD" with matching_alg ≠ "default", ir_mode = "fgmres", ir_tol > 0, a factor_precision other than the working precision, "S" with a pivot_type other than 'N' and 'D' (Bunch–Kaufman) or pivot_epsilon_alg ≠ "default", "pivot_sign", "pivot_type" and "pivot_threshold" on "SPD", a matrix without a front of width ≤ 256 for the fused solve, and every setparam! name not listed above. The options of the inner solver are checked again at the analysis. DirectSolver remains the general solver.
The performance knobs of the pipeline live in one bundle, a platform's tuning being a single value; how each field was measured and the per-architecture champions are in bench/ARCH-TUNING.md. default_tuning gives oneAPI, Metal and any other backend that reports no CUDA thread count per multiprocessor the AMD profile.
SparseDirectSolver.Fused.SDSTuning — Type
SDSTuningEvery performance knob of the fused pipeline in one immutable bundle, so a platform's tuning is a single value (see bench/ARCH-TUNING.md for how each field was measured and the per-architecture champions). All fields are runtime parameters — no environment variables, no recompilation.
The T34 fields: solve_workgroup is the workgroup size of the fused solve sweeps (a multiple of 32 in 32:256); wide_host_min puts the wide fronts wider than it on the host vendor path in a :merged Cholesky plan (the per-front wide strategy; typemax(Int), the default, keeps every wide front in-kernel; ignored for "S"); graph_max_n replays the refactorization and the solve sweeps from a CUDA graph when n <= graph_max_n, vendor dense calls in the captured range included (the host-wide fronts, the solve fronts wider than 256; #174); 0, the default, never captures (no measured gain, see bench/ARCH-TUNING.md).
SparseDirectSolver.Fused.default_tuning — Function
default_tuning(backend) -> SDSTuningThe measured per-architecture defaults — the single place they live. 2048-threads/SM NVIDIA parts (sm70/80/90): host wides, 16K budgets, fused-solve workgroup 128 (T34, measured on an H200; sm70/80 not re-measured). 1536-thread parts (sm86/89, Blackwell workstation): merged wides, 8K budgets, solve workgroup 64 (T34 did not measure them). AMD (gfx906-measured): merged, 8K, workgroup 256, spin cap 16. A backend without a CUDA resident-thread count (`maxthreadspermultiprocessor` returns 0: AMDGPU, oneAPI, Metal, the CPU backend, anything but CUDA) gets this AMD profile.
SparseDirectSolver.Fused.resolve_tuning — Function
resolve_tuning(t::SDSTuning, backend) -> SDSTuningt with wides = :auto replaced by the wide-front strategy of default_tuning(backend); any other t is returned as is.