← Back to Pull requests

Add real LAPACK GETRS derivative rules #3524

Open
unknown opened this pull request with 502 lines diff across 6 files
View on GitHub
unknown unknown commented on Oct 26, 2026 20:51 UTC
Author

Real Fortran LAPACK sgetrs/dgetrs calls currently stop differentiation with a missing-derivative error. This adds forward and reverse rules for solves with supplied packed LU factors and fixed integer pivots, allowing a factorization to be reused across differentiated solves.

The rules are defined in BlasDerivatives.td, following the review request. The dedicated BlasGetrs implementation, handler and tape have been removed. The BLAS generator gains inactive integer-array caching for pivots, guarded cache copies, outlined statement rules and masked matrix updates. Outlining keeps derivative control flow separate from Enzyme's mapped primal blocks. Existing Fortran declaration argument counts and callee calling conventions are preserved.

The rules differentiate both packed factors and the in-place RHS/solution. They cover real N/T/C operations, multiple RHS, padded leading dimensions, vector differentiation, and recognized LP64 / _64_ ILP64 spellings. The primal remains a LAPACK call; derivatives use GETRS, TRMM, GEMM and LASWP without constructing an inverse. The reverse factor rule reconstructs the solution from the cached input RHS.

Native validation now covers LLVM 15.0.7 and 16.0.6, each in Release and Debug on Linux:

  • Every configuration replays all 1,251 IR files in Enzyme, TypeAnalysis and ActivityAnalysis: 1,240 PASS, 11 declared XFAIL and zero unexpected results. The private C++23 harness preserves the checked-in RUN directives, FileCheck, version conditions, pipelines, shared temporaries and XFAIL/XPASS semantics. No checks or output were normalized or disabled. This is command replay, not an official llvm-lit or GitHub CI result.

  • The 38-file BLAS slice has 36 PASS and two existing XFAIL in every configuration. Exact Fortran signatures, fastcc calls, malformed-ABI diagnostics and blas_diffuse pass in all four.

  • Each configuration also passes the unchanged numerical fixtures: three 720-case grids for portable LP64, portable ILP64 and O2 input IR, plus the repeated-factorization diffusion example at O1/O2. Numerical fixtures and the replay harness use C++23 mode.

  • Actual LP64 LAPACK and generated-code ASan/leak checks were validated with LLVM18.1.3; the portable backend also passed UBSan.

  • Actual OpenBLAS64 ILP64 passes the 720-case grid at O1/O2. The library reports USE64BITINT and has eight-byte blasint. It exports unsuffixed symbols, so a separately compiled non-LTO C++23 adapter forwards the eight _64_ names without arithmetic or integer conversion. AD cannot see the adapter implementation. This is actual ILP64 coverage through a symbol adapter, not direct LAPACKE64 validation or a claim that the vendor exports _64_ symbols.

  • Changed C++ files in the formatting workflow scope pass Clang-Format 16 with LLVM style; the full PR patch passes git diff --check.
  • The earlier LLVM18 golden-check replay is superseded by the LLVM15/16 matrix. Its one intentional raw-IR difference preserves an existing 13-argument GEMM declaration rather than adding hidden lengths. The original checks remain intact.

    Private environment caveat: GCC13/C++23 builds use a documented LLVM SDK DiagnosticInfo.h lvalue-return compatibility edit, a CMake standard override and isolated SDK dependency bootstrap. These are not upstream changes. The numerical source uses -std=c++2b with Clang15/16, their spelling for C++23 mode. Official CI, other platforms and full compiler soundness remain separate unverified gates.

    Scope: supplied nonsingular packed factors, fixed pivots, ordinary pointer-based Fortran declarations, an active RHS and static activity. This does not add GETRF or pivot-selection differentiation. Complex arithmetic, runtime activity, split-forward mode, integer-encoded references and arbitrary factor/RHS overlap are outside this change. GETRS argument-error identity behavior is tested; GETRS does not supply a new singularity check. No performance improvement is claimed.

    Related request: https://github.com/EnzymeAD/Enzyme.jl/issues/3039

    Diff: 502 lines (+376 / -126) across 6 files Reviewer: agourakis82 Review duration: 51096m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.55) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.55 · 502 lines diff across 6 files
    0.55
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.372
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #3524"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 54.5% (MEDIUM) · Higher = larger blast radius
    54.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 30.2% · Safe to merge
    30.2%