Add tensor-based TileArray programs and GEMM pattern rewriting - #3
Open
ShangkunLi wants to merge 19 commits into
Open
ShangkunLi wants to merge 19 commits into
ShangkunLi wants to merge 19 commits into
Conversation
ShangkunLi
marked this pull request as ready for review
September 11, 2026 17:18
ShangkunLi
marked this pull request as draft
September 15, 2026 02:02
ShangkunLi
marked this pull request as ready for review
September 16, 2026 02:09
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
This PR adds two complementary capabilities:
Example: programming a GEMM
The following program computes
C = A @ Bfor 3×3 i32 tensors on a physical 4×4 TileArray. The west column performs loads, nine tiles perform MACs, and the south row performs stores.xandyidentify physical tiles;kidentifies the reduction position assigned to each MAC row.B[k, x - 1]remains stationary, whileA[:, k]supplies successive output rows.Standalone compilation records a
TileArrayProgram, creates a Taskflow task, and lowers its body to a Neura kernel. The backend handles routing and scheduling. C is overwritten and must not overlap A or B.Pattern matching and rewriting
Each pattern directly inherits
TileArrayRewritePatternand defines:root: the operation type considered by the driver;match_and_rewrite(): computation-specific checks and the replacement call.This PR provides patterns for named
linalg.matmul, canonicallinalg.genericcontraction, and canonical Affine GEMM. All three reusews_gemm_3x3.flowchart TD A["Existing Taskflow task<br/>Linalg or Affine computation"] B["Filter by pattern.root"] C["match_and_rewrite()<br/>Check computation and implementation conditions"] D["Build TileArrayProgram<br/>from the selected Python function"] E["Check task and memory compatibility"] F["lower_to_kernel()<br/>Generate and verify the replacement"] G["Replace the original computation<br/>Preserve the task, results, and completion dependencies"] U["Keep original IR"] A --> B B -->|Matching root| C C -->|Match| D C -->|Not applicable| U D --> E E -->|Compatible| F E -->|Not compatible| U F --> GThe current GEMM implementation overwrites C, whereas source matmul accumulates into C. Its patterns therefore require zero-initialized C. Generic and Affine patterns additionally check the indexing and multiply-add dataflow.
The rewriter constructs and verifies the replacement before changing the original IR. Both standalone compilation and pattern rewriting share
lower_to_kernel().Unmatched computations remain available for later lowering. Automatic Counter/General fallback is not connected in this PR.