Skip to content

[xegpu] Generalize reduction schedule to work with nD inputs - #278

Merged
tkarna merged 9 commits into
llvm:mainfrom
tkarna:xegpu-rms-reduction
Sep 11, 2026
Merged

tkarna merged 9 commits into
llvm:mainfrom
tkarna:xegpu-rms-reduction

Conversation

@tkarna

@tkarna tkarna commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Updates reduction_schedule so that KernelBench level1/36_RMSNorm_.py case can be executed.

  • Generalized reduction_schedule parameters: wg_tile, sg_tile, reduction_tile parameters are n-D lists.
  • Adds optional wg_subtile parameter to add a persistent for loop to reduce WG tile size.
  • Reductions are tiled with tile_using_for; avoids iter dim permutation issue caused by tile_reduction_using_for.
  • Applies math-expand-ops pass after vectorization; e.g. pow(x, 2) -> x*x
  • Adds sink_extract_slice_into_loop transform_ext op to avoid spurious vector.transfer_read/write patterns.
  • The common vectorize function takes disable_multi_reduction_to_contract_patterns argument; Setting it avoids converting vector.multi_reduction ops to vector.contract which xegpu lowering does not support correctly at the moment.

Assisted-by: Claude

- reductions are tiled with tile_using_for; avoids iter dim permutation
  issue in tile_reduction_using_for
- add optional wg_subtile parameter
- apply math-expand-ops after vectorization; pow(x, 2) -> x*x
- support kernelbench rms norm case
@tkarna
tkarna requested review from adam-smnk and a lite review from Copilot September 10, 2026 18:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

examples/xegpu/kernel_bench.py can raise an UnboundLocalError because layer_params is not initialized for unsupported elemwise+reduction shapes/iterator layouts before it is used.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR updates the XeGPU reduction scheduling pipeline to support nD inputs (notably enabling KernelBench level1/36_RMSNorm_.py) by generalizing tiling parameters and adding a new transform to simplify slice patterns before vectorization.

Changes:

  • Generalizes reduction schedule parameters to nD (wg_tile, sg_tile, reduction_tile) and adds optional wg_subtile for persistent workgroup sub-tiling.
  • Adds a new sink_extract_slice_into_loop transform extension op (with tests) and uses it in the reduction schedule to avoid problematic extract/insert slice patterns prior to vectorization.
  • Adjusts vectorization and lowering behavior (disable multi-reduction→contract patterns; apply math-expand-ops after vectorization) and updates example parameter wiring.
File summaries
File Description
test/transform/test_sink_extract_slice_into_loop.py Adds a FileCheck test validating the new sink transform behavior on matching vs non-matching loops.
lighthouse/schedule/xegpu/reduction_schedule.py Generalizes reduction tiling to nD, adds optional WG subtile loop, sinks extract-slices into loops, and updates vectorization/lowering sequencing.
lighthouse/schedule/xegpu/lowering_common.py Extends the common vectorize helper with a flag to disable multi-reduction→contract patterns.
lighthouse/dialects/transform/transform_ext/ops/sink_extract_slice_into_loop.py Implements the new transform extension op to sink tensor.extract_slice loop inits into scf.for.
lighthouse/dialects/transform/transform_ext/__init__.py Exports the new sink_extract_slice_into_loop op from the extension package.
examples/xegpu/softmax.py Updates CLI schedule parameters to the new nD tiling format.
examples/xegpu/layer_norm.py Updates CLI schedule parameters to the new nD tiling format.
examples/xegpu/kernel_bench.py Updates parameter inference for elemwise+reduction kernels (including RMSNorm-like 4D case) and adjusts verification tolerances/verbosity wiring.
Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread examples/xegpu/kernel_bench.py Resolved
@tkarna
tkarna force-pushed the xegpu-rms-reduction branch from c6716d6 to 2f4e098 Compare September 10, 2026 18:52
@tkarna

tkarna commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

Overall, the reduction_schedule now generates cleaner IR. The layer_norm.py example performance improved by 29%.

@tkarna
tkarna force-pushed the xegpu-rms-reduction branch from ecdd20c to 825d7f6 Compare September 11, 2026 06:18
@tkarna
tkarna merged commit 2521ccb into llvm:main Sep 11, 2026
3 checks passed
@tkarna
tkarna deleted the xegpu-rms-reduction branch September 11, 2026 09:43
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.

3 participants