Skip to content

Clean-up of NextLA's dense and mixed-precision code - #23

Open
AkhilAkkapelli wants to merge 17 commits into
mainfrom
mxp-corrections
Open

AkhilAkkapelli wants to merge 17 commits into
mainfrom
mxp-corrections

Conversation

@AkhilAkkapelli

@AkhilAkkapelli AkhilAkkapelli commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A clean-up of NextLA's two parts, dense (src/dense) and mixed precision (src/mxp): wrong results and
crashes fixed, the code laid out like BLAS/LAPACK, tests for every routine, docs and a benchmark runner. It started
as the mixed-precision corrections on top of #22. The tile low-rank module is taken out; it comes back in its own PR.

Dense (src/dense, ext/)

  • Layout: src/dense/blas/ (GEMM, SYRK, TRSM/TRMM, …) and src/dense/lapack/ (Cholesky, LU, QR, …), as in
    BLAS/LAPACK. GPU vendor code is in ext/, as package extensions.
  • Fixes:
    • flags accepted in either case and checked (trsm!, trmm!, unified_rectrxm!);
    • PosDefException from the Cholesky kernels, with info counted in the whole matrix for the recursive LU and
      Cholesky;
    • empty inputs return at once;
    • Float16 sums in Float32 (SYRK kernel, QR norms);
    • CUDA views with non-consecutive rows;
    • a transposed A in a mixed-type SYRK is copied before BLAS, which refused it.
  • CUDA paths, the same as the branches NextLA is benchmarked against:
    • TRSM and TRMM recurse, with cuBLAS at the leaves (smallest TRMM block 16);
    • Cholesky's Float32/Float64 panel solves are one cuBLAS trsm!;
    • Float64 GEMM and the TRSM/TRMM updates use Dgemm/Sgemm;
    • SYRK runs its two halves in parallel when n > 4096, and computes mixed A/C types in the wider one.

Mixed precision (src/mxp)

  • Containers (FullMixedPrec, SymmMixedPrec, TriMixedPrec, TiledTriMixedPrec):
    • scale factors are always Float32, raised only when an update or solve outgrows them; a scale past
      floatmax(Float32) throws instead of leaving the block Inf;
    • precisions[end] must be Float32 or Float64;
    • BFloat16 blocks work on Julia 1.10 too (BFloat16s.jl);
    • A' gives a TransposedMixedPrec, and the routines refuse transposed containers with a clear error.
  • Fixes:
    • mixed TRSM with trans = 'T' used the stored triangle untransposed (2–10 % error);
    • mixed GEMM and LU work for sizes that are not a power of two;
    • adaptive_precisions accepts finite BFloat16 matrices with very large or very small entries;
    • safe concurrent tasks in the recursions.
  • Speed: faster Float64-leaf SYRK update and container build. Mixed SYRK uses 4096-row leaves. TF32 is off in
    mixed GEMM; mixed LU keeps it. Float16 updates keep Float32 sums.

Tests, docs, benchmarks

  • Tests:
    • one environment with ParallelTestRunner, with paths that mirror src/ and shared helpers in test/setup/;
    • options to choose cases (--types, --uplo, --n, …, --backends);
    • CI runs Julia 1.10, the current release and nightly.
  • Docs: README as the home page, Getting started, a Manual (dense, mixed precision, backends, benchmarks), and
    an API reference organised like src/. Every docstring was checked against the code.
  • Benchmarks: benchmark/run.jl reproduces the Benchmarks page against the vendor libraries, on the CPU or
    CUDA:
    julia --project=benchmark benchmark/run.jl gemm potrf --backends=CUDA
    Results and conditions: the Benchmarks page of the
    docs preview.

Testing

  • CI (Julia 1.10, release, nightly; CPU)
  • Local, CPU, Julia 1.13, full suite on 8bff36b: 28,408 passed, 0 failed, 41 broken (known bugs pinned with
    @test_broken).
  • CUDA: the full suite was last run on CUDA before the CUDA path changes. Each of those changes was checked on
    the GPU against the previous code: results bit-identical, or the change in error measured.
  • The docs build passes with every doctest.

