Skip to content

Fix error in FuseMultiUseElementwiseProducersPass#18855

Closed
IanWood1 wants to merge 3 commits intoiree-org:mainfrom
IanWood1:fix_multi_use_fusion_error
Closed

Fix error in FuseMultiUseElementwiseProducersPass#18855
IanWood1 wants to merge 3 commits intoiree-org:mainfrom
IanWood1:fix_multi_use_fusion_error

Conversation

@IanWood1
Copy link
Contributor

@IanWood1 IanWood1 commented Oct 21, 2024

isHorizontalToGroup doesn't check op to make sure it doesn't use any values defined above. This is a workaround for the fact that getBackwardsSlice doesn't track ops if they are used in the region but not as an operand to the operation.

Closes #18847

@IanWood1
Copy link
Contributor Author

IanWood1 commented Oct 21, 2024

This pass is very brittle because any constant hoisted out of a linalg.generic will cause fusion to be blocked. e.g. running -canonicalize on the test I changed will break it. It might be worth rewriting isHorizontalToGroup and moveOperandDefs to not use getBackwardsSlice.

Edit: this is separate from this PR. I created an issue here #18856

`op` isn't included in `slice` so it must be independently checked to
make sure it doesn't use any values defined above. Otherwise, a consumer
that uses values defined above may be fused with a producer causing
dominance errors.

Closes iree-org#18847

Signed-off-by: Ian Wood <ianwood2024@u.northwestern.edu>
Signed-off-by: Ian Wood <ianwood2024@u.northwestern.edu>
@IanWood1 IanWood1 force-pushed the fix_multi_use_fusion_error branch from 37e4da8 to 89d8862 Compare October 21, 2024 16:53
@MaheshRavishankar
Copy link
Collaborator

I think this is basically a bug in backwardSlice computation. For operations that have regions, it should follow those that are defined outside the op and used in the region as well. We can try it first by adding a wrapper around getBackwardSlice that does this and see if that fixes it, and then you can try to update the upstream slice functionality.

Signed-off-by: Ian Wood <ianwood2024@u.northwestern.edu>
@IanWood1
Copy link
Contributor Author

I think this is basically a bug in backwardSlice computation. For operations that have regions, it should follow those that are defined outside the op and used in the region as well. We can try it first by adding a wrapper around getBackwardSlice that does this and see if that fixes it, and then you can try to update the upstream slice functionality.

I have something working, but the wrapper needs some cleanup because it's a bit confusing.

@IanWood1 IanWood1 linked an issue Oct 24, 2024 that may be closed by this pull request
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 <ianwood2024@u.northwestern.edu>
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 <ianwood2024@u.northwestern.edu>
Signed-off-by: Elias Joseph <eljoseph@amd.com>
@IanWood1
Copy link
Contributor Author

IanWood1 commented Nov 5, 2024

#19032

@IanWood1 IanWood1 closed this Nov 5, 2024
IanWood1 added a commit that referenced this pull request Nov 5, 2024
Since the upstream changes to `getBackwardSlice` have been integrated
(llvm/llvm-project#114452), its now possible to
reland #18855.

The first commit relands the reverted changes. The second commit uses
`BackwardSliceOptions::omitUsesFromAbove` to track all transitive
definitions of the possibly fusible op preventing ops being moved before
uses. Also, added two tests that check for this issue.



Closes #18879

---------

Signed-off-by: Ian Wood <ianwood2024@u.northwestern.edu>
Groverkss pushed a commit to Groverkss/iree that referenced this pull request Dec 1, 2024
…rg#19032)

Since the upstream changes to `getBackwardSlice` have been integrated
(llvm/llvm-project#114452), its now possible to
reland iree-org#18855.

The first commit relands the reverted changes. The second commit uses
`BackwardSliceOptions::omitUsesFromAbove` to track all transitive
definitions of the possibly fusible op preventing ops being moved before
uses. Also, added two tests that check for this issue.



Closes iree-org#18879

---------

Signed-off-by: Ian Wood <ianwood2024@u.northwestern.edu>
giacs-epic pushed a commit to giacs-epic/iree that referenced this pull request Dec 4, 2024
…g#18917)

The reverted commit does not handle when the "consumer" uses a value
defined above. See iree-org#18879 for the
original issue. This is causing issue with ~15 onnx models.

I have a PR (iree-org#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 iree-org#18551

---------

Signed-off-by: Ian Wood <ianwood2024@u.northwestern.edu>
Signed-off-by: Giacomo Serafini <179146510+giacs-epic@users.noreply.github.com>
giacs-epic pushed a commit to giacs-epic/iree that referenced this pull request Dec 4, 2024
…rg#19032)

Since the upstream changes to `getBackwardSlice` have been integrated
(llvm/llvm-project#114452), its now possible to
reland iree-org#18855.

The first commit relands the reverted changes. The second commit uses
`BackwardSliceOptions::omitUsesFromAbove` to track all transitive
definitions of the possibly fusible op preventing ops being moved before
uses. Also, added two tests that check for this issue.

Closes iree-org#18879

---------

Signed-off-by: Ian Wood <ianwood2024@u.northwestern.edu>
Signed-off-by: Giacomo Serafini <179146510+giacs-epic@users.noreply.github.com>
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.

[regression] error: operand #0 does not dominate this use Operand #1 does not dominate this use

2 participants

Comments