Repository navigation
[HIP] [Perf] scaled_silu_and_mul: split short batches across workgroups - #6656
junhaha666 merged 4 commits into
Conversation
…, 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]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
ChuanLi1101
left a comment
There was a problem hiding this comment.
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.
Signed-off-by: Andreas Karatzas <[email protected]>
e23155f to
81cfd1c
Compare
|
Merged main, so the #6641 commits no longer show up in the diff; this PR now only changes 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:
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 |
scaled_silu_and_mullaunches 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).
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.scaled_act_and_mul_kernelas arguments, so the first loads don't wait on the implicit grid/block size arguments.v_pk_mul_f32asm output early-clobber. The asm writes%0before it reads%3. With the new register allocation, thevec_size == 2kernels 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:
test_scaled_silu_and_mul_edge_cases.Results:
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.