Skip to content

perf(xla): close the IREE decode-kernel efficiency gap (small-M vecmats and the serial argmax) #2873

Closed

Description

@inureyes

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.

  1. 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.

  2. 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

  1. 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_general at 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).
  2. 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.
  3. 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.
  4. 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 keep REFERENCE-EXACT on xla_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=1 vs n=128 trace 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-xla lib tests with unchanged goldens, and clippy at default and iree features 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.

Refs #2859, #2863

Activity

  1. added
    type:performance
    status:investigation
    area:inference
    priority:high
    on Nov 6, 2026
  2. inureyes commented on Nov 6, 2026

    @inureyes
    MemberAuthor

    First follow-up trace on the vecmat question, from the pinned iree-compile (3.12.0rc20260721) compiled for gfx1151.

    The small-N and large-N vecmats get the same lowering config from the default strix-halo tuning module:

    #iree_gpu.lowering_config<{reduction = [0, 4], thread = [8, 0], workgroup = [256, 0]}>
    

    for n = 2048, 8192, and 128256, 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 = 8192 launches 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 = 128256 launches 16032 workgroups and saturates. The same config also explains why n = 512 and n = 2048 sit at the same about 50 GB/s.

    Candidate directions, cheapest first:

    1. A custom tuning spec passed through --iree-codegen-tuning-spec-path that 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 at n in {2048, 8192, 512} without an extra dispatch cost that eats the win.
    2. If split-K does not pay at these sizes, fuse q/k/v and gate/up into one wider contraction per layer, which raises each shape toward the range where the default config already saturates.
    3. The argmax stays a separate fix: its dispatch is 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.

  3. added
    status:in-progress
    status:review
    and removed
    status:investigation
    status:in-progress
    on Nov 16, 2026
  4. added
    status:done
    and removed
    status:review
    on Nov 18, 2026
  5. added this to the 0.9 milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:inferencepriority:highstatus:donetype:performance

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions