libr4d: tiled runtime-LoRA rows over row tiles, preferred over the scalar rows

The v1 rows grid by row: shrink is one block a row walking K serially, and
expand one block a (row, 256 columns) that re-reads all of B[s] for every
row, so a prefill chunk reads it M times and a chunk of base rows still
launches M * ceil(N/256) blocks that read a slot and leave.

lora_shrink_wmma (bf16 a) and lora_shrink_wmma_q (fp8 / i8 codes whose scale
group is whole 32-wide steps) run WMMA bf16 over 16-row x 16-j tiles: K in
32-wide steps over 4 waves, the waves summed in fixed order in LDS, and a K
split fixed by K and R alone (sh_plan) whose partials live in the op's
scratch and are summed in split order by the last block to arrive; the
arrival counters are a small block keyed on (device, t). Codes are exact in
bf16 and each step's partial is scaled by its group's f32 scale; f16 / f32
activations and other groups stay on the scalar kernel.

lora_expand_tiled stages B[s]'s [128 columns, 32 j] slab in LDS as f32 for a
32-row tile and keeps v1's per-output sequence (j ascending, no FMA), so its
bytes are libref's.

Both grid by row tiles; a tile of base rows leaves on one ballot before any
barrier or operand load, a mixed tile runs one pass per distinct slot, and a
small grid spreads a tile's passes over blockIdx.z. No choice depends on M
but which block runs a pass. The scalar rows stay, by name and as the
f16 / f32 shrink, below R4D_PRIO_LORA_TILED.
This commit is contained in:
baKon committed 2026-10-16 20:52:09 -05:00
1 parent b427e2774c
commit ec1e830c43
6 files changed
+690 -36

No files matched your search

+5 -2
View File
@@ -72,8 +72,11 @@ const std::vector<TolRow> g_tol = {
{ "logit_rerank", "*", 8e-3 },
{ "moe_gemm", "*", 3e-2 },
/* Runtime LoRA's shrink is a K-long reduction into an f32 `t` whatever `a` is -- the codes are
* decoded the same way on both sides, so only the summation order differs, and that is what
* gemm_nt's f32 row allows. Expand's R-long sum lands in `y` and takes the dtype rows below. */
* decoded the same way on both sides, so only the summation order differs (and, in libr4d's
* WMMA row, a code's group scale is applied to each 32-wide step's partial rather than to each
* element: a different rounding of the same terms), and that is what gemm_nt's f32 row
* allows. Expand's R-long sum lands in `y` and takes the dtype rows below; libr4d's tiled
* expand computes libref's bytes. */
{ "lora_shrink", "*", 2e-5 },
/* Attention: a softmax over a long context plus a second reduction. */
{ "attn_", "bf16", 2e-2 },