Conversation
Tile IR is natively row-major (Python cuTile passes shapes verbatim). We were passing Julia's column-major shapes through as-is, then compensating with per-operation fixups: reshape emitted a permute-reshape-permute sandwich, and batched matmul emitted 4 permute ops to convert trailing batch dims to MmaFOp's leading batch convention. Instead, reverse all shapes at the Julia↔Tile IR boundary: Julia (M, K, B) → Tile IR (B, K, M). CGVal.shape now stores Tile IR (row-major) order. Conversion happens in three functions: _tile_type_for_julia!, tile_type_and_shape_for_julia!, and extract_tile_shape. This eliminates the reshape double-permute (now a direct ReshapeOp) and all matmul permutes (operands swapped: mmaf(b, a, acc) computes (N,K)@(K,M)=(N,M) → Julia (M,N), which is correct). Axes for reduce/scan/cat are flipped (tileir_axis = ndim-1-julia_axis), indices for load/store are reversed, and tensor view sizes/strides are reversed to match. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
This is a great solution. I was previously confused by the operand ordering and shapes and why it was that they could be passed directly to mmaf, but this resolves the confusion. |
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.
Tile IR is natively row-major (Python cuTile passes shapes through verbatim). We were passing Julia's column-major shapes as-is, then compensating per-operation: reshape emitted a permute-reshape-permute sandwich, and batched matmul emitted 4 permute ops to convert trailing batch dims to MmaFOp's leading-batch convention.
This PR proposes to reverse all shapes once at the Julia-Tile IR boundary: Julia
(M, K, B)becomes Tile IR(B, K, M).What changes
Reshape — the double-permute hack is gone. Was:
Now:
Batched matmul — 4 permute ops per MmaFOp eliminated. Operands are swapped instead (
mmaf(b, a, acc)), which produces the correct result because Julia(M,K,B)→ Tile IR(B,K,M)and(B,N,K) @ (B,K,M) = (B,N,M)→ Julia(M,N,B). Was:Now:
Axes for reduce/scan/cat are flipped (
tileir_axis = ndim - 1 - julia_axis). Permutation indices are transformed. Load/store indices and tensor view sizes/strides are reversed.Tile IR comparison: 3D batched matmul
(32,16,4) * (16,32,4)Before (7 ops between load and store):
After (2 ops):
Benchmarks (RTX 5080, min of 10 runs)