Skip to content

Linalg: distributed LU for solve, inv, det, slogdet - #35

Open
AdvaitTahilyani wants to merge 9 commits into
scale/19-matmul-dtypesfrom
scale/20-distributed-lu
Open

AdvaitTahilyani wants to merge 9 commits into
scale/19-matmul-dtypesfrom
scale/20-distributed-lu

Conversation

@AdvaitTahilyani

Copy link
Copy Markdown

solve, inv, det and slogdet used to gather the matrix onto one GPU. Now:

  • The work uses a panel-cyclic LU with partial pivoting and lookahead.
  • On 1 GPU it runs as an in-place cusolverDnXgetrf.
  • The path applies when n ≥ 2048 (CNUM_LA_LU_MIN).

solve on A100s:

n GPUs Before After
16384 4 ~345 ms 170 ms
32768 1 out of memory 1.9 s
32768 4 1.9 s 0.64 s

Adds test_lu_dist (166 checks).

🤖 Generated with Claude Code

AdvaitTahilyani and others added 2 commits November 4, 2026 23:33
M = A^T (row-major tiles are column-major blocks of M) is factored with
partial pivoting; panels of CNUM_LA_LU_NB columns are dealt cyclically to
one worker chare per PE, filled in place by the chares on its PE. Panel
owner getrf and broadcast, row swaps and trsm/gemm trailing updates with
one-panel lookahead, fan-out U^T and L^T substitution, result rows
permuted on the way to the output tiles. One worker on NVIDIA runs
cusolverDnXgetrf/Xgetrs on the whole matrix in its own buffer, so
1-GPU solve holds the operand tiles plus one copy. Used from
CNUM_LA_LU_MIN (2048) rows in both builds. la_dalloc now evicts cached
arrays and blocks before large allocations and retries after releasing
the caches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 4ac40c896bc541397bf17f7886a9d1593f71701d)
The forward and backward substitutions pass one nb x nrhs block per
panel; as device messages each step paid a stream callback and an IPC
round trip. Blocks up to 1 MB are now copied to the host once and sent
as plain messages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit c3e04a8664997265b5990e36bda8cd969b08333b)

@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: request changes as a standalone merge. Please squash #37 into this.

This is a static review, plus a NumPy port of the LU (lu_factor_loop in both this PR's ordering and #37's, lu_subst, the output permutation and the det sign). It matches NumPy's solve and det to about 1e-13 with 1–4 workers and odd n and nb. Line numbers are at this PR's head.

The algorithm is right:

  • the pivot search is local, because panels hold all n rows;
  • row swaps are applied to the left and right of the panel;
  • lookahead, the det sign, and singular det/slogdet (0, -inf) are all correct.
  1. [major, fixed by #37] Chunks are copied into the LU buffers before their allocation is ordered on the worker's stream.
    • Where: W, B and piv are allocated with cudaMallocAsync on the stream of whichever chare on the PE calls ctx() first, and L->ready is recorded there (executor_linalg.cpp:3462-3483).
    • la_lu_recv (:3572-3584) copies the received LU_A/LU_B chunks into them on the worker's stream without waiting. The worker only waits on ready at assembly (:3385).
    • When a non-worker chare creates the context (another 2-D chare on the PE, or a 1-D b chare), the pool can hand out memory that pending work on the creator's stream is still using.
    • Effect: solve/det are intermittently wrong on 2+ PEs with n ≥ 2048.
    • #37's cudaStreamWaitEvent(..., st.lu->ready) fixes it completely, so please land the two as one commit.
  2. [minor] test_lu_dist.py mostly bypasses the LU workers by default.
    • The workers only run for n ≥ CNUM_LA_LU_MIN (default 2048), so with defaults only the n=2100 solve/slogdet cases reach them.
    • inv, det, singular, complex and strided-view cases, and #36's solve_triangular, need the server started with CNUM_LA_LU_MIN=1.
    • Worth having the test set it, or documenting it in the test runner.

W, B and piv are allocated on the stream of whichever chare on the PE creates the
LU context; LU_A/LU_B chunks copied in on the worker's stream now wait on its ready
event. test_lu_dist: CNUM_SERVER=<server.out> starts a private server with
CNUM_LA_LU_MIN=1 so every case goes through the distributed LU.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AdvaitTahilyani added a commit that referenced this pull request Nov 10, 2026
…sync

The wait on the context's ready event now lands with the distributed LU itself;
release_device_caches() already starts with a global fence.

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

Copy link
Copy Markdown
Author
  1. [major] chunk copies before the allocation is ordered: fixed in a36ea94 (linalg LU: apply the lookahead panel's row swaps first (latency) #37's cudaStreamWaitEvent(compute, st.lu->ready) moved here; linalg LU: apply the lookahead panel's row swaps first (latency) #37 drops its copy in c6d2eb8)
  2. [minor] test_lu_dist bypasses the workers: fixed in a36ea94 (CNUM_SERVER=<server.out> starts a private server with CNUM_LA_LU_MIN=1, so every case runs on the LU workers)

Validated: CPU regress +p1/+p2 (orig 15/15, ports 25/25, ops 32/32); test_lu_dist with CNUM_LA_LU_MIN=1 at 1/2/4 PEs (86 checks). 1- and 4-A100 runs are queued.

AdvaitTahilyani and others added 2 commits November 10, 2026 16:19
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AdvaitTahilyani

Copy link
Copy Markdown
Author

GPU check on 1 and 4 A100s: test_lu_dist passes (86 checks), and chol_check passes (36 checks, including tiled cholesky(upper=True) reading the upper triangle) on both.

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