Work that was scoped but not done, written down so that it can be picked up later. Each file says what the change is, the measurements behind it, a plan, the effort and the expected gain, and where to start. The numbers are an Apple M5 Pro’s (20 GPU cores, 18 CPU cores).
None (2026-10-09): every proposal written so far is done, tried and rejected, or measured and judged not worth building; see Done below.
Not code, but open:
python3 tuning/run.py on an idle machine.In 2.17.0 (2026-10-09), eigh and the SVD:
| work | outcome |
|---|---|
| eigh for batches of mid-size matrices | tridiag_batch: a batch reduced together (a threadgroup a matrix and panel), the tridiagonal problems on the CPU’s cores under the GPU’s stages: 1.3-1.5x the CPU at 256-1024 matrices of 96-256; its symmetric products from the lower triangle alone, 1.5x at 1024 |
| the SVD for batches of mid-size matrices | bidiag_batch, the same for the SVD, each panel step reading the trailing block once (slabrd reads it twice): 1.4-1.65x the CPU at 256-1024 matrices of 128-256 |
| eigh with eigenvectors in two stages | band with eigenvectors, as the SVD’s: 1.36x tridiag at 4096, 1.59x at 8192 |
| ql in registers | up to N = 32 a simdgroup a matrix: 1.1-1.5x; eigenvalues alone by bisection, 2-3x |
| golub_kahan in registers | up to 32 x 32 in a simdgroup’s registers, four or two matrices a simdgroup up to 8 or 16 rows: 1.6-2.1x with vectors to 16 x 16; singular values alone by bisection on the Golub-Kahan tridiagonal, 1.6-2.7x; ql’s registers packed the same way, 2x up to N = 8 |
bidiag_batch for tall and wide matrices |
R of this library’s QR first, as on the CPU: 256 x 1024x128 2.5x (1.77x the CPU, from 0.71x), 256 x 128x1024 2.4x (1.96x) |
| singular values alone of batches in two stages | from k = 160: a band on the GPU (batched panels and products), bidiagonal on the CPU’s cores: 1.5x at 512, 2-2.3x at 1024 (3.3x the CPU at 16 x 1024^2). The eigensolver’s counterpart not built: its CPU path is LAPACK’s own two-stage driver, whose band chase alone is two-thirds of its time (64 x 512^2: 15.8 of 23.2 ms), so a GPU first stage could reach about 1.3x |
| a runner simdgroup for the register kernels’ QR iterations (17-32 rows) | the SVD’s: 1.1-1.35x; eigh’s ql: 0.8-1.1x, not kept (its sweeps are cheap against a threadgroup barrier a sweep) |
| one trailing product a SVD panel; the batch back-transformations | not built: removing a whole product saved 3-6%, the whole back-transformation 6-14% of the wall time (it overlaps the CPU’s solve); what a rework would recover is a few %. The SVD panel’s two trailing products as one of rank 2nb (2026-10-09; its operands [Y; U] and [V; X] gathered by the panel kernel, as eigh’s): 0.98-1.04x from 64 to 1024, the gather costing what the second product had; reverted |
| the blocked QR’s fixed costs (what was left) | the TSQR is half of one matrix’s call (57 us a 16-column panel at 1024): panels of 8 columns for up to 4 matrices of 768-3072 rows, 1.05-1.1x; the three TSQR kernels as one threadgroup tried, 0.74x (its rebuild on one core); the in-aggregate updates as one kernel (up to 4 matrices, 3072 rows), 1.16x at 1024^2; the input’s scan on the GPU, 1.01-1.03x |
| a constant matrix’s Q (found on the way) | far from orthogonal on the blocked QR and both band backends (5e4 at 600 x 64, 3e7 for the SVD’s at 1024²): sums of squares that underflowed in part; a rest below 2^-80 is now zero in every kernel |
| the eigensolver’s batched band blocks in four dispatches (found on the way) | the panel kernel forms V T, one kernel (sb_small) does V^T X, M and Y: four dispatches a block instead of seven, 1.09-1.31x; two stages then pay from N = 64 for small batches and up to 32 matrices from 896 |
| the batch back-transformations (left from the mid-size work) | measured: 3-15% of a batch call, mostly batched products near their flop rate; their T, built column by column with 128 barriers, 1-4%. T now built in blocks (diagonal 16 x 16 blocks a thread a row, merged in pairs, five barriers): its cost gone, 1.04-1.05x the SVD and 1.02-1.15x eigh at 96-384. A row a thread without blocks (no barriers, the same dependent chain) gained nothing. The input’s scan in these backends (0.3 ms of 27-117, every core already) not moved to the GPU |
| the batch pipelines’ smallest chunk (found on the way) | tried and rejected: below 16 matrices a chunk the one-stage reductions’ threadgroup-a-matrix kernels leave the GPU idle (24 x 1024^2 in chunks of 2-8: 0.97-1.04x; 16 x 1024^2 0.63-0.93x) |
| the SVD’s batched band blocks in three passes | three passes and five dispatches a block instead of four and eight (the row panel’s kernel applies the left update): 1.04-1.16x; as planned, with the small products separate, it lost (0.91-0.96x). Two stages with vectors now from k = 288 (160 for small batches) |
| batches of a few large matrices with vectors in two stages | bidiag_batch with vectors from k = 384 and tridiag_batch with eigenvectors (N from 384, small batches) in two stages, both stages’ reflectors kept and applied on the GPU: the SVD 1.96x the CPU at 1 x 1024^2, 2.7x at 16 (2.7-3.4x the direct reduction); eigh 1.6x the CPU at 1 x 1024^2, 1.7x at 8. band with vectors hands them batches of two or more. Eigenvalues alone: not kept (LAPACK’s two-stage driver faster) |
| the CPU path’s divide and conquer | eigh and the SVD with vectors, a batch of at most a quarter as many matrices as cores, in the drivers’ steps with the divide and conquer on the idle cores: eigh 1.17-1.26x ssyevd from 256 to 2048, the SVD 1.23-1.4x sgesdd (1.16-1.3x tall or wide); with fewer than 4 cores a matrix it lost (6 of 1024: 1.1x slower) |
| the batch backends at 1024 | the SVD’s panel with 1024 threads, 1.1x. With vectors, 8 matrices of 768-1024 still go to the CPU (1.3-1.5x ahead): a threadgroup a matrix leaves 12 of 20 cores idle. Singular values alone are solved by the two stages above (their products use every core); with vectors the same would need the band backend’s transformations batched, a project of days |
| a GPU solve for the batch backends; two matrices a threadgroup | not built: timed stage by stage, the batch backends were bound by the GPU’s reduction (its memory traffic), not the CPU’s solve, from 256; at 128 the two balance. Two matrices a threadgroup helps a latency-bound kernel, which these are not |
| the batch panels’ own columns in registers | tried on eigh’s panel, three ways, and reverted: 10-17% slower at 128-512. The 64 registers a thread costs fewer simdgroups a core in a kernel bound by memory, and the reads it saved were mostly cache hits. Measured on the SVD’s panel (2026-10-09): those reads were a third of its reduction at 96-128, so each step now makes one pass over the panel’s rows instead of two, and up to 128 rows the dot products go two columns a pass, in both panels: svdvals 1.12-1.15x and eigvalsh 1.07-1.1x at 64-128 |
| the bulge chase on the GPU (new on the way) | tried and rejected: a threadgroup a matrix, the sweeps in lockstep, gives the CPU’s tridiagonal in 11 ms at 1024 whatever the batch (16 x 512^2 4.2 ms), bound by one core’s issue rate; the CPU’s cores do a batch’s chases about as fast, and skipping the chase entirely gains 1.13-1.8x, so the GPU’s would net 1.0-1.1x. Two sweeps a simdgroup: slower (16.4 ms); the band in threadgroup memory, at best 1.24-1.37x where 3x was needed |
In 2.16.0 (2026-10-08):
| proposal | outcome |
|---|---|
| A QR kernel for batches of small matrices | a kernel in a simdgroup’s registers (sgeqr2, sorg2r; up to 32 columns and 128 rows), 4-6x the unblocked backend’s first kernel; the threadgroup-memory kernel proposed was built and then beaten by the blocked one below |
| A QR kernel for batches of mid-size matrices | LAPACK’s blocked QR in one threadgroup a matrix, the updates 8 x 8 simdgroup matrix products: 1024 of 128 x 128 in 6.4 ms (the blocked QR 17.8, the CPU 25), 256 of 256 x 256 in 8.3 (17.8, 18.7); replaced two kernels; small batches get more simdgroups a matrix (one 384 x 384 2.0 ms against 3.0) |
| MLX’s buffers, not wrapped again | through the MLX API the arrays’ own Metal buffers, not new ones over their memory: 10-25% off a call for large batches of small matrices, every decomposition; the same for the C API (metal_linalg_know_buffer) and PyTorch’s MPS tensors; the rest of the per-call cost found to be the sweeps’ (MLX’s buffer cache off), which keep it on since; a residency set tried, no gain |
In 2.15.0 (2026-10-07); see the study:
| proposal | outcome |
|---|---|
| Parallel divide and conquer | sstedc 176 to 50 ms, sbdsdc 753 to 100 at 4096; eigh with vectors 1.4-1.5x, the SVD’s 1.7-1.9x |
| A faster TSQR top kernel | the top a tree of triangle pairs, and the panels off IEEE arithmetic: a panel 140 to 76 us; svdvals on band 1.13-1.30x, eigvalsh 1.08-1.18x |
| Fused small products | two kernels a block instead of three products: 2-5% at 1024-2048 |
| Symmetric trailing update | the update on the lower triangle, mirrored: eigvalsh on band 1.08x at 4096, 1.17x at 8192; X from the lower triangle lost to MPS |
| Band width per device | values_band_width, measured by stages 3b and 4b |
| Band threshold tie-break | a finer grid, and thresholds compared on the points where they disagree |
| The bulge chase under the band reduction | eigvalsh and svdvals on band, one matrix: 1.04-1.05x, not the 1.15-1.2x estimated (each sweep runs to the band’s end, which the GPU finishes last, so only about 6% of the chase can go before it) |
| The band SVD with vectors, overlapped further | the GPU found to be the bottleneck; its two idle gaps closed (Q1 and P1 queued during the reduction, Q2 and P2 released in two chunks as the chase finishes them): 1.04x at 4096, 1.06x at 2048 (alternating runs) |
| The divide and conquer’s top products on the GPU | for one matrix, products of 1 GFLOP or more as MPS products on the merges’ memory in place: eigh with vectors 1.075x at 4096, the SVD on bidiag 1.046x |
| IEEE arithmetic in the remaining shaders | the SVD’s Jacobi kernel’s rotation and output on fast division and square roots (rsqrt with two Newton steps, for V’s orthogonality): 1.14-1.17x on batches of small matrices; nothing left in the one-stage reductions |
| Long single-threadgroup kernels and the watchdog | the whole-matrix Jacobi kernels split a long solve over dispatches of a few rounds (about 15 ms each, from 1.7-2.8 s for one threadgroup), bit for bit the same and in the same time |
| The blocked QR for a batch at once | a batch is one pass of kernels and batched MPS products (whose left and result matrices ignore matrixBytes: views a whole stride tall); beats the streaming kernels everywhere, 1.8-3.5x; 16 x 1024^2 in 25 ms against the CPU’s 48 |
| QR’s large-matrix clause by rows and k | the clause on sqrt(M k) rather than k (it fitted better than the work’s own size), tall large shapes in the grid, the fit in both orders: 8192 x 512 to the GPU (8.5 ms against 48); the M5 Pro’s QR row 1.013x regret |
| The blocked QR’s fixed costs and panels | padded to whole panels, no CPU round trip: one 256^2 2.5 to 1.5 ms; 32-column panels and 256-row leaves tried, slower |
| Blocked QR on the band reduction’s panels | one large matrix 2.1x the streaming kernels at 1024, 2.6x at 2048, 3.7x at 4096 (62 ms against 231; the CPU 634), 5x on tall 4096 x 1024 and 8192 x 512 |
| Less GPU work for the band SVD with vectors | bd_chase_apply’s blocks carry Y = -T^T V^T instead of T (two products a step, not three): Q2 and P2 98 ms instead of 135 at 4096; the CPU then the bottleneck, the divide and conquer’s top products on the GPU once Q2 and P2 are done: 1.04-1.05x at 2048-4096 |
| Two-stage reduction with vectors | the SVD with vectors on band: 1.21x bidiag at 1024, 1.45x at 2048, 2.35x at 4096, about 2.7x at 8192 with the overlap above (Q2 applied by a pipeline of groups, 60-64 ms a side at 4096; Q = Q1 Q2 and P = P1 P2 formed under the CPU’s chase and divide and conquer) |
Found along the way, also in 2.15.0: the tridiag and bidiag backends’ block
reflectors’ T from a Gram matrix (eigh with vectors 1.1x at 4096); the
one-stage reductions and bisection off IEEE arithmetic (eigvalsh on
tridiag 1.07-1.11x); the sweeps’ correctness gate failing from N ~ 6500
(the CPU reference outlasting the GPU’s watchdog).
So that they are not retried without a new idea:
sbdsvdx (bisection by index range) in place of sbdsqr: 30x
slower on one core, and wrong when the bidiagonal splits.sb_update’s tiles for the general reduction’s update (2.15.0): no
symmetry to save memory on, and no faster than MPS (svdvals unchanged).How the profile numbers in the 2.13 proposals were taken. The per-kernel
times came from a temporary build of src/band_reduce.mm that committed
every panel kernel and every matrix product in a command buffer of its own
and summed GPUEndTime - GPUStartTime per kind of operation. Each operation
then carries about 10 us of launch overhead it does not have in the real,
single command buffer a block: the profiled stage summed to 204 ms for
svdvals at 4096, against about 180 ms in the real run. In 2.15.0 kernels were
timed instead with scratch harnesses that dispatch one kernel many times in
one command buffer (GPU time per dispatch), and changes with the whole call
(sweep_eigh, sweep_svd), side by side with the previous build.