Skip to content

Device-resident linear algebra, tiled Cholesky and TSQR - #22

Open
AdvaitTahilyani wants to merge 10 commits into
scale/06-device-indexingfrom
scale/07-device-linalg
Open

AdvaitTahilyani wants to merge 10 commits into
scale/06-device-indexingfrom
scale/07-device-linalg

Conversation

@AdvaitTahilyani

@AdvaitTahilyani AdvaitTahilyani commented Nov 4, 2026 •

Copy link
Copy Markdown

Stacked on #21.

1 A100: cholesky 16000 6.8 s → 0.16 s; qr 16384×8192 14 s → 0.5 s; solve 16384 7 s → 0.32 s; tssvd 4e6×64 2.7 s → 19 ms.

Tests: test_linalg.py (587 checks, incl. non-PD failure at first/middle/last tile).

Tested (full stack): CPU +p1/+p2 15/15 originals, 25/25 ports, 30/30 ops; A100 1 GPU 15/15, 25/25, 30/30 and 4 GPUs (one process per GPU) 15/15, 25/25.

🤖 Generated with Claude Code

AdvaitTahilyani and others added 5 commits November 2, 2026 12:50
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Operand blocks travel as device chunks (<= 64 MB, CUDA IPC between processes)
through receive_data (input_index LA_DEV_INPUT + kind) to chare 0 of the
operands' partition, which assembles column-major operands in device memory,
factors them in place with cuSOLVER/cuBLAS (QR in place in the packed result,
failure NaNs from the device info word) and sends row-major result chunks to
the output tiles. No host copies except for svd/lstsq (host-assisted as before)
and det/slogdet (the LU diagonal). tssvd with all columns in one tile column
sums per-chare Gram matrices instead of gathering A.

1 A100: cholesky n=16000 6.8 s -> 0.13 s, qr 16384x8192 14.3 s -> 0.53 s,
solve n=16384 7.1 s -> 0.32 s, tssvd 4e6x64 2.8 s -> 0.05 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lower cholesky of a whole real array, result tiled like the operand: each tile
chare factors its tile in place in the result (right-looking: potrf on the
diagonal, trsm by the diagonal panel, syrk/gemm updates from the panels of its
row and column, sent as device chunks). The last diagonal tile broadcasts a
status, so a failure anywhere still gives an all-NaN result. CNUM_LA_DIST=0
gathers instead.

qr 'reduced'/'r' of a real tall matrix in one tile column: each chare runs
geqrf on its row block, the root factors the stacked R_i and returns the Q
slices, each chare sends its rows of Q (CNUM_LA_TSQR=0 gathers instead).

Device scatter takes a sub-box of the result. Tests: multi-tile cholesky,
not-PD failures in the first, a middle and the last tile, tssvd over two tile
columns, tall reduced QR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, tests)

- Every chare orders its operand reads after the other streams
  (compute_after_others at the top of the device path).
- TSQR returns LAPACK's (NumPy's) signs: the top chare sends Q's top n x n
  block to the root, which recovers the Householder signs by a modified LU
  (Householder reconstruction) and broadcasts them; R and Q are scaled before
  they are sent. TSQR needs n <= 512 and n rows in the first row block.
- QR is factored in place in the packed result only below INT_MAX elements
  (cuSOLVER 32-bit sizes), else in its own buffer and copied.
- Gram path capped like TSQR (n^2 elements within a 64 MB chunk); tssvd clamps
  negative eigenvalues before sqrt; la_prof() inserts nothing unless timing.
- receive_data: LINALG chunk tags start at 1 << 24 (static_assert; other tag
  ranges must stay below).
- Tests compare Q and R with NumPy directly (signs included); add strided and
  offset views through TSQR, Gram tssvd and gathered cholesky, and a last row
  tile with fewer than n rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	CODEMAP.md
#	src/partition_comm.cpp

@adityapb adityapb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verdict: approve with nits.

This is a static review, with two extra checks:

  • The TSQR sign reconstruction, ported to NumPy, matches np.linalg.qr Q and R to 7e-16 over 200 cases.
  • I derived the tiled Cholesky tile algebra by hand.

Line numbers are at this PR's head.

These check out:

  • Device gather/scatter.
  • Tiled right-looking Cholesky: each tile gets exactly the panels it needs, and a non-PD failure in the first, middle or last tile is detected.
  • TSQR.
  • Gram tssvd.
  1. Nit: "no host copies" isn't true yet. svd, lstsq and gathered tssvd still go D2H → host → H2D through la_dev_host_compute (executor_linalg.cpp:1903). #36 removes this.
  2. Nit: tssvd breaks on rank-deficient or ill-conditioned input.
    • It gives s = 0 and an inf/NaN column in U (tssvd_pack, :351-355). The threshold is κ ≳ 7e7 for float64 and ~3e3 for float32.
    • The syevd info is never read (:2087-2120).
    • This is cuPyNumeric's definition of tssvd, but it's worth a docstring warning. Still at #44.
  3. Nit: tile element counts are cast to int (:2187, :2322). This is unreachable unless a tile edge exceeds 46340.

tssvd returns NaNs when syevd reports non-convergence. Panel chunks travel as chunk
numbers instead of 32-bit element offsets, and la_k_pack takes 64-bit extents.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AdvaitTahilyani

Copy link
Copy Markdown
Author
  1. "no host copies" is not true yet: description fixed (svd, lstsq and gathered tssvd still go through the host until Linalg: device svd/lstsq, distributed solve_triangular, complex/upper tiled cholesky #36).
    2a. tssvd on rank-deficient or ill-conditioned input: docstring warning added in 5cb65e9 (kappa thresholds, use svd instead); behaviour kept, it is cuPyNumeric's definition.
    2b. syevd info never read: fixed in 5cb65e9 (a nonzero info gives NaNs, as the other LINALG failures do).
  2. Tile counts cast to int: fixed in 5cb65e9 (la_k_pack takes 64-bit extents; Cholesky panel chunks travel as chunk numbers, since the region wire format is 32-bit, and the receiver derives the 64-bit element range).

Validated: nc build and CPU regress at +p1 (orig 15/15, ports 25/25, ops 28/28). The C++ changes are device-only: executor_linalg.cpp compiles with the GPU flags, but I did not run them on a GPU (no Cholesky or tssvd run after the change).

AdvaitTahilyani and others added 4 commits November 10, 2026 16:01
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants