Skip to content

Give inner_tiled a strict verifier and explicit semantics with boolean parameters distributed and opaque - #22369

Merged
bjacob merged 2 commits into
iree-org:mainfrom
bjacob:inner-tiled-semantics
Oct 27, 2025
Merged

bjacob merged 2 commits into
iree-org:mainfrom
bjacob:inner-tiled-semantics

Conversation

@bjacob

@bjacob bjacob commented Oct 21, 2025

Copy link
Copy Markdown
Collaborator

@bjacob
bjacob marked this pull request as ready for review October 21, 2025 19:47
@bjacob
bjacob requested a review from Max191 October 21, 2025 19:49

@MaheshRavishankar MaheshRavishankar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ill let other people provide more detailed feedback, but IMO this implies that this op is not designed properly, and is being used in contexts where it shouldnt be. Adding extra attributes on top seems like a band-aid to me.

Btw, the new attributes added should at least be spelled out in the op description.

@qedawkins

Copy link
Copy Markdown
Contributor

Instead of adding these attributes on the operation itself, we could instead add it to the kind descriptor. When I first introduced the precursor to this op I left verification somewhat sparse because an interface method for verification smelled wrong. Perhaps the real mistake though was ExpandUndistributedInnerTiledDims and DistributeInnerTiledToX passes not updating the kind. The semantics of the op itself are really quite simple and would be good to keep as such:

  • Iterate over the outer dimensions of the input operands
  • Extract an inner tile from each operand based on the data type
  • Invoke the functionality described by the kind attribute on said inner tile.

The reason for an attribute descriptor instead of a body region is that the kinds of transformations we needed to do (expansion/distribution) are substantially harder when dealing with regions. The price of that is verbose attributes.

The reason for a single op over an interface is that patterns that transform the outer dims would necessarily have shared implementations meaning the interface would likely bloat quickly (not that the InnerTiledDescAttr isn't somewhat bloated, but that's kind of unavoidable).

@bjacob

bjacob commented Oct 22, 2025 •

Copy link
Copy Markdown
Collaborator Author

@MaheshRavishankar / @qedawkins , some high-level replies:

this implies that this op is not designed properly

I think it was designed initially just right for the problem space that we were entering then, given that there was no way that we could see the destination so this would have to evolve anyway. Evolve it did -- and along the way it accrued technical debt in that some of the evolutions came at a cost in terms of clarity and definedness of semantics. You could say that "supporting distribution" was part of the initial scope so that shouldn't have compromised semantics, but that "initial scope" was a really big chunk in itself, and maybe playing fast and loose was the reasonable thing to do, particularly as in exchange for the lax semantics we got more flexibility for the subsequent evolutions. One thing that in hindsight is impressive is that even though the initial non-DT flavors relied on opaque shapes, when I did DT I was able to do strict expanded shapes without changing the framework - so the new/better/stricter form was able to evolve within the existing lax form, thanks to the laxness.

Key point: This PR is not having strong opinions about anything. It's just the smallest incremental change to this op that recovers clarity and definedness of semantics.

The concern about the lax verifier and loose semantics is not just an abstract concern. The lax verifier meant that we had false positives allowing ill-formed IR to pass and later cause out-of-bounds accesses in the compiler (#22284 (comment)) as mentioned in #22336. The verifier code was also convoluted. These were not incidental details but were forced by the loose semantics.

Btw, the new attributes added should at least be spelled out in the op description.

Yup, omission, doing that.

Instead of adding these attributes on the operation itself, we could instead add it to the kind descriptor.

We could do that and I'm not opposed to it, but:

  1. It's not clear to me that this is better aligned with the semantics. "distributed" in particular is more about the tensor operands than it is about the mmaKind. "opaque" is equal parts about both".
  2. It will result in a bit more C++ code, as rewrites of InnerTiledOp's can't anymore just forward getKind().
  3. It will be a bit more work here, and I was hoping to merge quickly as this PR touches many tests.

@bjacob
bjacob force-pushed the inner-tiled-semantics branch from 896244c to ee7dd7c Compare October 22, 2025 14:21
@qedawkins

Copy link
Copy Markdown
Contributor

We could do that and I'm not opposed to it, but:

1. It's not clear to me that this is better aligned with the semantics. "distributed" in particular is more about the tensor operands than it is about the mmaKind. "opaque" is equal parts about both".

2. It will result in a bit more C++ code, as rewrites of InnerTiledOp's can't anymore just forward `getKind()`.

3. It will be a bit more work here, and I was hoping to merge quickly as this PR touches many tests.

At this point I'm not any more an owner of this op than you/others given how much it has evolved, and if this is the direction we have to go right now I don't want to cause needless churn and won't block, but I do want to share my concerns.

"distributed" in particular is more about the tensor operands than it is about the mmaKind

I don't agree. From the perspective of the inner_tiled op, before and after distribution the iteration over outer dimensions remains the same. What changes is how each tile is processed (before distribution, each lane must load the subvector they are responsible for). So in my mind the thing that had loosely defined semantics wasn't the inner_tiled op, but the kind describing its body.

  1. and 3) are both true, but what I am concerned about is an ever growing set of "semantic modifiers" for the kind that we add to the inner_tiled op and are hard to interpret in a vacuum.

