[DNM][WIP]attn: convert boolean template params to runtime dispatch#444
[DNM][WIP]attn: convert boolean template params to runtime dispatch#444jikunshang wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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_prefillandpaged_decodeinstantiation chains with runtimeboolfields andifbranches. - 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.
| const ElementSink* sm_sink; | ||
| bool is_paged; | ||
| bool is_causal; | ||
| bool is_local; | ||
| bool is_sink; |
| 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() |
|
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>
751491f to
519fcfb
Compare
|
UPDATE: we found perf regression(~15%), we will not merge this, just make it as a reference for now and will root cause. |
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
ifinstead ofif constexpr.Policy (tile-size) templates are preserved as they must remain compile-time for SYCL register allocation.
Results (default config build):
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor 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)