Repository navigation
Fused solve: in-front pivot orders and 2×2 blocks of a pivoted LDLᵀ factor (refs #167, stage 1) - #203
Conversation
…LDLᵀ factor (refs #167) Stage 1 of the pivoted fused pipeline: the partitioned-inverse fused solve runs on a factor with in-front pivoting (pivot_type 'D' or Bunch-Kaufman, as the stock LDLᵀ leaves it in numeric.piv/pivot_kind). The forward inverse GEMV of each front reads y through the front's pivot order (z = inv(L11) Pᵀ y), the backward one scatters x back through it, the fronts wider than 256 take the LDLᵀ solve kind (the dense calls with _piv_dense! around them) and the diagonal step goes through diagonal_sweep! (1x1 and 2x2). Compile-time switch (Val) per sweep: the no-pivot/Cholesky instantiation has the same launches and arithmetic and never reads piv. Internal entry point: FusedSolve.pivoted, set with Fused.set_pivoted!(fs, true); DirectSolver solve_alg = "algo1", FusedSolver and KKTSolver are unchanged. The bench-only chain kernel refuses a pivoted factor (NotSupportedError). New testset in test_solve_algo1.jl against the stock solve on the same factor and the residual, with interchanges asserted in subtrees, narrow fronts, the level-batched entries and the wide front (new helper kkt_forest_matrix in test/matrices.jl). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MsLzHkzHJjM2g5P6ZyZKhr
| fwd1_kernel!(backend, WG)(fargs(a, b_ - a + 1)..., Val(false), Val(WG), Val(false); ndrange = WG * (b_ - a + 1)) | ||
| fwd1_kernel!(backend, WG)(fargs(a, b_ - a + 1)..., Val(false), Val(WG), Val(true), N.piv, pvv; | ||
| ndrange = WG * (b_ - a + 1)) : | ||
| fwd1_kernel!(backend, WG)(fargs(a, b_ - a + 1)..., Val(false), Val(WG), Val(false), N.piv, pvv; |
There was a problem hiding this comment.
nit (non-blocking): _dense_kind(Val(true)) hard-codes _SV_LDL_HERM, so the wide-front dense calls of a pivoted factor always run the Hermitian kind (tr = 'C'). That is correct today because the fused solve is real-only (_check_algo1 refuses complex, FusedSolver too), and algo2_diagonal! already picks the structure-aware kind through diagonal_sweep!. If the complex restriction is ever lifted, a complex symmetric "S" factor would need _SV_LDL_SYM here; SDS._solve_kind(S, eltype(ws.Y)) would give the right kind in both cases with no runtime cost beyond what _bwd_dense! already pays. Fine to leave as is for stage 1.
There was a problem hiding this comment.
VERDICT: APPROVE (head c9fa9ce)
Reviewed the diff (src/fused.jl, test/matrices.jl, test/test_solve_algo1.jl) against AGENTS.md, PLAN.md §2.5/§2.7 and the stock LDLᵀ solve (src/solve/sweeps.jl, src/numeric/storage.jl).
Scope. Not a TASKS.md task but a maintenance PR for #167, as the body states and as the owner set up for #200/#202; PLAN.md, TASKS.md and Manifest.toml untouched; no public name, parameter or phase string changed. The public front ends still refuse pivoting with the fused solve (_check_algo1_pivoting, FusedSolver); set_pivoted! is internal and reached only from the test. The existing bench caller (bench/e2e/fused_probe.jl) keeps working through the new defaulted arguments.
Correctness. The folded permutation matches _sv_piv_apply! exactly: forward t = inv(L₁₁) · y[piv[c0 + j]] (stock: Y[c0 + k] = saved[piv[c0 + k] − c0]), backward Y[piv[c0 + k]] = x_k (stock: Y[c0 + p] = saved[k]). In all four kernels (fwd1, fwd2, bwd1, bwd2) every read of the front's slice of Y precedes the barrier that precedes the writes, and the rows below (rowval) stay in the pre-pivot numbering, so children and ancestors see the same numbering as in the level sweeps. The yb variant of fwd2 indexes the local copy with piv − c0 ∈ 1:w. The L₁₁ inverses are computed from the unit-lower panel exactly as the stock TRSV reads it, so 2×2 blocks need no special case there; the diagonal step goes through diagonal_sweep!, which handles PIVOT_KIND_2X2_*. Wide fronts use the stock _SV_LDL_HERM path; _piv_dense! uses rows 1:w of the front's ws.U buffer, which the fused deterministic pull leaves untouched (it zeroes and accumulates w+1:f only), and ws.U is always allocated so the non-deterministic path is safe too. _pj is Int-typed and Val-dispatched; the no-pivot instantiation never touches piv. The chain kernels refuse pivoting with NotSupportedError instead of solving wrongly. Graph capture is per (det, pivoted) variant and dropped on set_pivoted!.
Conventions. Generic T/INT, 1-D workgroups, @localmem sized by constants, no new atomics, no host sync or allocation added to the sweeps (compile-time Val branches), dense calls through the existing interface, no @allowscalar, errors from src/errors.jl.
Tests. The new testset runs on ALGO1_BACKENDS (GPU backends, as the rest of the file) over eltypes_among((Float32, Float64)), with Random.seed!(666), tol(T) and relres; it asserts interchanges in subtrees, narrow and wide fronts and the level-batched entries, non-vacuity (the unpivoted fused solve is wrong), agreement with the stock solve for both all_segments and both det, bitwise reproducibility and the sub-phase composition, and the chain-kernel refusal. The kkt_forest_matrix helper lives in test/matrices.jl. No @test_broken, nothing weakened. CI: CPU, CUDA, AMDGPU, Aurora and docs all green, consistent with the body's counts.
Blocking findings: none. One nit (non-blocking) inline on _dense_kind hard-coding the Hermitian kind.
…d element type (PR #203 review) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MsLzHkzHJjM2g5P6ZyZKhr
Refs #167. Stage 1 of three maintenance PRs for it (pivot-aware fused solve, then diagonal pivoting in the fused factorization, then hybrid Bunch–Kaufman). Not a
TASKS.mdtask.What changed
src/fused.jl): the row interchanges ofpivot_type = 'D'and the interchanges and 2×2 blocks of Bunch–Kaufman, on a factor in the stock layout (N.piv,N.pivot_kind).L₁₁readsythrough the front's pivot order, after the children's updates have arrived; the result is stored in factor order.diagonal_sweep!, which handles 1×1 and 2×2 blocks._pj.FusedSolvehas a fieldpivoted, set throughFused.set_pivoted!.FusedSolver,KKTSolverandsolve_alg = "algo1"refuse pivoting as before; stage 2 supplies the factorization and lifts that. No CHANGELOG entry.test/test_solve_algo1.jl(stock pivoted factorization, fused solve), helperkkt_forest_matrixintest/matrices.jl. It asserts interchanges in subtrees, narrow fronts, the wide front and the level-batched entries, that the solve without the pivot order is wrong, agreement with the stock solve withintol(T), and bitwise reproducibility in deterministic mode.The prototype's failure (#135)
The prototype's testset
fused solve on a pivoted factorfailed with a deterministic wrong answer, recorded in #167 as a logic bug in the solve. Two of its three configurations (no segment, and the chain kernel on the merged segment) never solve the regime-A subtrees, with or without pivoting: onmainwithpivot_type = 'N'they give a relative residual of 0.48 to 56 on matrices with subtrees, where the counter sweep gives 2e-14. So the testset was invalid; no kernel bug was found in the prototype.Measurements (CUDA, H200, smoke scripts)
Float32,Float64). Against the stock solve on the same factor: at most 1e-15 inFloat64, 8e-7 inFloat32.'D'and'B'; thresholds 0.01, 0.1, 0.5; both deterministic modes; graph capture and replay; refactorization without rebuilding the plan), 49 configurations against a host UMFPACK reference: the fused solve matches the stock solve on the same factor in every row, and the solve without the pivot order is wrong by 5e2 or more in every row.L(for instance'D'at threshold 0.1) the fused solve is 2 to 100 times less accurate than the stock solve before refinement, as expected from the explicit inverse ofL₁₁; three refinement steps bring both to 2e-14 on the case tried.mainon six solver/matrix pairs.Tests
Run as plain scripts with the
runtests.jlsetup, CPU backend and CUDA:test_solve_algo1all element types 582 of 582; inFloat64test_fused516 of 516,test_kkt977 of 977,test_solve304 of 304,test_refinement279 of 279. Not run locally: the other files,test_allocations,Int64indices on the new path, AMDGPU, oneAPI; CI runs them.Deviations
PLAN.mddefines the fused pipeline without pivoting; this follows the owner's decision to do #167 as maintenance PRs.🤖 Generated with Claude Code
https://claude.ai/code/session_01MsLzHkzHJjM2g5P6ZyZKhr