Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LinalgExt] Scatter fusion by expansion 3/3 #19588

Merged
merged 4 commits into from
Jan 9, 2025

Conversation

IanWood1
Copy link
Contributor

@IanWood1 IanWood1 commented Jan 2, 2025

Implements fusion with reshapes by expansion for LinalgExt::ScatterOp.

TODO: fix >1 dynamic dim (also a problem with attention).

See main issue #19091

@IanWood1 IanWood1 changed the title [LinalgExt] Scatter fusion by expansion [LinalgExt] Scatter fusion by expansion 3/3 Jan 2, 2025
@IanWood1 IanWood1 force-pushed the scatter_reshape_fusion branch from c6c862a to 7cd1fad Compare January 6, 2025 17:57
@IanWood1 IanWood1 marked this pull request as ready for review January 6, 2025 17:59
@@ -391,6 +392,197 @@ static std::optional<SmallVector<Value>> fuseAttentionWithReshapeByExpansion(
return resultVals;
}

namespace {
class ScatterExpansionInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if we need to replicate all this logic for each op. It seems with a cursory glance that the CollapseInfo (which can be reused for expansion as well) can just use methods defined by the FusionInterface? Then we should be able to just use that as a tool to get the reassociations we need. The actual math is fairly independent of the op?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem I had with that is that the original operand has a nullptr AffineMap which breaks the logic of CollapseInfo. We need a way to represent the link between the innermost dims of original and updates while also expressing the fact that the outermost dims of original are not indexed in an AffineMap represent-able way.

I know CustomOp uses affine symbols which could possibly be useful here? I'm not to familiar with it so I'll need to check.

Copy link
Contributor

@MaheshRavishankar MaheshRavishankar left a comment

Choose a reason for hiding this comment

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

(see comment below).

@IanWood1 IanWood1 force-pushed the scatter_reshape_fusion branch from 7cd1fad to 8b870e6 Compare January 7, 2025 22:53
Copy link
Contributor

@MaheshRavishankar MaheshRavishankar left a comment

Choose a reason for hiding this comment

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

Thanks! I didnt verify all the details of the expansion etc, but overall this seems much easier to reuse.

@IanWood1 IanWood1 merged commit 74f8d3c into iree-org:main Jan 9, 2025
33 checks passed
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.

2 participants