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

[DispatchCreation] Extend multi-use producer fusion #18551

Merged
merged 7 commits into from
Oct 16, 2024

Conversation

IanWood1
Copy link
Contributor

Fuse even in cases where the most dominant op isn't fusable but other operations would be legal to fuse.

Fuse even in cases where the most dominant op isn't fusable but other
operations would be legal to fuse.

Signed-off-by: Ian Wood <[email protected]>
@IanWood1
Copy link
Contributor Author

IanWood1 commented Sep 19, 2024

I think I'm going to have to implement the use-def traversal instead of using getBackwardsSlice since values defined above should be tracked in the slice too.

Maybe that could be added upstream, but assuming worst case scenario works (only really effects gather ops)

@IanWood1 IanWood1 marked this pull request as ready for review September 19, 2024 17:54
@ScottTodd ScottTodd removed their request for review September 19, 2024 21:38
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.

Could you provide some more context on this change. Just trying to place what this is addressing.

llvm::SetVector<Operation *> slice;
getBackwardSlice(op, &slice, options);

// `getBackwardSlice` doesnt track uses from within an ops region, so make
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I follow this comment. Can you explain more?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

%0 = linalg.generic
%1 = linalg.generic %0
%2 = linalg.generic %1 ins(%0 : tensor<...>) {
  ^bb0(%in: i64, %out: i64):
    %extracted = tensor.extract %1 [...]
    linalg.yield %extracted : f16
  } -> tensor<...>

In the above, the backward slice starting at %2 would only include %2 (but not %1 because it isn't a direct operand). Which makes it seem like %2 can be moved before %1. Just looking at the slice doesn't tell you if there is a dependency between the ops.

This was causing issues with the open llama regression tests since (i think) there are multiple gathers

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to use a slice of the values that are captured from above to make sure that there is no dependence?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think so. Maybe this could be a option of getBackwardsSlice?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe... lets leave this this way for now.

Copy link
Contributor

@nirvedhmeshram nirvedhmeshram Oct 24, 2024

Choose a reason for hiding this comment

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

If I am seeing the test added in this PR correctly there wasnt a test added for this? The failure in #18879 seems related to this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nirvedhmeshram There were several other tests that failed related to the backward slice problem (regression tests), but none were because the consumer was using values defined above which is why this slipped through. I'll make sure to add more testing when fixing this

@IanWood1
Copy link
Contributor Author

Could you provide some more context on this change. Just trying to place what this is addressing.

Oh I think I forgot to update the description. There is a commit here originally from #18341 but since thats waiting for bangtian's multi reduction pipeline change and this was easily seperatable I just moved it's own PR. #18341 allows more movement of reshape ops which changed the order of some of the consumers. For example:

Before:

%producer = linalg.generic
%fusableConsumer = linalg.generic
%unfusableConsumer = expand_shape %producer

After:

%producer = linalg.generic
%unfusableConsumer = expand_shape %producer
%fusableConsumer = linalg.generic

This caused regressions in dispatch count because fusableConsumer could only be fused if it dominated all other consumers. This patch is just to make multiuse fusion less dependent on program order.

llvm::SetVector<Operation *> slice;
getBackwardSlice(op, &slice, options);

// `getBackwardSlice` doesnt track uses from within an ops region, so make
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe... lets leave this this way for now.

@IanWood1 IanWood1 merged commit 206b60c into iree-org:main Oct 16, 2024
35 checks passed
@IanWood1 IanWood1 deleted the multi_use_fusion branch October 16, 2024 17:52
IanWood1 added a commit that referenced this pull request Oct 24, 2024
IanWood1 added a commit that referenced this pull request Oct 28, 2024
The reverted commit does not handle when the "consumer" uses a value
defined above. See #18879 for the
original issue. This is causing issue with ~15 onnx models.

I have a PR (#18855) to fix this by
including values used in an ops region in the backwards slice, but It is
waiting on upstream changes to `getBackwardSlice`. Currently, the PR is
using a wrapper around `getBackwardSlice` to acheive the same effect,
but this will be updated once the upstream change lands
(llvm/llvm-project#113478)


Reverts #18551

---------

Signed-off-by: Ian Wood <[email protected]>
Eliasj42 pushed a commit that referenced this pull request Oct 31, 2024
The reverted commit does not handle when the "consumer" uses a value
defined above. See #18879 for the
original issue. This is causing issue with ~15 onnx models.

I have a PR (#18855) to fix this by
including values used in an ops region in the backwards slice, but It is
waiting on upstream changes to `getBackwardSlice`. Currently, the PR is
using a wrapper around `getBackwardSlice` to acheive the same effect,
but this will be updated once the upstream change lands
(llvm/llvm-project#113478)

Reverts #18551

---------

Signed-off-by: Ian Wood <[email protected]>
Signed-off-by: Elias Joseph <[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.

4 participants