Skip to content

Conversation

@neildhar
Copy link
Contributor

@neildhar neildhar commented Sep 25, 2025

When we construct a slice, we correctly only consider rematerialisations
that dominate the use in question. However, when rewriting the slice, we
allow any rematerialisation, including one that might not dominate the
users we want to rewrite.

To address this, record the set of rematerialisations that we permitted
while constructing the slice, and reuse them when rewriting the slice.
This ensures that both operations consider the same set of valid
rematerialisations.

Note that it is important that they are the same, because slice creation
stops once it encounters a valid rematerialisation, so the inputs to the
value we are looking up will not be in the slice.

This addresses the crash in #8257.

New contributor declaration

  • 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.)

@neildhar neildhar force-pushed the fix-layout-dominance branch from 3ea7fc5 to 7bb6583 Compare September 26, 2025 22:28
`getConvertBackwardSlice` currently includes any existing
rematerialisation it finds in the returned slice. However, this
shouldn't be necessary because that value does not need to be
rematerialised or included in the cost calculation.

Instead, once we find a valid rematerialisation, we can stop the
traversal right away.
@neildhar neildhar force-pushed the fix-layout-dominance branch from 7bb6583 to 087c9b7 Compare September 26, 2025 22:33
@neildhar neildhar marked this pull request as ready for review September 29, 2025 22:22
@neildhar neildhar requested a review from ptillet as a code owner September 29, 2025 22:22
if (Value remat = getRematValue(v, layoutIt->second)) {
// If we found a valid rematerialization for this value while constructing
// the slice, use that.
if (Value remat = existingRemats.lookup({v, layoutIt->second})) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you check properlyDominates here instead and not need to pass the additional data structure around everywhere?

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 issue is knowing which users it needs to dominate. We need to consider exactly the same rematerialisations as getConvertBackwardSlice here because any value that getConvertBackwardSlice finds an existing rematerialisation for will not be propagated through when constructing the backward slice.

If we require that the rematerialisation dominate all the users (or the original value itself), then it is possible we will disqualify rematerialisations that getConvertBackwardSlice did allow.

@neildhar neildhar force-pushed the fix-layout-dominance branch from 087c9b7 to 364706a Compare October 6, 2025 04:47
When we construct a slice, we correctly only consider rematerialisations
that dominate the use in question. However, when rewriting the slice, we
allow any rematerialisation, including one that might not dominate the
users we want to rewrite.

To address this, record the set of rematerialisations that we permitted
while constructing the slice, and reuse them when rewriting the slice.
This ensures that both operations consider the same set of valid
rematerialisations.

Note that it is important that they are the same, because slice creation
stops once it encounters a valid rematerialisation, so the inputs to the
value we are looking up will not be in the slice.
@neildhar neildhar force-pushed the fix-layout-dominance branch from 364706a to a80b07e Compare October 6, 2025 14:54
@peterbell10 peterbell10 merged commit e3cf2ad into triton-lang:main Oct 7, 2025
9 checks passed
@neildhar neildhar deleted the fix-layout-dominance branch October 7, 2025 20:35
@ThomasRaoux
Copy link
Collaborator

This is causing some crash in our internal kernels. (causes inconsistent types to be generated: error: 'arith.cmpi' op failed to verify that result type has i1 element type and same shape as operands)
I'll revert this for now. Sorry I haven't had a chance to review so I'm not sure if the problem is obvious or not

ThomasRaoux added a commit that referenced this pull request Oct 7, 2025
ThomasRaoux added a commit that referenced this pull request Oct 7, 2025
@neildhar
Copy link
Contributor Author

neildhar commented Oct 7, 2025

@ThomasRaoux Sorry about the failures, if you have a repro or more information you can share, I'll dig into them when I next get the chance.

@ThomasRaoux
Copy link
Collaborator

@ThomasRaoux Sorry about the failures, if you have a repro or more information you can share, I'll dig into them when I next get the chance.

I cannot share the repro at the moment but I'll try to reduce it and share

yangshuxin pushed a commit to yangshuxin/triton that referenced this pull request Oct 9, 2025
When we construct a slice, we correctly only consider rematerialisations
that dominate the use in question. However, when rewriting the slice, we
allow any rematerialisation, including one that might not dominate the
users we want to rewrite.

To address this, record the set of rematerialisations that we permitted
while constructing the slice, and reuse them when rewriting the slice.
This ensures that both operations consider the same set of valid
rematerialisations.

Note that it is important that they are the same, because slice creation
stops once it encounters a valid rematerialisation, so the inputs to the
value we are looking up will not be in the slice.

This addresses the crash in
triton-lang#8257.
yangshuxin pushed a commit to yangshuxin/triton that referenced this pull request Oct 9, 2025
Jokeren pushed a commit that referenced this pull request Oct 10, 2025
When we construct a slice, we correctly only consider rematerialisations
that dominate the use in question. However, when rewriting the slice, we
allow any rematerialisation, including one that might not dominate the
users we want to rewrite.

To address this, record the set of rematerialisations that we permitted
while constructing the slice, and reuse them when rewriting the slice.
This ensures that both operations consider the same set of valid
rematerialisations.

Note that it is important that they are the same, because slice creation
stops once it encounters a valid rematerialisation, so the inputs to the
value we are looking up will not be in the slice.

This addresses the crash in
#8257.
Jokeren pushed a commit that referenced this pull request Oct 10, 2025
ita9naiwa pushed a commit to ita9naiwa/triton that referenced this pull request Oct 12, 2025
When we construct a slice, we correctly only consider rematerialisations
that dominate the use in question. However, when rewriting the slice, we
allow any rematerialisation, including one that might not dominate the
users we want to rewrite.

To address this, record the set of rematerialisations that we permitted
while constructing the slice, and reuse them when rewriting the slice.
This ensures that both operations consider the same set of valid
rematerialisations.

Note that it is important that they are the same, because slice creation
stops once it encounters a valid rematerialisation, so the inputs to the
value we are looking up will not be in the slice.

This addresses the crash in
triton-lang#8257.
ita9naiwa pushed a commit to ita9naiwa/triton that referenced this pull request Oct 12, 2025
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