AkhilAkkapelli and others added 4 commits November 16, 2026 16:59
Corrections on top of #22, agreed change by change: BFloat16, helper
names, then the mixed-precision corrections.

BFloat16
- BFloat16s.jl is a dependency and its BFloat16 replaces the _BFloat16
  constant in src, ext and tests, so BFloat16 blocks and GEMM work on
  Julia 1.10 as well as 1.11.

Names
- _supported -> _is_block_precision, _check_args -> _check_mixedprec_args.
- Block helpers renamed: _quantize_mixedprec_block,
  _requantize_mixedprec_offdiag_block!, _update_mixedprec_offdiag_block!,
  _solve_mixedprec_offdiag_block!, _triangular_mixedprec. No comments in
  blocks.jl.

Scales and leaves
- Scale factors are always Float32: scale_type and T_Scale are removed
  from the four containers and adaptive_precisions, and quantize is
  quantize(A, T=Float16) -> (Q, s).
- precisions[end] must be Float32 or Float64.
- A scale is only raised when an update or solve outgrows it; a scale past
  floatmax(Float32) throws ArgumentError instead of leaving the block Inf.

Fixes
- unified_rectrxm! with a SymmMixedPrec and trans = 'T' used the stored
  triangle untransposed (2-10% error, or DimensionMismatch).
- unified_rectrxm! throws when uplo is not A.uplo for a SymmMixedPrec or
  TriMixedPrec instead of giving a wrong result.
- recgemm! takes one product over the whole k per quadrant, so sizes that
  are not a power of two work in recgemm! and lu_recursive!.
- adaptive_precisions takes 16- and 8-bit block norms in Float64, so finite
  BFloat16 matrices with very large or very small entries are accepted.
- typemin of a signed integer matrix is scaled instead of stored as -Inf.
- A' on a container gives a TransposedMixedPrec.

Cleanups
- No clamp when quantizing; the block max is taken without a temporary.
- adaptive_precisions gives Float32 leaves to a Float32 matrix and reads A
  once; the adaptive_precision_LT, lu_recursive_mixed! and
  unified_rec_mixed names are removed.
- MixedPrecision re-exports the five routines it extends.
- Seven single-caller _ helpers are folded into their callers;
  lu_recursive! and recgemm! recurse into themselves.
- src/recursion.jl and src/backend_traits.jl are folded into src/NextLA.jl.
- Docstrings match the code; tests cover every fix above.
…le; fixes for nightly, larfb! aliasing and the mixed-precision containers on the GPU

Co-authored-by: Alessandro <axelcar482@gmail.com>
…r src/, --backends option, tests for the mixed-precision containers and TLR
…ed precision, tile low-rank, benchmarks), API reference organised like src/, CONTRIBUTING, CITATION; move the poster and handout to docs/src/assets
Code (src/, ext/):
- Fixes found by the test and benchmark work (runs T127-T146): flags accepted in either case
  and checked in trsm!/trmm!/unified_rectrxm!; PosDefException from cholesky_lower! and
  cholesky_blocked!; info counted in the whole matrix for the recursive LU and Cholesky;
  empty inputs return at once; Float16 sums in Float32 (SYRK kernel, QR norms); CUDA views
  with non-consecutive rows and mixed-size vector batches; cuBLAS at the CUDA leaves of the
  triangular solve and multiply, and for larfb!/unmqr! in Float32; concurrent tasks in the
  mixed-precision recursions; transposed containers refused with a clear error.
- Docstrings checked against the code and corrected.
- The tile low-rank (TLR) module is removed; it will come back in its own PR.

Tests (test/): new and reorganised tests, shared helpers in test/setup/, options to choose
cases inside the tests (--types, --uplo, --n, ...), --failfast, --gpu-debug, --no-float64.
CI also runs the current Julia release.

Docs: a Dense matrices manual page, the Benchmarks page redone from the final GPU runs
(speed, accuracy, adaptive_precisions, the Euro-Par 2026 experiments), the WHPC/ISC 2026
poster on the home page, and "Running the benchmarks".

