Skip to content

[DNM][WIP]attn: convert boolean template params to runtime dispatch#444

Draft
jikunshang wants to merge 1 commit into
vllm-project:mainfrom
jikunshang:refactor/runtime-bool-dispatch
Draft

[DNM][WIP]attn: convert boolean template params to runtime dispatch#444
jikunshang wants to merge 1 commit into
vllm-project:mainfrom
jikunshang:refactor/runtime-bool-dispatch

Conversation

@jikunshang

@jikunshang jikunshang commented Jun 30, 2026

Copy link
Copy Markdown
Member

UPDATE: we found perf regression(~15%), we will not merge this, just make it as a reference for now and will root cause.

Remove 5 boolean template parameters (Paged, Causal, Local, Sink, SoftmaxLSE) from chunk_prefill and 3 (Causal, Local, Sink) from paged_decode kernel instantiation chains. Boolean flags are now passed through the existing args structs and evaluated at runtime with regular if instead of if constexpr.

Policy (tile-size) templates are preserved as they must remain compile-time for SYCL register allocation.

Results (default config build):

  • Build time: 15m21s → 6m45s (-56%)
  • Template source files: 43 → 17 (-60%)
  • Full-build template files: 600 → 60 (-90%)
  • Binary size: ~unchanged (43M → 42M)
  • Performance: no regression (3276 tests pass)
  • Config files no longer need bool columns (backward compatible)

Essential Elements of an Effective PR Description Checklist

  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

PLEASE FILL IN THE PR DESCRIPTION HERE ENSURING ALL CHECKLIST ITEMS ABOVE HAVE BEEN CONSIDERED.

Purpose

Test Plan

Test Result

(Optional) Documentation Update

BEFORE SUBMITTING, PLEASE READ https://docs.vllm.ai/en/latest/contributing (anything written below this line will be removed by GitHub Actions)

Copilot AI review requested due to automatic review settings June 30, 2026 22:58

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.

Pull request overview

This PR refactors Xe2 attention kernel instantiation to reduce compile-time blowup by moving several boolean “feature” template parameters (paged/causal/local/sink/softmax_lse) into runtime flags carried through existing argument/parameter structs, while preserving compile-time policy templates that affect SYCL register allocation.

Changes:

  • Replace boolean template parameters in chunk_prefill and paged_decode instantiation chains with runtime bool fields and if branches.
  • Simplify generated extern/instantiation headers and CMake kernel-generation logic to build per-policy kernels (not per-boolean-combination kernels).
  • Update mainloop/epilogue argument plumbing so runtime feature flags reach device code.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
csrc/xpu/attn/xe_2/paged_decode.hpp Pass runtime flags through kernel/mainloop/epilogue argument structs; remove bool template params from config path.
csrc/xpu/attn/xe_2/paged_decode_utils.hpp Remove bool-combination dispatch; gate only on enabled policies.
csrc/xpu/attn/xe_2/paged_decode_kernel_template.cpp.in Generate explicit instantiations per policy (no bool macro axes).
csrc/xpu/attn/xe_2/paged_decode_extern.hpp.in Extern template declarations per enabled policy only.
csrc/xpu/attn/xe_2/paged_decode_extern.hpp Extern template declarations per policy only (non-generated header).
csrc/xpu/attn/xe_2/paged_decode_enabled_policies.hpp.in Drop policy+bool tuple traits; keep per-policy enablement.
csrc/xpu/attn/xe_2/paged_decode_configure.cmake Parse config as (qgroup, headsize, pagesize) and generate one TU per policy; ignore trailing bools.
csrc/xpu/attn/xe_2/kernel/paged_decode_kernel.hpp Add runtime feature flags into params; convert some if constexpr feature branches to runtime if.
csrc/xpu/attn/xe_2/kernel/chunk_prefill_kernel.hpp Move paged/causal/local/sink/softmax_lse decisions to runtime flags in params.
csrc/xpu/attn/xe_2/fmha_xe2.cpp Remove prior runtime restriction around softmax_lse specialization and simplify dispatch calls.
csrc/xpu/attn/xe_2/collective/chunk_prefill_mainloop.hpp Remove bool template axes and plumb runtime flags into mainloop params; convert masking/paging logic to runtime.
csrc/xpu/attn/xe_2/collective/chunk_prefill_epilogue.hpp Remove sink bool template axis; plumb sink as runtime parameter and branch in epilogues.
csrc/xpu/attn/xe_2/chunk_prefill.hpp Pass runtime flags to kernel/mainloop/epilogue args and wire has_softmax_lse.
csrc/xpu/attn/xe_2/chunk_prefill_utils.hpp Remove bool-combination dispatch; gate only on enabled policies.
csrc/xpu/attn/xe_2/chunk_prefill_kernel_template.cpp.in Generate explicit instantiations per policy (no bool macro axes).
csrc/xpu/attn/xe_2/chunk_prefill_extern.hpp.in Extern template declarations per enabled policy only.
csrc/xpu/attn/xe_2/chunk_prefill_extern.hpp Extern template declarations per policy only (non-generated header).
csrc/xpu/attn/xe_2/chunk_prefill_enabled_policies.hpp.in Drop policy+bool tuple traits; keep per-policy enablement.
csrc/xpu/attn/xe_2/chunk_prefill_configure.cmake Parse config as head sizes and generate one TU per policy; ignore trailing bools.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 144 to +148
const ElementSink* sm_sink;
bool is_paged;
bool is_causal;
bool is_local;
bool is_sink;
Comment on lines +226 to 230
string(REGEX MATCH "_q([0-9]+)_h([0-9]+)_p([0-9]+)$" _unused
"${IMPL_POLICY}")
if(NOT CMAKE_MATCH_1)
message(WARNING "Could not derive filename suffix for policy ${IMPL_POLICY}")
continue()
@rogerxfeng8

Copy link
Copy Markdown
Collaborator

What's the wheel size with the PR using the full config?

@jikunshang

Copy link
Copy Markdown
Member Author

What's the wheel size with the PR using the full config?

67MB https://github.com/vllm-project/vllm-xpu-kernels/actions/runs/28481312527?pr=444

Remove 5 boolean template parameters (Paged, Causal, Local, Sink,
SoftmaxLSE) from chunk_prefill and 3 (Causal, Local, Sink) from
paged_decode kernel instantiation chains. Boolean flags are now
passed through the existing args structs and evaluated at runtime
with regular `if` instead of `if constexpr`.

Policy (tile-size) templates are preserved as they must remain
compile-time for SYCL register allocation.

Results (default config build):
- Build time: 15m21s → 6m45s (-56%)
- Template source files: 43 → 17 (-60%)
- Full-build template files: 600 → 60 (-90%)
- Binary size: ~unchanged (43M → 42M)
- Performance: no regression (3276 tests pass)
- Config files no longer need bool columns (backward compatible)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Kunshang Ji <kunshang.ji@intel.com>
@jikunshang
jikunshang force-pushed the refactor/runtime-bool-dispatch branch from 751491f to 519fcfb Compare July 1, 2026 07:46
@jikunshang
jikunshang marked this pull request as draft July 7, 2026 01:38
@jikunshang jikunshang changed the title [WIP]attn: convert boolean template params to runtime dispatch [DNM][WIP]attn: convert boolean template params to runtime dispatch Jul 7, 2026
@jikunshang

Copy link
Copy Markdown
Member Author

UPDATE: we found perf regression(~15%), we will not merge this, just make it as a reference for now and will root cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants