Skip to content

[LayoutLowering] Ignore size-one leaves in contiguous-segment detection - #1193

Open
mustafayildirim wants to merge 5 commits into
ROCm:mainfrom
mustafayildirim:fix/1165-singleton-contig-segment
Open

mustafayildirim wants to merge 5 commits into
ROCm:mainfrom
mustafayildirim:fix/1165-singleton-contig-segment

Conversation

@mustafayildirim

Copy link
Copy Markdown

What

findContigSegment (lib/Dialect/Fly/Transforms/LayoutLowering.cpp) rejected any layout with more than one stride-1 flat leaf, without excluding size-one dimensions. A fully contiguous register tensor like (1, 4):(1, 1) — produced by make_rmem_tensor((1, 4), Float32) + fill(0.0) — therefore failed to lower, and the kernel died with a bare DSLCompileError: Failure while executing pass pipeline (#1165).

Size-one dims are contiguous with everything: they neither define nor break the contiguous segment. The fix skips static size-1 leaves when counting stride-1 leaves, so (1, 4):(1, 1) resolves to the width-4 vector segment instead of being flagged as ambiguous. (4, 1):(1, 1) (singleton last) resolves the same way.

Genuinely overlapping layouts are still rejected: (2, 1, 4):(1, 1, 1) keeps returning Invalid (two non-singleton stride-1 dims), and (1, 1):(1, 1) degenerates to the scalar path, which is equivalent. The isStatic() guard runs before getLeafAsInt() so dynamic shape leaves (common in the GEMM path) never hit the assert in IntTupleAttr::getLeafAsInt().

Testing

All on MI325X (gfx942), in-pod build of this branch against LLVM e2a39f504fe (RelWithDebInfo):

Check Result
Issue repro (fill on (1,4) rmem, store to global) on upstream main FAIL — DSLCompileError: Failure while executing pass pipeline
Same repro with this patch PASS — compiles, launches, zero-output assert holds
New tests/mlir/Conversion/memref_singleton_layout.mlir (4 cases: singleton-first/last × load/store_vec) PASS
Full mlir FileCheck suite (tests/mlir, all 51 files, every RUN line) 51/51 PASS
tests/language/ + tests/unit/ pytest (gfx942) 2481 passed, 10 skipped, 0 failures (18 initial failures traced to a missing OCML bitcode path in the test pod's ROCm shim, not this patch; all 124 re-ran green after fixing the pod env)

Fixes #1165

findContigSegment rejected layouts with more than one stride-1
dimension without excluding size-one leaves, so a fully contiguous
register tensor like (1,4):(1,1) failed to lower with
'DSLCompileError: Failure while executing pass pipeline'.

Size-one leaves are contiguous with everything: skip them when
counting stride-1 leaves so (1,4):(1,1) resolves to the width-4
vector instead of being flagged as ambiguous.

Lit-checked: new tests/mlir/Conversion/memref_singleton_layout.mlir
covers singleton-first and singleton-last layouts; memref_ops.mlir
and layout_lowering.mlir still pass.

Signed-off-by: mustafa <mustafa@character.ai>
Copilot AI lite review requested due to automatic review settings September 25, 2026 00:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Add coverage for all-singleton and overlapping stride-1 boundary cases.

Review effort: Lite
Findings: None

What changed in this PR

Fixes contiguous-segment detection for layouts containing static singleton dimensions.

Changes:

  • Ignores size-one leaves when identifying vector segments.
  • Adds MLIR load/store coverage for singleton-first and singleton-last layouts.
File Summary
tests/​mlir/​Conversion/​memref_singleton_layout.mlir Adds singleton layout lowering tests.
lib/​Dialect/​Fly/​Transforms/​LayoutLowering.cpp Updates contiguous-segment detection.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@coderfeli

Copy link
Copy Markdown
Collaborator

Looks good ? @sjfeng1999

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Issue]: Tensor.fill fails for singleton layouts with multiple unit strides

3 participants