@bjacob

bjacob commented Oct 22, 2025

Copy link
Copy Markdown
Collaborator Author

I don't agree. From the perspective of the inner_tiled op, before and after distribution the iteration over outer dimensions remains the same. What changes is how each tile is processed (before distribution, each lane must load the subvector they are responsible for). So in my mind the thing that had loosely defined semantics wasn't the inner_tiled op, but the kind describing its body.

The other thing that changes with distribution is the shape of the tensor operands, in the inner dimensions.

I can see the mental model you are laying out here, where distributedness is a property of the Kind attributes. But if we look at the current MMAAttr-like attributes and even the underlying interfaces like InnerTileDescAttrInterface, they don't know about distributedness and their interface methods reflect that, having side-by-side methods for distributed and undistributed cases, which is exactly what they wouldn't have if these interfaces were meant to cover distributedness (see below).

So I think I agree with you on the destination, but I think that getting there in a way that is really worth doing (doesn't just shift a semantics gap one step down) will take more changes than should be fitted into this PR. I think that this PR as-is is a necessary first step towards that, as by tightening the existing semantics it takes care of the hard part (climbing out of a hole of loose semantics) and leaves only a more reasonable follow-up to do (evolve design within clear constraints covered by verifiers).

Do you want me to file the Issue?

  DeclareAttrInterfaceMethods<IREECodegen_InnerTileDescAttrInterface, [
    "getExpectedNumInputs",
    "getExpectedNumOutputs",
    "verifyIndexingMaps",
    "getUndistributedTileTypes",
    "getDistributedTileTypes",
    "getUndistributedTileDimExpansion",
    "populateOperandOffsetsSizesStrides",
    "getDistributionMappingKind",
    "getDistributionWorkerCount",
    "buildUnderlyingOperations",
  ]>

@qedawkins

Copy link
Copy Markdown
Contributor

But if we look at the current MMAAttr-like attributes and even the underlying interfaces like InnerTileDescAttrInterface, they don't know about distributedness and their interface methods reflect that, having side-by-side methods for distributed and undistributed cases, which is exactly what they wouldn't have if these interfaces were meant to cover distributedness (see below).

Yes, I think you hit the nail on the head here and I should have been clearer when stating my concerns. The InnerTileDescAttrInterface is as much to blame for the current need for additional semantic modifiers as the inner_tiled op itself.

I think that this PR as-is is a necessary first step towards that, as by tightening the existing semantics it takes care of the hard part (climbing out of a hole of loose semantics) and leaves only a more reasonable follow-up to do (evolve design within clear constraints covered by verifiers).

Part of why I said I wouldn't block was because the changes I'm asking for amounts to a substantial rewrite, and if we are on the same page then this SGTM.

@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

Just looking on from fairly far off, this operation has been rewritten once already. Going by the rule of three (you need three tries to get something right), its OK to have substantial changes and staging them, but what's missing is someone effectively owning the state and making sure that we are heading towards what is (eventually) stable.

@bjacob
bjacob force-pushed the inner-tiled-semantics branch from ee7dd7c to cd74cb6 Compare October 23, 2025 20:46
@bjacob
bjacob requested a review from qedawkins October 23, 2025 20:48
@bjacob

bjacob commented Oct 23, 2025

Copy link
Copy Markdown
Collaborator Author

@qedawkins , @krzysz00 , what I just pushed here should have all what we discussed.

@Groverkss Groverkss 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.

Looks fine to me, I don't have much opinion on this

1. Expanded vs opaque tile shapes.
2. On GPU: distributed vs undistributed tile shapes.
Having this split into a separate interface allows mutating those
attribtutes separately.

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.

Suggested change
attribtutes separately.
attributes separately.

if (!isPermutationVector(permAttr.asArrayRef()))
return emitOpError("invalid permutation");
for (auto [index, permAttr] :
llvm::enumerate(getPermutations()->getAsRange<DenseI64ArrayAttr>())) {

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.

I believe this is missing verification that the number of permutations equals the operand count (needed to keep later indexing in bounds).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch: added several more test cases here.

Signed-off-by: Benoit Jacob <[email protected]>

review comments

Signed-off-by: Benoit Jacob <[email protected]>

wip

Signed-off-by: Benoit Jacob <[email protected]>
Signed-off-by: Benoit Jacob <[email protected]>
@bjacob
bjacob force-pushed the inner-tiled-semantics branch from cd74cb6 to 96b836f Compare October 27, 2025 17:47
@bjacob
bjacob merged commit 34379e6 into iree-org:main Oct 27, 2025
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.

inner_tiled op needs explicit semantics and a strict verifier

5 participants