Skip to content

decompose-transfer peel output (memref.subview + unrolled dma_start) incompatible with TOG generation #258

Closed

Description

@YWHyuk

Summary

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.

Generated MLIR (the failing kernel)

%subview = memref.subview %0[0,0,0,0,0][1,2,2,4,2][1,1,1,1,1]
           : memref<2x2x2x4x2xf32,1> to memref<2x2x4x2xf32, strided<[16,8,2,1]>,1>
memref.dma_start %arg0[%2], %subview[%c0,%c0,%c0,%c0], ...      // peel slice 0
%subview_2 = memref.subview %0[1,0,0,0,0]...offset:32
memref.dma_start %arg0[%4], %subview_2[%c0,%c0,%c0,%c0], ...    // peel slice 1 (unrolled)

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

  1. 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)
  2. 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.

Activity

  1. YWHyuk commented on Jun 17, 2026

    @YWHyuk
    CollaboratorAuthor

    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.

  2. added 7 commits that reference this issue on Jun 17, 2026
    3d871c8
    692588c
    0f18d05
    a127c37
    3da3a7c
    a6b7ebb
    ab0beaa
  3. YWHyuk commented on Jun 17, 2026

    @YWHyuk
    CollaboratorAuthor

    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.

  4. added 3 commits that reference this issue on Jun 19, 2026
    fbc4a02
    037742e
    2f87360
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions