Skip to content

[HIP] [Perf] scaled_silu_and_mul: split short batches across workgroups - #6656

Merged
junhaha666 merged 4 commits into
ROCm:mainfrom
AndreasKaratzas:akaratza/scaled-silu-and-mul-decode-speed
Oct 21, 2026
Merged

junhaha666 merged 4 commits into
ROCm:mainfrom
AndreasKaratzas:akaratza/scaled-silu-and-mul-decode-speed

Conversation

@AndreasKaratzas

@AndreasKaratzas AndreasKaratzas commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

scaled_silu_and_mul launches one workgroup per row, so decode-sized batches use only a few CUs. On MI300X a 14336-wide row is walked by a single 512-thread workgroup in four dependent load rounds, and the call takes about 4.5 us at M = 1-64 against a 1.6 us empty-launch floor. That is slower than the fused SiLU-mul + static FP8 quant kernel Inductor generates for the same graph (2.5-2.8 us), which keeps the op out of vLLM's AITER path for Llama-style FP8 models.

Depends on #6641 (stacked on its branch; the first two commits are #6641).

  • Split each row over several workgroups (grid.y) when there are fewer than 16 rows per CU, with at most 4 waves per workgroup below 2 rows per CU. Larger batches keep the current launch.
  • Pass the column offset and stride to scaled_act_and_mul_kernel as arguments, so the first loads don't wait on the implicit grid/block size arguments.
  • Read the scale after the data loads are issued, so the two latencies overlap.
  • Mark the v_pk_mul_f32 asm output early-clobber. The asm writes %0 before it reads %3. With the new register allocation, the vec_size == 2 kernels put the scale and the output in the same VGPRs (d <= 8 gave wrong values).

Thresholds are in rows per CU, but only gfx942 was measured.

To test:

Results:

  • Outputs match [HIP] [Bugfix] scaled_silu_and_mul: device-side scale, fp8 saturation, row bounds #6641 byte for byte except one element in an odd-d row's scalar tail: fast-math no longer reassociates that multiply, so it now rounds like the vector path and matches the fp64 reference.
  • The correctness suite passed all 864 cases in 10 of 10 seeded runs; graph replay and the edge-case test pass.
  • Time in us at d = 14336, bf16 -> fp8, median per GPU, range over 4 MI300X GPUs:
M #6641 this PR Inductor fused kernel (vLLM's pick)
1 4.45-4.53 1.86-1.91 2.51-2.54
4 4.57-4.65 1.92-1.93 2.54-2.59
32 4.62-4.76 2.03-2.04 2.70-2.73
64 4.70-4.78 2.36-2.37 2.82-2.85
128 4.93-4.96 2.98-3.02 4.14-4.18
256 5.94-5.99 4.79-5.14 5.98-6.13
512 10.06-10.21 8.82-8.91 11.42-11.55
1024 22.05-22.51 20.73-21.67 23.03-23.45
4096 82.65-86.96 82.26-86.22 97.09-100.44
16384 323.4-330.5 323.4-328.6 424.7-450.7

It is at least as fast as #6641 at every M up to 16384, and the same holds for d = 1000-28672. At d = 128 the launch is unchanged and the time stays within 0.04 us.

AndreasKaratzas and others added 3 commits October 16, 2026 02:14
…, row bounds

scaled_act_and_mul_kernel had three defects:

- The scale was dereferenced on the host at launch. Under CUDA/HIP graph
  capture its value was frozen, and a scale written by a still-running
  kernel on the same stream was read stale. Pass the pointer and compute
  1/scale in the kernel.
- Values beyond the output range were converted unclamped, and
  v_cvt_pk_fp8_f32 turns |x| >= 248 into NaN on gfx942. Saturate to the
  output type's finite range (fp8 or int8) before the cast.
- When d was not a multiple of the vector size, the last vector store of
  each row spilled into the next row (and past the end of the tensor for
  the last row), and rows were assumed to be packed. Store the partial
  last vector element-wise and honour the input/output row strides.

