Repository navigation
Description
Problem
The OpenXLA/IREE backend on gfx1151 now runs a llama-3.2-1b decode step in 39.6 ms (317 dispatches) after #2859 and #2863 removed the per-step weight transposes. The MLX ROCm backend on the same host, checkpoint and protocol does the same step in about 4.2 ms, so the remaining gap is roughly 9-10x: 235-238 tok/s (MLX, mlxcel-bench-decode --ignore-eos --no-chat-template, n=64 and n=128) against 21-28 tok/s (XLA CLI, capacity 256, same prompt).
The step is now dominated by kernel efficiency, not graph layout. From a rocprofv3 --kernel-trace of the XLA CLI at n=128 (14465 vecmat dispatches over the run, 4.35 s of 5.19 s total device time):
| kernel | per step | threads (workgroup x grid) | bytes read | effective bandwidth |
|---|---|---|---|---|
vecmat_2048x8192_f16xf16xf32 (down) |
13.4 ms (16 calls) | 32 x 256 | 33.5 MB per call | about 50 GB/s |
vecmat_8192x2048_f16xf16xf32 (gate/up) |
4.4 + 4.4 ms (16 + 16 calls) | 32 x 1024 | 33.5 MB per call | about 50 GB/s |
vecmat_2048x2048_f16xf16xf32 (qkv/o) |
3.3 + 3.2 ms (16 + 15 calls) | 32 x 256 | 8.4 MB per call | about 50 GB/s |
vecmat_128256x2048_f16xf16xf32 (LM head) |
3.5 ms (1 call) | 32 x 16032 | 525 MB | about 228 GB/s |
reduction_128256_f32xf32xi32 (argmax) |
3.86 ms (1 call) | 1 x 1 | 512 KB | about 134 MB/s |
Two distinct defects are visible.
-
Small-M vecmats run at about 50 GB/s while the same lowering reaches 228 GB/s on the 128256-wide head. The per-layer projections are one thread block of 32 lanes per few outputs with a serial K=2048 reduction, so the small shapes never fill the device; the issue is codegen/occupancy at these shapes, not memory volume.
-
The argmax is lowered to a single workgroup of one lane (
grid = (1,1,1),workgroup = (1,1,1)), so 3.86 ms are spent in a serial scan of 128256 f32 logits.
The MLX path reaches about 0.04 ms per qmv_wide_kernel call against about 0.31 ms for the IREE vecmat, so per-call efficiency is the target.
Work to do
- Characterize the small-M vecmat lowering. Dump the executable sources from the pinned
iree-compile(--iree-hal-dump-executable-sources-to) for a[k] x [k, n]dot_generalat n in {512, 2048, 8192, 128256} and explain why n = 8192 saturates while 2048/8192 do not (workgroup count, vector width, LDS use, reread of the activation vector per block). - Evaluate fixes in this order, measuring each on the same trace protocol: compiler/target tuning flags that change the vecmat codegen; a larger workgroup or split-K form the emitter can express without changing the weight layout; and, if neither restores bandwidth, fusing q/k/v and gate/up into one wider contraction per layer (100 dispatches per step become about 35), which needs a concatenated upload-time weight spec.
- Replace the serial argmax with a parallel reduction. Either emit a two-stage reduce in the graph (reduce along an inner axis, then across the partials, preserving the argmax index) or find the option that stops IREE from lowering it to one lane. Target under 0.2 ms.
- Keep the batch engine and every committed golden unchanged (
ProjectionLayout::OutIn), keep output token-identical on llama-3.2-1b and at least one untied checkpoint, and keepREFERENCE-EXACTonxla_batch_bench.
Acceptance criteria
- A measured per-step breakdown before/after each change at B=1, n=128, capacity 256 on gfx1151, with the same
n=1vsn=128trace subtraction. - The small-M vecmats either reach the head's effective bandwidth or the issue records why the pin cannot and what fusion is needed instead.
- The argmax drops below 0.2 ms per step.
- Token identity, the
mlxcel-xlalib tests with unchanged goldens, and clippy at default andireefeatures stay green.
Out of scope
Graph layout (resolved in #2859 and #2863), prefill throughput, and the batch/serving paths beyond a no-regression check. Any model-family coverage work.
Activity
inureyes commentedon Nov 6, 2026
First follow-up trace on the vecmat question, from the pinned
iree-compile(3.12.0rc20260721) compiled forgfx1151.The small-N and large-N vecmats get the same lowering config from the default strix-halo tuning module:
for
n = 2048,8192, and128256, so the 4.5x bandwidth difference (about 50 GB/s versus 228 GB/s) is not a different tile choice. It tracks the grid size instead:n = 8192launches 8192 / 256 = 32 workgroups of 32 threads, roughly one wave on a 20-WGP device, and the serial K reduction cannot hide memory latency;n = 128256launches 16032 workgroups and saturates. The same config also explains whyn = 512andn = 2048sit at the same about 50 GB/s.Candidate directions, cheapest first:
--iree-codegen-tuning-spec-paththat gives the small-N vecmats a workgroup-level reduction tile (split-K). The vector-distribute pipeline already supports split-K dispatch configs (pipeline_vector_distribute_gfx942.mlir::@online_attention_split_k2), so the question is whether a split reduction plus combine restores bandwidth atnin {2048, 8192, 512} without an extra dispatch cost that eats the win.grid = (1,1,1),workgroup = (1,1,1), 3.86 ms for 128256 f32 logits.Recording this here so the split-K experiment is the next step, not a re-derivation.
perf(xla): raise the K tile for long-K vecmats on ROCm (#2874)
perf(xla): split the on-device argmax into two parallel stages (#2875)
perf(xla): keep the decode KV cache in the contraction precision (#3106)
test(xla): pin the wide vecmat predicates and correct the tuning notes
docs(xla): name the authoritative figure for the #2873 breakdown
test(xla): observe the vecmat tuning spec on the emitted decode graph
docs(xla): record the #2873 decode tuning and refresh the f16 baseline
perf(xla): give the narrow decode vecmats one output per thread (#2873)…