benchmark/: run.jl reproduces the Benchmarks page for gemm, syrk, trsm, trmm, potrf and lu
against the vendor libraries (CPU or CUDA):
    julia --project=benchmark benchmark/run.jl gemm potrf --backends=CUDA
@AkhilAkkapelli AkhilAkkapelli changed the title mxp: Float32 scales, fixes for wrong results and crashes, and cleanups Mixed-precision corrections, src reorganisation, tests, docs and benchmarks Nov 29, 2026
Akhil Akkapelli and others added 9 commits November 29, 2026 06:01
…HPC/ISC 2026 poster

The Float64 points at n = 32768 (and Cholesky at 65536) are run without time caps; the
comparison uses the poster's numbers against the vendor Float64 routines; formulas in LaTeX.
Same behaviour, easier to read: run.jl reads the command line; routines.jl has the six routines,
their test matrices and what each line calls; harness.jl measures the points and writes the results.
Checked on the CPU and with CUDA: the same points and fields as the single-file version.
The full suite with coverage ran past 60 minutes on the Julia 1 runner and was cancelled; 1.10 and
nightly finished in time. Test sizes are unchanged.
…timeout, benchmark timing, docs

- Float16 x Float16 products on Metal and oneAPI form the sum in Float32 instead of failing (B50);
  recgemm! keeps wider operands wide where gemmEx! is refused (T51).
- uplo flags in either case (C18); parfb! with m2 = 0, CUDA potrf_batched! returns (A, info),
  ttqrt!/ttmqr! read only the upper triangle; TriMixedPrec(::SymmMixedPrec) docstring.
- CI: coverage off for Julia 1, test timeout 60 minutes.
- benchmark/: the timer waits for every GPU stream; README timing rule and one device per run.
- Docs: Backends, dense and mixed-precision pages follow the fixes.
…(pf5, pf6a)

- recsyrk! into a SymmMixedPrec: a Float64 leaf updated by Float16 or Float32 rows takes the
  product in Float32 and adds it into the leaf in Float64 (pf5).
- A faster SymmMixedPrec/TriMixedPrec container build (pf6a).
- Tests for both; the Mixed precision page describes the Float64-leaf update.
…paper [3]'s code; pf5 accuracy note, README bound 1e-6

- Benchmarks page rewritten: mixed-precision Cholesky, SYRK and TRSM against paper [3]'s own code and the
  vendor libraries at n = 65536, GEMM and LU against the same code, papers [1] and [2], the GB10
  Float16 : Float32 ceiling, and how it was measured. Eight new charts (Markdown images, so their paths
  work with pretty URLs); the old charts are removed. Some points are still being rerun, as the page says.
- pf5's Float32 sums for a Float64 leaf's update cost accuracy when only Float32 blocks feed the leaf:
  the Mixed precision page and the source comment say so, and the README's [Float32, Float64] example
  checks < 1e-6 (measured up to 1.9e-7).
…as the other branches

- TRSM/TRMM on CUDA recurse instead of one whole-call cuBLAS solve;
  smallest TRMM block 16; Float32/Float64 updates via Sgemm/Dgemm.
- Cholesky's Float32/Float64 panel solves use trsm!, which on CUDA is
  one cuBLAS call.
- Dense Float64 GEMM on CUDA via Dgemm.
- Dense SYRK runs its halves in parallel when n > 4096; mixed-type
  SYRK/GEMM is computed in the wider type.
- Mixed SYRK smallest block 4096; TF32 off in mixed GEMM (mixed LU
  keeps TF32). Float16 GEMM/LU keep Float32 sums.
BLAS syrk! takes only contiguous columns; a Transpose/Adjoint, or a view
of one, of the wider type was passed on as it was and refused (test
mxp/blas/syrk/recsyrk_mixedprec, a transposed A with [Float16, Float32]).
Plain arrays and views of them are unchanged.
@AkhilAkkapelli AkhilAkkapelli changed the title Mixed-precision corrections, src reorganisation, tests, docs and benchmarks Clean-up of NextLA's dense and mixed-precision code Dec 4, 2026

This branch was previously deployed

1 inactive (outdated) deployment
github-pages — 1091941f Deployed Dec 3, 2026 by AkhilAkkapelli via deploy #3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant