Skip to content

[LinalgExt][NFC] Split the op definition between pure ops and LinalgExt ops - #22368

Merged
hanhanW merged 2 commits into
iree-org:mainfrom
sakupan102:split-linalgext
Oct 27, 2025
Merged

hanhanW merged 2 commits into
iree-org:mainfrom
sakupan102:split-linalgext

Conversation

@sakupan102

@sakupan102 sakupan102 commented Oct 21, 2025 •

Copy link
Copy Markdown
Contributor

Split LinalgExtOp into PureOp and LinalgExtOp. This enables automatically attaching the right interfaces by simply including the generated .cpp.inc files, preventing missed interface attachments.

Closes #20862

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

Thanks for the patch!

I think MapScatterOp and attention ops should belong to LinalgExtOps.td. (I don't know why they dont inherit LinalgExtOp for now, but it is a separate issue.)

My mental model is that we structure it like linalg ops. There are pure ops and structure ops (that I call compute ops in IREE). The MapScatterOp and attention ops describe the computation, so they belong to LinalgExtOps.td.


class IREELinalgExt_Op<string mnemonic, list<Trait> traits = []> :
IREELinalgExt_PureOp<mnemonic, !listconcat(traits,
Op<IREELinalgExt_Dialect, mnemonic, !listconcat(traits,

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.

Can't this file include LinalgExtPureOps.td?

@sakupan102 sakupan102 Oct 22, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If this file directly includes LinalgExtPureOps.td, it redefines pureOps, which causes an error.
It is better to move the base class to LinalgExtBase.td and include it from there.

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

overall looks good, I think we miss few removal; I think we can drop the comments for three ops.

Comment on lines +273 to +274
// map_scatter op does not have enough operands to use AttrSizedOperandSegments trait
// so we inherit from IREELinalgExt_PureOp for now.

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.

The comment is not accurate to me. The reason of using AttrSizedOperandSegments for an op if it has at least two variadic operands. I think you can drop the comments for this case and other cases. I'll do a cleanup for this in a follow-up. Thanks.

https://mlir.llvm.org/docs/DefiningDialects/Operations/#variadic-operands

Comment on lines +704 to +707
IREE::LinalgExt::AttentionOp::attachInterface<
LinalgExtOpInterface<IREE::LinalgExt::AttentionOp>>(*ctx);
IREE::LinalgExt::MapScatterOp::attachInterface<
LinalgExtOpInterface<IREE::LinalgExt::MapScatterOp>>(*ctx);

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.

We no longer need them, right? Because they should be registered with the above include.

Comment on lines 455 to 456
IREE::LinalgExt::AttentionOp::attachInterface<
LinalgOpTiedOpInterface<IREE::LinalgExt::AttentionOp>>(*context);

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.

This is no longer needed.

@hanhanW
hanhanW enabled auto-merge (squash) October 23, 2025 17:24

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

Hanhan approved it, but missing context as to why we need this? Its a bit of an artificial split. I have no strong opinions, but curious why we did this to start with (especially since we only moved a single op into a different file).

@hanhanW

hanhanW commented Oct 23, 2025

Copy link
Copy Markdown
Contributor

Hanhan approved it, but missing context as to why we need this? Its a bit of an artificial split. I have no strong opinions, but curious why we did this to start with (especially since we only moved a single op into a different file).

The main reason is described here: #20862 (comment)

It will allow us to have less burden when adding a new LinalgExt op. The interface registration (e.g., memory side effect, bufferization, etc) will be done automatically, so we no longer need commit like dce563a

@hanhanW
hanhanW disabled auto-merge October 23, 2025 19:58
@hanhanW

hanhanW commented Oct 23, 2025

Copy link
Copy Markdown
Contributor

@sakupan102 can you fix the bazel and update PR description? https://google.github.io/eng-practices/review/developer/cl-descriptions.html has the guidance about what a good PR title and description can be.

@Groverkss

Copy link
Copy Markdown
Contributor

I think MapScatterOp and attention ops should belong to LinalgExtOps.td. (I don't know why they dont inherit LinalgExtOp for now, but it is a separate issue.)

IIRC it's because most of linalg ext ops are trying to act like linalg.generic syntax with ins()/outs() which the interface requires. Attention/MapScatter have a fixed number of arguements and don't need that.

Most ops in linalg_ext don't need variadic arguements and but we never changed it.

@Groverkss

Groverkss commented Oct 24, 2025 •

Copy link
Copy Markdown
Contributor

LGTM, we need to revamp LinalgExtInterface to not have variadic arguements in future though, most ops don't need it in linalg_ext

@hanhanW

hanhanW commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

LGTM, we need to revamp LinalgExtInterface to not have variadic arguements in future though, most ops don't need it in linalg_ext

This is what I'm going to do in a follow-up. Ops should add the interface when they need to; it should not belong to the LinalgExtOps traits today. (It's mostly legacy.)

@hanhanW hanhanW changed the title [LinalgExt] Split the op definition between pure ops and LinalgExt ops [LinalgExt][NFC] Split the op definition between pure ops and LinalgExt ops Oct 27, 2025
@hanhanW
hanhanW enabled auto-merge (squash) October 27, 2025 16:55
@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

LGTM, we need to revamp LinalgExtInterface to not have variadic arguements in future though, most ops don't need it in linalg_ext

This is what I'm going to do in a follow-up. Ops should add the interface when they need to; it should not belong to the LinalgExtOps traits today. (It's mostly legacy.)

Yeah my bad! It wrote that at a time when I didn't know better

bangtianliu pushed a commit to bangtianliu/iree that referenced this pull request Oct 30, 2025
…xt ops (iree-org#22368)

Split LinalgExtOp into PureOp and LinalgExtOp. This enables
automatically attaching the right interfaces by simply including the
generated .cpp.inc files, preventing missed interface attachments.

Closes iree-org#20862

---------

Signed-off-by: Ryutaro Okada <[email protected]>
bangtianliu pushed a commit to bangtianliu/iree that referenced this pull request Nov 19, 2025
…xt ops (iree-org#22368)

Split LinalgExtOp into PureOp and LinalgExtOp. This enables
automatically attaching the right interfaces by simply including the
generated .cpp.inc files, preventing missed interface attachments.

Closes iree-org#20862

---------

Signed-off-by: Ryutaro Okada <[email protected]>
pstarkcdpr pushed a commit to pstarkcdpr/iree that referenced this pull request Nov 28, 2025
…xt ops (iree-org#22368)

Split LinalgExtOp into PureOp and LinalgExtOp. This enables
automatically attaching the right interfaces by simply including the
generated .cpp.inc files, preventing missed interface attachments.

Closes iree-org#20862

---------

Signed-off-by: Ryutaro Okada <[email protected]>
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.

[LinalgExt] Split the op definition between pure ops and LinalgExt ops

4 participants