Refactor rms_norm transform script to follow mlir-air layernorm prototype#65
Merged
Merged
Conversation
…type Replace post-bufferize linalg_promote (which leaks self-copies that crash transform.air.copy_to_dma) with pre-bufferize bufferize_to_allocation + promote_tensor for L1 staging, mirroring mlir-air xrt 43_triton_layernorm. Eliminates "expected to produce 1 results (actually produced 0)" stderr on aie2p reported in amd#64.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the AIE2P MLIR transform sequence for the rms_norm example to mirror the mlir-air layernorm XRT prototype structure, replacing the prior post-bufferize linalg_promote-based L1 staging approach that could generate SSA self-copies and trigger transform.air.copy_to_dma result-contract diagnostics.
Changes:
- Reworks the transform pipeline into phased steps (canonicalize/fuse, dataflow navigation, tiling+fusion, pre-bufferize allocations/promotions, bufferize, vectorization prep, herd/DMA/vectorization, type casts).
- Replaces post-bufferize
transform.air.linalg_promotestaging with pre-bufferizebufferize_to_allocation {memory_space = 2}andpromote_tensor to 2to avoid self-copy patterns. - Adds prototype-aligned transforms: delayed
generalizeof remaininglinalg.reduce,convert_divf_sqrt_to_rsqrt, andbroadcast_before_unaryformath.rsqrt.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactors examples/rms_norm/transform_aie2p.mlir to follow the structure of the mlir-air xrt prototype
test/xrt/43_triton_layernorm/transform_aie2p.mlirexactly.Fixes the spurious stderr reported during testing of #64 on Windows aie2p:
```
loc("-":83:11): error: application of transform.air.copy_to_dma expected to produce 1 results (actually produced 0).
```
Root cause
The previous script used `transform.air.linalg_promote` (post-bufferize) to stage L2 subviews into L1. When the linalg op's destination is itself an L2 subview, `linalg_promote` emits `memref.copy %sv, %sv` (literal SSA self-copy). `transform.air.copy_to_dma` then detects each self-copy in `CopyToDmaOp::applyToOne`, erases the op, and returns success without pushing a result handle — violating the framework's 1-result contract for `applyToOne` and producing the diagnostic above. Reproduces deterministically on Linux aie2p.
Fix
Replace the post-bufferize `linalg_promote` mechanism with the layernorm prototype's pre-bufferize approach:
Self-copies are never emitted, so the diagnostic disappears structurally rather than via a workaround. Resulting AIR shows clean separated loops (square → reduce → output) with a single shared L1 input alloc.
Test plan
🤖 Generated with Claude Code