Skip to content

Invalid IR produced for MetalLayoutAttr #6036

@brnorris03

Description

@brnorris03

Describe the bug

The #ttcore.metal_layout attribute printer outputs an empty memory_layout field, producing l1,, which fails to parse back.

Impact

  • Cannot incrementally run pipeline stages using intermediate files
  • Debugging requires running the full pipeline rather than individual passes

Workaround

Use the full pipeline (--ttir-to-ttmetal-pipeline) instead of piping intermediate outputs between frontend/middleend/backend stages.

Steps to reproduce the issue

Reproducer 1: Simple add operation

Create /tmp/simple_add.mlir:

func.func @add(%arg0: tensor<32x32xf32>, %arg1: tensor<32x32xf32>) -> tensor<32x32xf32> {
  %0 = ttir.empty() : tensor<32x32xf32>
  %1 = "ttir.add"(%arg0, %arg1, %0) : (tensor<32x32xf32>, tensor<32x32xf32>, tensor<32x32xf32>) -> tensor<32x32xf32>
  return %1 : tensor<32x32xf32>
}

Run:

# Run frontend pipeline and save output
build/bin/ttmlir-opt --ttir-to-ttmetal-fe-pipeline="system-desc-path=" \
  /tmp/simple_add.mlir -o /tmp/simple_add_fe.mlir

# Attempt to parse the output (FAILS)
build/bin/ttmlir-opt /tmp/simple_add_fe.mlir

Reproducer 2: Reduction test

# Run frontend pipeline and save output
build/bin/ttmlir-opt --ttir-to-ttmetal-fe-pipeline="system-desc-path=" \
  test/ttmlir/Dialect/D2M/Transforms/dst_graph_coloring/debug_reduction_dst.mlir \
  -o /tmp/reduction_fe.mlir

# Attempt to parse the output (FAILS)
build/bin/ttmlir-opt /tmp/reduction_fe.mlir

Error Message

/tmp/reduction_fe.mlir:1:156: error: expected keyword for TTCore Tensor Memory Layout
#layout = #ttcore.metal_layout<logical_shape = 256x256, dim_alignments = 32x32, collapsed_intervals = dense<[[0, 1], [1, 2]]> : tensor<2x2xi64>, undef, l1,, index_map = map(0)>
                                                                                                                                                           ^
/tmp/reduction_fe.mlir:1:156: error: failed to parse TTCore_MetalLayoutAttr parameter 'memory_layout' which is to be a `TensorMemoryLayout`

Analysis

The printed output shows l1,, (note the double comma) indicating the memory_layout field is empty/unset. The parser expects a keyword for TensorMemoryLayout but finds nothing.

Expected behavior

Either:

  1. The printer should output a valid default value when memory_layout is unset
  2. The attribute should be defined to always have a valid memory_layout
  3. The parser should handle the case when memory_layout is empty

Please complete the following environment information

reproducible anywhere

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions