Add average pooling example (row-wise mean reduction)#17
Merged
Conversation
New reduction example computing per-row mean of a 2D input, verified on NPU2 (Strix/AIE2P). Uses the rms_norm reduction pattern with linalg_promote for L1 staging and tile_sizes [2] to satisfy the 4-byte DMA alignment constraint (single bf16 = 2 bytes). Requires mlir-air >= 4bc5734 (fix for linalg_promote memref.cast on linalg.reduce operands, Xilinx/mlir-air#1399). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
14825c7 to
426cbd6
Compare
mlir-air: 4ef22a2 -> 4bc5734 (includes #1402 fix for linalg_promote memref.cast on linalg.reduce operands) mlir-aie: c5d4bef -> c668d2c (matching mlir-air's clone-mlir-aie pin) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
426cbd6 to
ca31d57
Compare
The 1D output form (storing just the mean per row) hits a 4-byte DMA alignment constraint on AIE (memref<1xbf16> = 2 bytes < 4-byte min). Redesigned as mean subtraction: y = x - mean(x), which broadcasts the mean back to [BLOCK_M, BLOCK_N] and follows the rms_norm reduction pattern exactly (tile [1], linalg_promote, 2D output DMA). Verified on NPU2: max diff 0.016, 0/8192 elements above 0.5 tolerance. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verified average_pool on NPU1 (Phoenix/AIE2): both M=32 and M=64 with N=256 pass assert_close. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
examples/average_pool/with Triton kernel, AIE2 and AIE2P transform scripts[M, N]input (BF16):y = x - mean(x, dim=-1)transpose_reduce+fuse_elementwise_linalg+tile_using_forall [1]+linalg_promoteDependencies
4bc5734which includes the fix forlinalg_promoteinsertingmemref.castto dynamic types onlinalg.reduceoperands (linalg_promote leaves memref.cast to dynamic types on promoted linalg.reduce operands Xilinx/mlir-air#1399, fixed by Fix linalg_promote leaving memref.cast on promoted linalg.reduce operands Xilinx/mlir-air#1402)Test plan
🤖 Generated with Claude Code