You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
decompose-transfer peel output (memref.subview + unrolled dma_start) incompatible with TOG generation #258
The decompose-transfer pass's >4D peel path emits memref.subview + unrolled, constant-offset memref.dma_start ops. The C++ TOG generation pass (test-tile-operation-graph) cannot extract loop indices from this form, producing an empty loop_idx_list, which then fails ONNX serialization:
ValueError: Could not infer attribute `torchsim_loop_idx_list` type from empty iterator
(AsmParser/onnx_utility.py:74)
How to reach it
This peel path was only validated in isolation (lower_text / mlir-opt verify), never through the full pipeline (it is unreachable under the default init_tile_size, which caps non-unit tile dims at 3). It becomes reachable when aligned axis-split (TORCHSIM_AXIS_SPLIT) splits multiple axes and pushes the effective tile rank past 4.
Repro: pixel_shuffle(x, 2) + 1.0 on x=randn(1,8,4,4) with TORCHSIM_AXIS_SPLIT=1. axis-split splits both spatial axes -> 5D tile -> peel.
The SRAM operand is a memref.subview (TOG expects the spad indexed by affine loop vars), and the peeled dim is unrolled to constants, so the TOG pass finds no enclosing loop index for the DMA.
Root cause
decompose-transfer peels >4D affine tiles by full unrolling + memref.subview rather than a real loop. This is fine for mlir-opt/LLVM lowering but not for the TOG pass, which keys on enclosing affine.for loop indices.
Fix options
Rewrite the peel to emit a real affine.for over the outer dims (keeping a loop index the TOG pass can read) and index the spad directly instead of via memref.subview. (preferred)
Teach the C++ TOG pass to handle memref.subview and unrolled DMAs.
Workaround in place
find_split_plan (axis-split) has a rank guard that drops the plan when it would push the index rank past 4, so the peel is not triggered from axis-split for now (pixel_shuffle falls back to baseline and passes). This issue tracks the underlying peel<->TOG incompatibility.
See docs/dma-transfer-lowering.md and docs/axis-split-scheduling.md.
Update: TOG crash fixed; peel numerical correctness is the remaining blocker
Root-caused and fixed the TOG-serialization crash. The >4D peel advanced the
per-slice DRAM base with arith.addi(dram_idx, const). The TOG pass builds loop_idx_list by walking the DRAM index via processDramIndices
(TestTileOperationGraph.cpp), which handles affine.apply / block-arg / constant
but NOT arith.addi -> the addi produced an empty loop_idx_list and ONNX
serialization failed. (The memref.subview on the SRAM side was a red herring --
TOG derives loop_idx_list from the DRAM index only.)
Fix (commit on feature/mlir-python-bindings): fold the constant offset into an affine.apply (d0)->(d0+const) over the original dram_idx instead of arith.addi; processDramIndices recurses through it. With this, pixel_shuffle (5D tile from
axis-split) no longer crashes the TOG pass.
Remaining: the peel now compiles and runs but produces a wrong result
(MISMATCH). It had only ever been isolation-validated for MLIR structure, never run
end-to-end, and has a numerical layout bug (wrong dim/stride/offset or vlane
mapping). The axis-split rank guard is kept (pixel falls back to the correct
baseline) until the peel numerics are fixed; only then can the guard be removed and
the recompile-dance retired for the >4D case.
Resolved on feature/tog-python-binding (commit a6b7ebb, "decompose-transfer:
affine.for peel with lane-banked physical SRAM offset").
The >4D peel was rewritten exactly along fix option (1): instead of full-unrolling
with memref.subview (which the TOG could not read and whose offset extract_aligned_pointer_as_index stripped), it now peels the outer dims into an affine.for nest (marked inner_loop, so build_tog/TOG registers the induction
var) and emits one <=4D memref.dma_start per iteration:
DRAM base folds into a single affine.apply(dram_idx + sum_k iv_k*stride_k)
(not arith.addi), so processDramIndices / build_tog walk the loop index.
The SRAM slice offset is the lane-banked physical offset (split-outer dims
rescaled by the lane coeff -- the MVIN block_stride / -dma-fine-grained
buildSramAffineMap rule), delivered as the last SRAM index operand, fixing the
numerics (the old subview offset aliased every slice -> pixel_shuffle MISMATCH).
The axis-split rank guard was removed. Validated end-to-end (Gem5+Spike+TOGSim,
allclose) on pixel_shuffle(x,2)+1.0 (5D tile) plus the gemm/bmm/conv2d and
resnet/transformer/vit/mlp suites. Closing.
Activity
YWHyuk commentedon Jun 17, 2026
Update: TOG crash fixed; peel numerical correctness is the remaining blocker
Root-caused and fixed the TOG-serialization crash. The >4D peel advanced the
per-slice DRAM base with
arith.addi(dram_idx, const). The TOG pass buildsloop_idx_listby walking the DRAM index viaprocessDramIndices(TestTileOperationGraph.cpp), which handles
affine.apply/ block-arg / constantbut NOT
arith.addi-> the addi produced an emptyloop_idx_listand ONNXserialization failed. (The
memref.subviewon the SRAM side was a red herring --TOG derives
loop_idx_listfrom the DRAM index only.)Fix (commit on feature/mlir-python-bindings): fold the constant offset into an
affine.apply (d0)->(d0+const)over the originaldram_idxinstead ofarith.addi;processDramIndicesrecurses through it. With this, pixel_shuffle (5D tile fromaxis-split) no longer crashes the TOG pass.
Remaining: the peel now compiles and runs but produces a wrong result
(MISMATCH). It had only ever been isolation-validated for MLIR structure, never run
end-to-end, and has a numerical layout bug (wrong dim/stride/offset or vlane
mapping). The axis-split rank guard is kept (pixel falls back to the correct
baseline) until the peel numerics are fixed; only then can the guard be removed and
the recompile-dance retired for the >4D case.
[Frontend] decompose-transfer peel: fix #258 TOG crash (affine.apply …
[Docs] axis-split + decompose-transfer: graph-copy, default-on, peel/#…
[Frontend] decompose-transfer peel: fix #258 TOG crash (affine.apply …
[Docs] axis-split + decompose-transfer: graph-copy, default-on, peel/#…
[Frontend] decompose togsim.transfer to <=4D dma_start
[Frontend] decompose-transfer: affine.for peel with lane-banked physi…
[Frontend] dma-fine-grained: port the C++ pass to Python (MLIR bindings)
YWHyuk commentedon Jun 17, 2026
Resolved on
feature/tog-python-binding(commit a6b7ebb, "decompose-transfer:affine.for peel with lane-banked physical SRAM offset").
The >4D peel was rewritten exactly along fix option (1): instead of full-unrolling
with
memref.subview(which the TOG could not read and whose offsetextract_aligned_pointer_as_indexstripped), it now peels the outer dims into anaffine.fornest (markedinner_loop, so build_tog/TOG registers the inductionvar) and emits one <=4D
memref.dma_startper iteration:affine.apply(dram_idx + sum_k iv_k*stride_k)(not
arith.addi), soprocessDramIndices/ build_tog walk the loop index.rescaled by the lane coeff -- the MVIN block_stride / -dma-fine-grained
buildSramAffineMap rule), delivered as the last SRAM index operand, fixing the
numerics (the old subview offset aliased every slice -> pixel_shuffle MISMATCH).
The axis-split rank guard was removed. Validated end-to-end (Gem5+Spike+TOGSim,
allclose) on pixel_shuffle(x,2)+1.0 (5D tile) plus the gemm/bmm/conv2d and
resnet/transformer/vit/mlp suites. Closing.
[Frontend] decompose togsim.transfer to <=4D dma_start
[Frontend] decompose-transfer: affine.for peel with lane-banked physi…
[Frontend] dma-fine-grained: port the C++ pass to Python (MLIR bindings)