Skip to content

Fused LDLᵀ: diagonal pivoting, KKTSolver pivoting = :diagonal (refs #167, stage 2) - #204

Merged
michel2323 merged 5 commits into
mainfrom
maint/fused-diagonal-pivoting
Nov 17, 2026
Merged

michel2323 merged 5 commits into
mainfrom
maint/fused-diagonal-pivoting

Conversation

@michel2323

@michel2323 michel2323 commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Refs #167. Stage 2 of three maintenance PRs for it, rebased on main after #202 and #203 were merged.

What changed

  • Diagonal pivoting in the fused factorization (src/fused.jl, structure "S", pivot_type = 'D'):
    • Regime-A subtrees run the stock subtree LDLᵀ kernel on the fused subtree list; the factor of a subtree is bitwise the stock one.
    • Narrow fronts (width ≤ 64) run the stock pivot steps inside the fused kernel's panel role, behind a compile-time switch: threshold test against the whole remaining column, interchanges inside the fully-summed block, replacement with pivot_epsilon and pivot_sign, and piv, pivot_kind in the stock layout. The panel factors the rows below itself, so the pivot plan has no TRSM roles.
    • Wide fronts (width > 64) are factored without interchanges, with the static pivot replacement, and write an identity pivot order (as In-front pivoting (diagonal and Bunch–Kaufman) for the fused pipeline: state of the closed prototypes #135 and #139 #167 recommends for the hybrid mode).
    • Without pivoting the switch compiles the new code away.
  • FusedSolver accepts pivot_type 'N' or 'D' and pivot_threshold on "S"; 'A', 'B', 'L' raise NotSupportedError. Refactorization gives a new pivot sequence on the same plans; captured CUDA graphs stay valid since the pivot decisions and piv live on the device.
  • KKTSolver gains pivoting = :diagonal (:ldl only, with pivot_threshold): the fused pipeline wherever :none is fused, pivot_type = 'D' on the stock pipeline. MadNLP's binding can then pass it instead of setting pivot_type on the inner solver.
  • Docs (docs/src/lib/fused.md, docs/src/lib/kkt.md, docs/src/man/madnlp.md), CHANGELOG.md (Added, under [0.4.1] - unreleased; no further version bump).

Pivot sequence against the stock pipeline

Equal outside the wide fronts and their ancestors on well-conditioned generators, in Float32 and Float64; the tests compare it exactly there. On strongly ill-conditioned matrices or with exact ties a few narrow-front pivots differ, since rounding differences in the assembly decide near-ties; those tests compare inertia, npivots and residuals.

Tests

No existing assertion was changed or removed. Two parametrizations in test/test_kkt.jl were extended with :diagonal. New testsets in test/test_fused.jl (against the stock factorization on the same analysis: interchanges asserted in subtrees and narrow fronts, identity order in wide fronts, exact piv, inertia, npivots, pivot-changing refactorization, bitwise reproducibility, graph replay, Int64 indices, zero-pivot replacement, matching "algo5"/"algo6" with ir_n_steps = 2) and in test/test_kkt.jl (keyword validation, pipeline selection, a configuration as MadNLP's).

Run as plain scripts with the runtests.jl setup, CPU backend and CUDA (H200): test_fused 684 of 684 in Float64 and in Float32; test_kkt 6389 of 6389; in Float64 test_solve_algo1 287 of 287, test_solve 304 of 304, test_refinement 279 of 279, test_numeric_ldlt 919 of 919.

Timing (H200, one GPU through Slurm, median of 20, Float64)

KKTSolver with matching = "algo6", pivot_epsilon = 1e-10, no refinement.

Matrix Configuration Factorization Solve
78k ACOPF condensed KKT (n = 674,562) fused, no pivoting (base branch) 24.8 ms 2.08 ms
fused, no pivoting (this branch) 24.8 ms 2.08 ms
fused, diagonal 43.4 ms (1.75×) 2.24 ms
stock, diagonal 207.2 ms 11.81 ms
case1354_pegase_k2_10 (n = 33,811) fused, no pivoting (base branch) 1.7 ms 0.32 ms
fused, no pivoting (this branch) 1.7 ms 0.31 ms
fused, diagonal 4.9 ms (2.9×) 0.34 ms
stock, diagonal 12.2 ms 1.27 ms
  • The unpivoted fused path is unchanged against the base branch.
  • Fused diagonal pivoting is 4.8 times faster than the stock one on the 78k matrix and 2.5 times on the smaller one, in the factorization; 5.3 and 3.7 times in the solve.
  • On case1354_pegase_k2_10 the residual without refinement is 2.0e-08 with diagonal pivoting (4 replaced pivots) against 4.3e-06 without pivoting (20 replaced pivots).
  • The 78k matrix is too ill-conditioned for a residual on a random right-hand side to say anything without refinement (host CHOLMOD: 1.9e-02; stock diagonal: 1.5e-02; fused, with or without pivoting and on the base branch alike: 25).

Not done

  • Not run locally: the other test files, test_allocations, the docs build, AMDGPU, oneAPI.
  • Aurora: the host-allocation check of the unpivoted fused cycle (test/test_fused.jl, the testset with ir_n_steps = 2) measured 101,384 and 101,624 bytes against the earlier oneAPI budget of 98,304. The kernel launch now has 56 arguments (50 before), and oneAPI.jl allocates about 1 KB per argument for a launch with 31 or more; the oneAPI budget is 112 KiB since dab6205, and the Aurora leg passes. Details in oneAPI: host allocation of the unpivoted fused cycle exceeds its budget after the diagonal-pivoting change (PR #204) #205.

Deviations

PLAN.md defines 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

michel2323 and others added 2 commits November 16, 2026 11:06
…zation (refs #167)

FusedSolver "S" takes pivot_type = 'D' and pivot_threshold. The regime-A
subtrees run the stock subtree LDLᵀ kernel; the narrow panels (PANEL_B/C,
width <= 64) run the stock pivot steps (_lt_pass1!/decide/pass3/swap/update/
finalize) on the split front (F11 in sh, rows below in the panel), factor the
rows below themselves (no TRSM role) and write piv/pivot_kind in the stock
layout; the in-kernel wide fronts (> 64) factor without interchanges with
the static replacement and an identity piv. Compile-time Val(PIV): the
no-pivot kernels are unchanged. The fused solve applies the pivot order
(set_pivoted!); refactorization picks a new pivot sequence with the same
plans; graph replay unaffected (pivots read on the device).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MsLzHkzHJjM2g5P6ZyZKhr
:diagonal (:ldl only, pivot_threshold allowed) is pivot_type = 'D'; fused
where :none is fused (fused = nothing: CUDA/AMDGPU/oneAPI fused, CPU/Metal
stock; fused = true/false honoured; the #200 fallback keeps 'D'). Docs,
MadNLP options table and CHANGELOG (0.4.1, Added).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MsLzHkzHJjM2g5P6ZyZKhr
@michel2323
michel2323 force-pushed the maint/fused-diagonal-pivoting branch from 91837fb to 12090c9 Compare November 16, 2026 17:06
@michel2323
michel2323 marked this pull request as ready for review November 16, 2026 17:07
@michel2323 michel2323 added the claude:pr PR opened by the Claude implementer; handled by the Claude pipeline label Nov 16, 2026
Comment thread src/kkt.jl
Comment on lines +217 to +221
# diagonal pivoting on either pipeline (the fused one: the subtrees and the narrow fronts, see FusedSolver)
if diagonal
setparam!(inner, "pivot_type", 'D')
pivot_threshold === nothing || setparam!(inner, "pivot_threshold", pivot_threshold)
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit (non-blocking): on the stock pipeline pivot_type is already set to 'D' at line 210 (setparam!(d, "pivot_type", diagonal ? 'D' : 'N')), so this block repeats it; only the fused pipeline and pivot_threshold need it. Harmless (the second call is a no-op), but one of the two writes could go, e.g. keep line 210 as setparam!(d, "pivot_type", 'N') under elseif ldl && !diagonal, or drop the diagonal ? 'D' : 'N' and let this block be the single place that turns diagonal pivoting on for both pipelines.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: APPROVE (head 12090c9)

Reviewed against AGENTS.md, issue #167 (the stage-2 scope of the owner's maintenance plan), PLAN.md §2.4/§2.7 and the diff (src/fused.jl, src/kkt.jl, test/test_fused.jl, test/test_kkt.jl, docs, CHANGELOG). Maintenance PR, not a TASKS.md task: PLAN.md, TASKS.md, Manifest.toml untouched; the PLAN deviation is stated in the body.

What I checked

  • Kernel (fused_fact_kernel!, PIV branch): the narrow panel runs the stock regime-B pivot steps (_lt_reset!/_lt_init_piv!/_lt_pass1!/_lt_stage1!/_lt_decide1!/_lt_pass3!/_lt_decide3!/_lt_swap!/_lt_update!/_lt_finalize!/_lt_stage!) on a _SplitFront with W = 64 over (sh, factor); the offsets match the fused panel indexing (front_ptr[v] - 1 + (j-1)f + i); red/redi are sized 3·WG/2·WG as the stock kernel; ctl, lpv collapse to one entry without pivoting. Barriers are uniform (the PHASE == 3 branch reads a local word after a barrier, as stock). After _lt_finalize! the sh diagonal holds D and the panel rows below hold L₂₁, which is what _front_ldl_syrk! and the TILE roles consume; the Schur complement is invariant to the in-block interchange and the CB row indexing is untouched, so extend-add is unchanged.
  • Dependency counters: emit_split sets trsm_left[v] = 1 with no TRSM roles; the panel decrements it after the fence and signals cb_done/arrived only when tiles_base[v] == 0, mirroring ROLE_TRSM; TILE roles spin on trsm_left == 0. Consistent.
  • Pivot-sign convention: the stock kernels read psign[perm[piv[g]]] (original row); psgo is Int8.(ps) unpermuted, the wide fronts use the factor-ordered psg with identity piv, so both agree. d has 2n entries (d_len = 2n), piv is Int32 storage, the d[n+g] write of _lt_select! is in bounds.
  • Regime A: subtree_ldlt_kernel! with the same LB - SUBTREE_LOCAL_RESERVE_LDLT budget as the fused LDL launcher and the stock one; stack/cb_ptr output as the no-pivot kernel.
  • Inertia/npivots of a FusedSolver are read from d/pivot_kind, which 1×1 pivoting keeps valid; prm.scaled = false is guaranteed by the existing refusal of pivot_epsilon_alg = "algo1".
  • FusedSolver.setparam!("pivot_type") restores the old value when refusing 'A'/'B'/'L'; _check_fused_options re-checks at analysis; set_pivoted! is set at analysis and at each factorization.
  • KKTSolver: :diagonal validation, pipeline selection (!bk && forward_progress), pivot_threshold gating, and the #200 fallback keeps pivot_type = 'D' since it lives in the inner options. One redundant setparam! on the stock path (inline nit).
  • Tests: no existing assertion weakened; the new testsets use eltypes_among((Float32, Float64)) (the fused LDL is real-only), FUSED_BACKENDS, Random.seed!(666), tol(T)/growth_tol and the shared helpers; they compare the pivot order exactly outside the wide fronts and their ancestors, identity order in the wide fronts, D, inertia, npivots, zero-pivot replacement with pivot_sign, the pivot_epsilon = 0 failure, refactorization with a new pivot sequence, bitwise reproducibility, graph replay, Int64 indices, and "algo5"/"algo6" with refinement. The reported counts are plausible for the added parametrizations.

Blocking findings: none.

For the owner (non-blocking):

  • The body says the PR is a draft until the Aurora host-allocation overshoot of the unpivoted fused cycle (101,384 / 101,624 vs 98,304 bytes on oneAPI) is traced, but the PR is not marked draft. The pivoted path adds six kernel arguments (56 now) to every fused launch, the likely source on oneAPI; ALCF / LTS stack (Aurora) was still pending at review time and would fail test_fused if the measurement holds. The CUDA, AMDGPU and CPU legs were pending too.
  • Performance, by design: a pivoted narrow panel factors all rows below itself in one workgroup (needed for the threshold test against the whole column), where the no-pivot plan spreads that over cld(m, wgf) TRSM roles; the body's 1.75× / 2.9× factorization cost reflects it.

michel2323 and others added 3 commits November 16, 2026 22:21
… with 31 or more arguments (#205)

The fused factorization kernel has 56 arguments since the diagonal pivoting
(50 before). oneAPI.jl converts the arguments of a launch with Base's map,
which is not inferred for a tuple of 32 or more elements (31 arguments and
the KernelAbstractions context); the launch then allocates about 1 KB per
argument: 42 KB for this one launch, 34-36 KB before. Measured on Aurora:
101.6 KB for the cycle with three solves (94.7 KB on main), 79-82 KB for
the others. No launch, fill or host read was added to the unpivoted cycle.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MsLzHmu82zj927Qv8Zq6Tq
The stock branch already sets it; the common block now sets it for the fused
pipeline only.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MsLzHkzHJjM2g5P6ZyZKhr
… (refs #167)

Stage 2 (pivot_type = 'D') added 816-864 B of host allocation to every
refactorize! + solve! cycle of a FusedSolver without pivoting (CUDA; every
configuration, "SPD" included), which pushed the refining "S" cycle over
the 96 KiB oneAPI budget on Aurora:

* the fused kernel launch passed the four arrays of the pivoted variant
  (N.piv, psgo, S.perm, N.aux) also without pivoting; the GPU packages
  convert and track every array argument of a launch. Without pivoting
  they are now `nothing` (never read: every use is under PIV);
* `_fused_factorize!` re-set the solve's pivot flag from `F.fp.piv`, a
  read of the untyped plan field that copied the 448-byte plan
  NamedTuple at every refactorization. The flag is set by the analysis
  together with the plan and is not re-set here.

The unpivoted cycle now allocates exactly what it did before stage 2
(byte for byte, same allocation profile).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MsLzHkzHJjM2g5P6ZyZKhr
@michel2323
michel2323 merged commit 25e65dd into main Nov 17, 2026
9 checks passed
michel2323 added a commit that referenced this pull request Nov 17, 2026
The stock branch already sets it; the common block now sets it for the fused
pipeline only.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MsLzHkzHJjM2g5P6ZyZKhr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude:pr PR opened by the Claude implementer; handled by the Claude pipeline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant