Repository navigation
[HIP] [JIT] Add gfx950 prefill FP8 MQA logits - #7183
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
Co-authored-by: OpenAI Codex <[email protected]> Signed-off-by: Sumin Hong <[email protected]>
4403a8a to
460c230
Compare
|
@amd-ruitang3 could you please review this? |
|
I validated this PR after a local rebase onto ROCm/aiter main. The rebase completed without conflicts. The HIP kernel, wrapper, header, pybind source, and PR op test are unchanged from the original PR head.
Environment: container rui_1106, image rocm/atom-dev:nightly_202611060646; gfx950 with 256 CUs; ROCm/hipcc 7.2.4; PyTorch 2.10.0+rocm7.2.4.git3d3aa833; Triton 3.8.0; FlyDSL 0.5.0. The Triton public entry selected the gfx950 Gluon kernel. FlyDSL was installed into an isolated directory because the image supplied 0.4.2 and current main requires 0.5.0. Correctness passed for the supported shape/dtype contract:
The PR suite uses the entry point below. My full run used an external wrapper to enforce the additional assertion and record each result: python3 op_tests/test_fp8_mqa_logits.py --num-heads 32 --head-dim 128 Cold-cache performance: public APIs with default launch heuristics and internally allocated output. Each sample follows a 1 GiB cache fill and synchronization. There are 10 warmup calls and three rounds of 21 samples, with backend order rotated between rounds. Values are the median of the three round medians, in microseconds. Gluon clean-mode output initialization is included. I summed actual GPU kernel durations inside each isolated GPU annotation range in the profiler trace. Cache-flush kernels and CPU launch gaps are excluded. This avoids a ROCTracer CPU-correlation issue observed during the run, where unrelated cache fills could be attributed to the measured call.
For the 32K/64K/128K single-request cases, clean-mode speedup over current Gluon is 1.68–1.72×. For four requests on those shapes, it is 1.26–1.50×. At 8192 × 8192 with four requests, clean is close to Gluon, while no-clean is 15.5% slower (61.56 vs 53.32 μs). The small 64 × 2048 smoke case is also slower than FlyDSL. These results support selecting the backend by shape and workload. The FlyDSL column uses current main’s default variants with FlyDSL 0.5.0, without a best-variant search: mfma32x32x64_bkv64_r2_w4_lds3 for 8192 × 8192, and mfma32x32x64_bkv64_r2_w2_lds3 for the three long-context shapes. This is a different baseline from the earlier revisions in the PR description, so these measurements are not a reproduction of the historical 1.32× geomean against that older FlyDSL baseline. Scope: this validates operator correctness and operator-level performance after rebase on ROCm 7.2.4. I did not repeat vLLM model evaluation, top-k output comparisons, needles tests, or TTFT measurements, so this run does not establish end-to-end speedup. |
|
@sumin-hong We cannot include |
Review on ROCm#7183: csrc .h/.cu must not include torch headers (slow compiles, .so tied to one PyTorch version). Follow the torch-free pattern of mega_mhc / dsv4_dequant_gather_k: - fp8_mqa_logits.h: include only aiter_tensor.h; aiter::fp8_mqa_logits takes aiter_tensor_t and writes into a caller-provided `out`. - fp8_mqa_logits.cu: TORCH_CHECK -> AITER_CHECK, at:: HIP guard/stream -> HipDeviceGuard + aiter::getCurrentHIPStream(); dtype checks on AiterDtype; add a same-device check. Kernel-local WARP_SIZE renamed to WAVE_SIZE (collides with aiter_hip_common.h's WARP_SIZE). - pybind: AITER_EXTENSION_NAME + AITER_SET_STREAM_PYBIND; out is the first, required argument; the ignored unroll2 is no longer bound. - optCompilerConfig.json: module_fp8_mqa_logits is torch_exclude. - aiter/ops/fp8_mqa_logits.py: compile_ops(develop=True) binding `_fp8_mqa_logits`; the public fp8_mqa_logits keeps its signature and allocates `out` (torch.empty [M, N] f32) when it is None. The 8 kernel instantiations compile to the same gfx950 ISA as before (ROCm 7.2.3, label-normalized diff), and the built .so links no torch/c10 library. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_012r9e4kzvV1zZxs8eymhVjv Signed-off-by: namle <[email protected]>
Use aiter_tensor_t, explicit output and AITER stream plumbing in the native module. Preserve the public Python signature and output reuse. Keep argument failures catchable with AiterThrowGuard. Co-authored-by: OpenAI Codex <[email protected]> Signed-off-by: Sumin Hong <[email protected]>
|
Addressed the Torch-dependency request in this follow-up. The native header/kernel/pybind use CPU wrapper/exception checks, Black/Ruff, changed-line clang-format and source/device-code comparisons passed. Device arithmetic and launch logic are unchanged after the WARP_SIZE/WAVE_SIZE rename. A clean HIP build, |
Merge current main after ROCm#7183 and retain both prefill and paged MQA registrations in the shared compiler configuration and pybind header. Preserve upstream header additions and the reviewed paged kernel/API. Co-authored-by: OpenAI Codex <[email protected]> Signed-off-by: Sumin Hong <[email protected]>
…rd (#8507) * Reapply "[HIP] [JIT] Add gfx950 prefill FP8 MQA logits" (#7183) This reverts commit cf16a55 (#8504), restoring the operator from #7183 by @sumin-hong unchanged. The build fix follows in the next commit. * [HIP] fp8_mqa_logits: guard the gfx950 kernel for multi-arch builds The kernel uses __builtin_amdgcn_mfma_scale_f32_32x32x64_f8f6f4 and v_permlane32_swap_b32, which exist only on gfx950, so building with GPU_ARCHS="gfx942;gfx950" failed with "needs target feature gfx950-insts". Compile the kernel body only for __gfx950__ and trap elsewhere, as the other gfx950-only kernels do. fp8_mqa_logits() now raises on other archs instead of launching the stub.
[HIP] [JIT] fp8_mqa_logits: v35w gfx950 prefill indexer logits kernel
Motivation
This PR adds a faster HIP kernel for the prefill fp8 MQA indexer logits used by GLM-5.x / DeepSeek-V3.2 sparse attention, on gfx950 (MI355X):
The added API and JIT module are:
aiter.ops.fp8_mqa_logits.fp8_mqa_logits/is_supportedmodule_fp8_mqa_logitsIt is an alternative to the Triton/Gluon
aiter.ops.triton.attention.fp8_mqa_logits. It supports n_heads = 32 and head_dim = 128 only; other shapes are routed viais_supported().Design (
csrc/kernels/fp8_mqa_logits.cu)vmcntwaits are placed by hand, becausevmcntalso counts the logits stores and compiler-derived waits drain them every stage.v_mfma_f32_32x32x64_f8f6f4. The fp32 epilogue is scalar (v_maxrelu,v_fmawith w) and is interleaved under the MFMAs. On gfx950, scalar VALU co-issues with an independent MFMA, but packedv_pk_*does not. Accumulation uses even/odd chains in a fixed order.v_permlane32_swaphead reduction is inline asm, because the clang builtin miscompiles its 2nd result on ROCm 7.2.3. kv_scale is applied after the reduction. The tail of each row pair is deferred by one sub-tile so it fills the MFMA→VALU hazard window, which leaves nos_nopin the loop.grid.y = SplitN. Withclean_logitsthe kernel writes -inf itself, so there is notorch.fullpass.(SplitN, reverse_rows)comes from a makespan model fitted on MI355X.-fno-honor-nans -fno-slp-vectorize -mllvm -disable-machine-sink:-fno-slp-vectorize: otherwise the epilogue is re-packed intov_pk_fma.-mllvm -disable-machine-sink: otherwise the last row's MFMA pair sinks past the loop exit.Kernel time on the GLM-5.3-Flash table shapes (MI355X, µs, clean_logits=True)
Setup:
vllm/vllm-openai-rocm:v0.30.0.Geomean vs FlyDSL #4538: 1.32× with clean_logits=True and 1.39× with clean_logits=False. It is also faster than every stronger baseline we measured, per shape:
3.7.0+amd.rocm7.2.0.git89002410)Against the best of those on each shape, the geomean is 1.26× (clean) and 1.30× (no-clean). The one exception is 8192×8192 multi_req, where this PR loses by 3% (clean) and 18% (no-clean, vs Gluon on the AMD Triton).
Test plan
python3 op_tests/test_fp8_mqa_logits.py --num-heads 32 --head-dim 128: all 150 HIP cases pass. They cover 6 window modes (causal, cp, misaligned, empty, past_end, multi_req), clean_logits 0/1, and a NaN-poisoned output buffer. The -inf mask matches exactly andcheckAllcloseerr = 0.Known limitations
SplitN=20. Callers that know the layout can passSplitN; a layout-aware heuristic is a follow-up.is_supported()plus a size gate in the caller if needed.emptyandpast_endop-test modes).Review update (2026-11-16)
Follow-up
48906854b749e5b4361e0e93ec1d5bb9b59423e1removes Torch/ATen/c10 dependencies from this operator's native header, kernel and pybind source. The native entry takesaiter_tensor_twith a required output buffer, usesHipDeviceGuard/aiter::getCurrentHIPStream(), and registersAITER_EXTENSION_NAMEplusAITER_SET_STREAM_PYBIND. The JIT module enablestorch_exclude.The public
fp8_mqa_logitsPython signature is unchanged. It allocates FP32 output whenout=None, otherwise reuses the supplied buffer, and calls the privatedevelop=Truebinding. Native argument failures are guarded byAiterThrowGuardso Python receives an exception.CPU wrapper tests cover allocation, output identity and tunable forwarding. Static checks preserve device arithmetic and launch logic after the local
WARP_SIZE→WAVE_SIZErename. No local HIP toolchain or gfx950 GPU is available, so a clean JIT build, shared-library linkage inspection, current-head GPU correctness and benchmarks were not run here. Historical measurements retain their original builds.Related work
Current validation
AI assistance: Claude Code was used in the source development; OpenAI Codex was used for the rebase, static validation, and preparation of this PR.
PR Self-Review
Reviewed revision
48906854b749e5b4361e0e93ec1d5bb9b59423e1Behavior and intent
This adds an opt-in gfx950 HIP prefill MQA logits operator. It computes weighted ReLU dot products over a contiguous gathered K buffer and supports clean or caller-managed output masks; existing Triton/Gluon and FlyDSL paths remain available. The aim is improved performance for the supported GLM indexer shapes.
Validation and unverified scope
The supplied review fix was compared by Python AST/C++ tokens, with the prefill exception guard added locally. Device-kernel arithmetic and launch code are preserved after the WARP_SIZE/WAVE_SIZE rename. Black 26.3.0, Ruff 0.15.7, changed-line clang-format 18.1.8, syntax and diff checks passed. CPU wrapper tests cover allocation, supplied-output reuse and tunable forwarding; the C++ host harness exercises exception-guard behavior. No local HIP toolchain or gfx950 GPU is available, so a clean JIT build, shared-library linkage inspection, current-head GPU correctness and benchmarks were not run here. Historical measurements retain their original builds.
PR-specific question
The intended contract is gfx950, 32 heads, head dimension 128, FP8 Q/K, float32 scales and weights, and int32 row bounds. The caller must check is_supported and supply the documented dtypes and contiguous layouts; the operator does not automatically route unsupported inputs. The C++ entry checks shape, contiguity and one-byte Q/K storage, but one-byte storage alone does not prove the FP8 dtype.
Changed op tests
op_tests/test_fp8_mqa_logits.py compares the new operator and Triton to the reference with clean and unclean outputs, poisoned buffers, causal, CP, misaligned, empty, past-end and multi-request windows. This new HIP entry and its masking behavior are not covered by the existing backend-only tests.