Skip to content

[Triton/Gluon] Updates to causal_conv1d_split_qkv kernel - #7028

Merged
azaidy merged 9 commits into
mainfrom
omuhamma/kda-prefill-conv1d
Nov 23, 2026
Merged

azaidy merged 9 commits into
mainfrom
omuhamma/kda-prefill-conv1d

Conversation

@omuhamma

@omuhamma omuhamma commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

slowdown when ISL increased on Kimi K3 when this kernel was called

Test Plan

Benchmark, Unit tests, e2e perf/accuracy

Test Result

e2e numbers (32k isl 32 osl 32 conc 32 prompts)

  • Tested 1k 1k 64 64 as well, same performance when the size is smaller
image

e2e accuracy verified with gsm8k

All benchmarks pass (bit exact result as before)

benchmark numbers:

image

Submission Checklist

PR Self-Review

Reviewed revision

4e7d587

Behavior and intent

causal_conv1d_split_qkv_triton_tile_fn got slow on Kimi-K3 prefill as ISL grew. In vLLM, x is a column slice of the row-major projection output (unit channel stride). The 2D-tiled kernel reads along tokens, so those loads are strided and poorly vectorized.

This PR adds a sliding-window kernel for that case. Each program loads x rows along channels (16 B per lane) and keeps the 4-tap window in registers. Head programs handle the first 3 tokens and the conv-state update of each sequence. The wrapper picks this kernel only when all of these hold:

  • x has channel stride 1
  • conv width is 4 and the weight is contiguous
  • dim == 2*k_dim + v_dim
  • the conv-state dtype is x's dtype or fp32
  • a tuned config exists for the arch (gfx950, gfx1250)
  • BD divides k_dim and v_dim
  • offsets fit in 32 bits

In every other case it falls back to the 2D-tiled kernel. AITER_CONV1D_SPLIT_QKV_WINDOW=0 turns the window kernel off.

Other changes:

  • 2D-tiled kernel:
    • block_n now defaults to 16 B per lane for channel-contiguous x, and stays 32 otherwise.
    • Blocks that fall entirely inside q, k or v (QKV_ALIGNED) do a single store.
    • SiLU uses the shared _silu_exp2_fast, which is the same v_rcp_f32 path that was inline asm before.
  • 1D kernel: SiLU uses the shared _silu_exp2.
  • New shared helpers: _silu_exp2_fast and _lower_bound.
  • The window kernel takes cache_indices' stride, so strided indices such as indices[::2] work. No copies are added.

Validation and unverified scope

Validated on MI355X (gfx950), torch 2.13.0+rocm10.0.0, triton 3.8.0, at the revision above:

  • pytest op_tests/triton_tests/gated_delta_net/test_causal_conv1d_prefill.py: 46 passed.
  • The strided cache_indices test fails on the window kernel when the stride is forced to 1, and passes with the fix.
  • python op_tests/op_benchmarks/triton/bench_causal_conv1d_prefill.py. Times are CUDA-graph replays, Kimi-K3 TP8 shapes (q/k/v = 1536), block_m=8. The baseline is this PR's 2D-tiled kernel with the window kernel off:
case 2D tile (us) window (us) speedup
one continuing chunk of 7680, row stride 6288 33.81 21.99 1.5x
continuing 5010 + new 2680, gathered 33.82 22.17 1.5x
7 new prompts of 1112, gathered 34.13 22.39 1.5x
60 new prompts of 128, gathered 39.82 23.40 1.7x
one prompt of 1024, row stride 6288 7.47 5.57 1.3x
  • E2E Kimi-K3: 32k ISL / 32 OSL / concurrency 32 / 32 prompts and 1k/1k/64/64 for perf, plus gsm8k for accuracy. These ran on the revision before 4e7d587. That commit only adds the cache_indices stride, sends non-contiguous weights to the tiled kernel, and touches tests.

Not verified:

  • gfx1250: the config is in place, but nothing was run on that hardware.
  • gfx942 and other archs without a window config: they use the 2D-tiled kernel. That path is covered by the AITER_CONV1D_SPLIT_QKV_WINDOW=0 tests on gfx950 but was not run on gfx942 itself.
  • Bit-exactness against main: the tests compare against an fp32 reference (atol/rtol 2e-2, conv states exact), not against main's output. The 1D kernel's SiLU moved from exp to exp2, which can change the last bits.

PR-specific question

The new configs are CAUSAL_CONV1D_SPLIT_QKV in configs/{gfx950,gfx1250}/triton/conv/causal_conv1d_split_qkv/DEFAULT.json. Only the window kernel reads them, through get_conv_config(..., M=cu_seqlen), where M is the total number of tokens in the batch:

  • M_LEQ_2048: R=4, BC=4, BD=256
  • any: R=4, BC=8, BD=512

If BD doesn't divide k_dim and v_dim, the wrapper halves BD and doubles R (down to BD=64). If that still doesn't divide, it falls back to the tiled kernel.

Evidence that unrelated shapes keep their previous selection:

  • x with token stride 1 never uses these configs. test_token_contiguous_x_uses_2d_kernel checks for zero window launches.
  • AITER_CONV1D_SPLIT_QKV_WINDOW=0 and archs with no config select the 2D-tiled kernel. test_window_kernel_selection checks this against has_conv_config.
  • causal_conv1d_split_qkv_triton_fn (1D) and the other conv backends don't read these configs.

The 2D-tiled kernel's own launch did change for channel-contiguous x (block_n default and the QKV_ALIGNED single store). test_2d_tiled_kernel_kimi_k3_shapes covers that. Token-contiguous x keeps block_n=32.

Changed op tests

  • op_tests/triton_tests/gated_delta_net/test_causal_conv1d_prefill.py (new): no existing test covered causal_conv1d_split_qkv_triton_tile_fn with channel-contiguous x, which is the layout vLLM passes. It checks q/k/v and the updated conv states against an fp32 reference. Cases:

    • Kimi-K3 and Qwen3-Next shapes
    • many sequences (the binary-search path past SEQ_VEC)
    • both conv-state layouts and state lengths
    • pad slots, bias, activation, fp32 conv state
    • strided cache_indices
    • the 2D-tiled kernel with the window kernel off
    • kernel selection: env flag, arch config, token-contiguous x
  • op_tests/op_benchmarks/triton/bench_causal_conv1d_prefill.py (new): no benchmark existed for this op. It times the window kernel against the 2D-tiled kernel on Kimi-K3 prefill shapes, called the way vLLM calls it (block_m=8, prebuilt metadata, CUDA graphs), and reports speedup and TB/s.

  • Look over the contributing guidelines at https://github.com/ROCm/TheRock/blob/main/GOVERNANCE.md#pull-requests.

@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 7028 --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.

@omuhamma
omuhamma marked this pull request as ready for review October 27, 2026 14:43
@omuhamma
omuhamma requested a review from a team October 27, 2026 14:43
@omuhamma omuhamma self-assigned this Oct 27, 2026
@github-actions github-actions Bot changed the title Updates to causal_conv1d_split_qkv kernel [Triton/Gluon] Updates to causal_conv1d_split_qkv kernel Oct 27, 2026
@azaidy
azaidy self-requested a review October 27, 2026 15:20
@Boss2002n
Boss2002n requested a balanced review from Copilot October 27, 2026 17:33

Copilot AI 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.

🟡 Changes recommended

The window kernel mishandles strided cache indices and can overwrite another sequence’s state, while the gfx942 test incorrectly requires a window launch when no window configuration exists.

2 open issues
What changed in this PR

This PR targets long-input prefill slowdowns in the gated-delta-net causal convolution path. It adds a sliding-window implementation for channel-contiguous inputs while retaining the existing tiled fallback.

Changes:

  • Add width-4 sliding-window dispatch with gfx950 and gfx1250 configs and an environment opt-out.
  • Adjust tiled-kernel sizing and Q/K/V stores, and reuse shared activation helpers.
  • Add correctness tests and a benchmark comparing window and tiled paths.
File Description
op_tests/​triton_tests/​gated_delta_net/​test_causal_conv1d_prefill.py Add correctness, state-layout, and dispatch tests.
op_tests/​op_benchmarks/​triton/​bench_causal_conv1d_prefill.py Compare window and tiled prefill latency.
aiter/​ops/​triton/​gated_delta_net/​causal_conv1d_prefill.py Dispatch eligible inputs to the window kernel and adjust fallback tiling.
aiter/​ops/​triton/​configs/​gfx950/​triton/​conv/​causal_conv1d_split_qkv/​DEFAULT.json Add gfx950 window-kernel configs.
aiter/​ops/​triton/​configs/​gfx1250/​triton/​conv/​causal_conv1d_split_qkv/​DEFAULT.json Add gfx1250 window-kernel configs.
aiter/​ops/​triton/​_triton_kernels/​gated_delta_net/​prefill/​causal_conv1d_fwd_split_qkv.py Implement sliding windows and optimize aligned Q/K/V stores.
aiter/​ops/​triton/​_triton_kernels/​common/​segment_tile.py Add a lower-bound helper for sequence lookup.
aiter/​ops/​triton/​_triton_kernels/​common/​activation.py Add a shared fast SiLU helper.

Review effort: Balanced

@aiter-bot

aiter-bot commented Oct 29, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision de1cbe9b5aed · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

Copilot AI 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.

🟡 Changes recommended

The new window path does not support pad_slot_id=None, and its BD-halving and divisibility-fallback dispatch branches lack output and launch-selection tests.

3 open issues
2 resolved since last review

Review effort: Balanced

@omuhamma
omuhamma force-pushed the omuhamma/kda-prefill-conv1d branch from 9c284f6 to 997f935 Compare November 6, 2026 15:56
Window kernel read cache_indices with unit stride, so strided indices
(e.g. indices[::2]) hit wrong conv-state slots. Pass the stride as the
tiled path does. Send non-contiguous weights to the tiled kernel instead
of copying them. Selection test now accounts for archs without a window
config and sets the env flag explicitly.
@omuhamma
omuhamma force-pushed the omuhamma/kda-prefill-conv1d branch from f1dea04 to 5e18409 Compare November 11, 2026 15:45
Resolve the conflict with the plugin route on causal_conv1d_split_qkv_triton_tile_fn
(#8075): keep the route and its provider contract alongside the window kernel.
Keep block_n: int = 32 so the routed contract (tests/plugin_contracts.json) is
unchanged; the window kernel does not read block_n. Pass pad_slot_id to
_window_config in the benchmark.

Copilot AI 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.

🟡 Changes recommended

The dispatch gate admits broadcast inputs that violate the window kernel’s stride precondition, while the benchmark bypasses the required harness and ignores its options.

2 open issues
3 resolved since last review

Review effort: Balanced

…ench

Broadcast x (token stride 0) now takes the 2D-tiled path, as the window
kernel assumes stride_x > 0. The benchmark uses RotatingBufferBench with
the --graph-* and --rot-bufs-* options and shares the unit test's input
generator.

@azaidy azaidy 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.

LGTM!

@azaidy
azaidy merged commit 2bd3416 into main Nov 23, 2026
68 checks passed
@azaidy
azaidy deleted the omuhamma/kda-prefill-conv1d branch November 23, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants