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

[AMD] getBackwardSlice variant with handling for op regions #4993

Closed
wants to merge 1 commit into from

Conversation

karthik-man
Copy link
Contributor

@karthik-man karthik-man commented Oct 25, 2024

mlir::getBackwardSlice does not traverse through op regions. This can cause the backward slice to not be in topological order and this can result in the reordering pass moving a value's use before its def.

Example:

%0 op0 ...
%1 scf.if %arg0
{
%2 op1 %0, ...
}
%3 op2 %0,
%4 tt.load %1, %3

while gathering the backward slice of the tt.load, if op1's use of %0 is not seen during the post-order walk in mlir::getBackwardSlice, then the backward slice can have op0 after the scf.if. Global load reordering relies on the load's backward set being topologically sorted to move the load and its transitive dependencies.

This PR adds a getBackwardSlice variant with handling for op regions. This is a temporary fix until these changes are upstreamed to mlir::getBackwardSlice.

The core Triton is a small number of people, and we receive many PRs (thank
you!). To help us review your code more quickly, if you are a new
contributor (less than 3 PRs merged) we ask that you complete the following
tasks and include the filled-out checklist in your PR description.

Complete the following tasks before sending your PR, and replace [ ] with
[x] to indicate you have done them.

  • I am not making a trivial change, such as fixing a typo in a comment.

  • I have written a PR description following these
    rules.

  • I have run pre-commit run --from-ref origin/main --to-ref HEAD.

  • Select one of the following.

    • I have added tests.
      • /test for lit tests
      • /unittest for C++ tests
      • /python/test for end-to-end tests
    • This PR does not need a test because FILL THIS IN.
  • Select one of the following.

    • I have not added any lit tests.
    • The lit tests I have added follow these best practices,
      including the "tests should be minimal" section. (Usually running Python code
      and using the instructions it generates is not minimal.)

@karthik-man
Copy link
Contributor Author

@htyu @manman-ren

@karthik-man karthik-man force-pushed the backward_slice branch 3 times, most recently from 54ebd43 to 307d809 Compare October 25, 2024 13:22
mlir::getBackwardSlice does not handle op regions. This can cause
the backward slice to not be in topological order and this can result
in the reordering pass moving a value's use before its def.
This is a temporary local fix until these changes are upstreamed to mlir.
@@ -24,6 +25,73 @@ static bool isLocalLoadOrDotLayoutConversion(Operation *op) {
return false;
}

// Copy of mlir::getBackwardSlice with changes to handle nested regions.
// This is a temporary local fix until these changes are upstreamed to mlir.
static void getDeepBackwardSlice(Operation *op,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider making this fix to the MLIR code base, perhaps through BackwardSliceOptions?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah BackwardSliceOptions will be a good place to handle this variant.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah we should consider landing such general changes to upstream mlir. Then we can update llvm submodule to bring it in.

Copy link
Collaborator

@manman-ren manman-ren left a comment

Choose a reason for hiding this comment

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

Looks generally okay to me if this is a temporary workaround before landing the change in mlir.

@@ -24,6 +25,73 @@ static bool isLocalLoadOrDotLayoutConversion(Operation *op) {
return false;
}

// Copy of mlir::getBackwardSlice with changes to handle nested regions.
// This is a temporary local fix until these changes are upstreamed to mlir.
static void getDeepBackwardSlice(Operation *op,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah BackwardSliceOptions will be a good place to handle this variant.

};

// collect all the values used in the nested regions of this op
// SetVector<Region*> nestedRegions;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this line be removed?
Also it will be good to mark which part is different from mlir::getBackwardSlice.

Copy link
Collaborator

@antiagainst antiagainst 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 think the improvement should happen in upstream mlir first. Also, we are looking at to avoid doing complicated reordering with #4881; so this might be resolved the other simpler way.

@@ -24,6 +25,73 @@ static bool isLocalLoadOrDotLayoutConversion(Operation *op) {
return false;
}

// Copy of mlir::getBackwardSlice with changes to handle nested regions.
// This is a temporary local fix until these changes are upstreamed to mlir.
static void getDeepBackwardSlice(Operation *op,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah we should consider landing such general changes to upstream mlir. Then we can update llvm submodule to bring it in.

@antiagainst
Copy link
Collaborator

Closing this given superseded by #5363.

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