Also check the scale/out arguments, and add a regression test.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
Fill the guard row and padding columns with 0x5A instead of zeros so an
out-of-bounds fp8 zero write is caught, and check the guard before the
value asserts so an overrun is reported as such.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
scaled_act_and_mul_kernel ran one workgroup per row. At decode batch
sizes that leaves most of the GPU idle: on MI300X a single 512-thread
workgroup walked a 14336-wide row in four dependent load rounds, and
the call took 4.5 us at M = 1-64 against a 1.6 us empty-launch floor.

- With fewer than 16 rows per CU, split each row over grid.y
  workgroups (up to 16 per CU in total), capped at 4 waves per
  workgroup below 2 rows per CU. Larger batches keep the old launch.
- Pass the column offset and stride as kernel arguments, so the first
  loads do not wait on the implicit grid and block size arguments.
- Read the scale after issuing the data loads so the two latencies
  overlap.
- Mark the v_pk_mul_f32 asm output early-clobber. The asm writes %0
  before reading %3, and with the new register allocation the vec_size 2
  kernels got the scale and output in the same VGPRs.

On MI300X with bf16 input, d = 14336, the call goes from 4.5 us to
1.9-2.0 us at M = 1-32 and from 5.9-6.0 to 4.8-5.1 us at M = 256. It is no
slower at any M up to 16384. The output is bit-identical except one
element of the odd-d scalar tail: fast-math no longer reassociates the
multiply there, so it now rounds the same way as the vector path.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Andreas Karatzas <[email protected]>
@AndreasKaratzas
AndreasKaratzas requested a review from a team October 18, 2026 19:48
@github-actions github-actions Bot added the HIP label Oct 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 6656 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@ChuanLi1101 ChuanLi1101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On MI300, a 14336-wide row at M=1 goes from about 4.5 µs to 1.9 µs. Large M stays flat. The split starts when there are fewer than 16 rows per CU, and that threshold was only timed on gfx942. Please add one short batch on MI355. The early-clobber has to stay with this launch change: d <= 8 was wrong after the new register allocation.

vgokhale
vgokhale previously approved these changes Oct 19, 2026
@AndreasKaratzas
AndreasKaratzas force-pushed the akaratza/scaled-silu-and-mul-decode-speed branch from e23155f to 81cfd1c Compare October 19, 2026 22:40
@AndreasKaratzas

Copy link
Copy Markdown
Contributor Author

Merged main, so the #6641 commits no longer show up in the diff; this PR now only changes activation_kernels.cu.

MI355 (gfx950, 256 CUs, so the split covers M < 4096). Time in us at d = 14336, bf16 -> fp8, under HIP graphs, median of 3 interleaved processes per build, range over 2 GPUs:

M main this PR
1 4.03-4.07 1.98-2.06
4 4.18 2.04-2.05
32 4.27 2.13-2.15
64 4.30-4.31 2.36-2.37
128 4.48-4.51 3.07-3.09
256 5.31-5.33 4.28-4.29
512 8.74-8.79 7.73-7.75
1024 14.55-14.60 13.99-14.07
4096 53.51-53.69 52.41-52.45
16384 237.5-239.9 235.5-238.3

d = 1000, 4096 and 28672 are also faster or unchanged; at d = 128 the change is at most +0.07 us on the ~2 us launch floor. Outputs are byte-identical to main over 1014 cases (bf16/fp16/fp32 input, fp8/int8 output, d 2-28672 including odd d, M on both sides of the thresholds), and op_tests/test_activation.py passes 3/3 on MI355.

@junhaha666
junhaha666 merged commit e999585 into ROCm:main Oct 21, 2026
@AndreasKaratzas
AndreasKaratzas deleted the akaratza/scaled-silu-and-mul-decode-speed branch October 22, 2026 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants