Skip to content

fix(ir): state what a symbolic mesh mode and a broadcast operand reach - #202

Closed
zhen8838 wants to merge 2 commits into
tile-ai:mainfrom
zhen8838:foundry/kda-fwd-r1
Closed

zhen8838 wants to merge 2 commits into
tile-ai:mainfrom
zhen8838:foundry/kda-fwd-r1

Conversation

@zhen8838

@zhen8838 zhen8838 commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Why

Two places assume a value they are handed is a number, and raise rather than
answer when it is not. Both block the documented workflow of
tilefoundry tutorial optimize on an ordinary program.

  • selected_run sorts a mesh level's modes by (stride, extent) and joins
    adjacent ones. A Mesh layout naming an extent a DimVar decides — how a
    chunk-parallel placement over an open sequence length is written — makes the
    strides around it symbolic, and the sort raises
    '<' not supported between instances of 'int' and 'Call' with no source
    location. Its neighbours in the same file already guard on isinstance(..., int). Issue fix(ir): handle a symbolic extent in selected_run #201.
  • identity_relations gives every read operand of an elementwise instruction an
    identity of that operand's own rank. A scalar operand therefore yields
    { [] -> [] }, which iterating rejects against the Op's domain, and
    schedule candidates aborts for the whole program: a boundary is asked by 0 coordinates and its Op iterates 2. Adding an epsilon to a reduction is the
    common case, so every normalisation hits it. A lower-rank broadcast operand
    fails the same way. Issue fix(schedule): give an elementwise read the result's rank #200.

What

  • ir/types/mesh.py: when any mode of a level carries a symbolic extent or
    stride, selected_run reports the modes the mesh states instead of ordering
    and joining them. A symbolic mode orders against nothing and is adjacent to
    nothing, and two equal runs still compare equal, so covered_by_scope keeps
    recognising a scope as itself.
  • visitor_registry/access_relation.py: identity_relations states each read
    operand's broadcast relation with the broadcast_access that HIR Binary
    already uses, so a scalar operand is read once per point the Op walks and a
    shorter one right-aligns. The docstring said a structural operand borrows the
    iteration rank; this is what makes that true for a rank-zero tensor too.
  • tests/ir/types/test_mesh.py: a regression test for a run whose modes a
    DimVar decides.

Contract

Neither change alters what a program means or what any already-working program
lowers to. selected_run's result for an all-integer level is unchanged; the
new branch is reachable only where the old code raised. identity_relations
returns the same identity relation whenever every read operand already carries
the result's shape, which is every case that type-checked before. The
instruction's own pattern matching is untouched: an operand it cannot accept is
still refused by shape, dtype or storage, and is now refused with a report
rather than an abort.

Risk

tests/ir, tests/schedule, tests/visitor_registry, tests/analysis,
tests/parser and tests/dsl pass. The full suite's 41 failures are the
pre-existing ones that compile CUDA in this image; the set is identical before
and after the change, verified by running it on both revisions.

The residual risk is in the second change: an instruction whose operands were
previously rejected for an unrelated reason may now be probed further and
reported as refused on a different ground. That is the intended effect — a
candidate report that names the real reason — but it does change the text of
some schedule candidates output.

A mesh axis whose extent a DimVar decides makes the strides around it
symbolic, and selected_run sorted and joined its modes as if they were
numbers; an elementwise instruction's scalar or lower-rank operand was given
an identity of its own rank, which no Op iterating a wider result can answer
about. Both now say what they reach: the stated modes in the first case, the
existing right-aligned broadcast relation in the second.

Fixes tile-ai#201
Fixes tile-ai#200
@zhen8838
zhen8838 force-pushed the foundry/kda-fwd-r1 branch from abcfd37 to 7022aa9 Compare October 1, 2026 17:22
@zhen8838

zhen8838 commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

Closing to redo under docs/plans/schedule-broadcast-symbolic-mesh: elementwise relations will share one broadcast-aware identity_relations derived from operand types only, and symbolic mesh scopes will be compared without selected_run. A new PR with a schedule fixture covering #200 and #201 will follow.

@zhen8838 zhen8838 closed this Oct 2, 2026
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.

1 participant