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
[MLIR][XLA] Buffer Assignment #37212
[MLIR][XLA] Buffer Assignment #37212
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First portion of nits. More coming.
ef5b032
to
964bfda
Compare
Refactored BufferAssignment analysis into two distinct parts:
|
Could you provide an example how the use of this would look like for hlo->lhlo? It is not clear to me how this composes. |
The intended use of this buffer assignment is that the dialect-expert creates an instance of BufferAssignmentLegalizer at the beginning of the pass (i.e. in the runOnFunction()) and passes this instance to all conversion-pattern classes using OwningRewritePatternList instance. BufferAssignmentOpConversionPattern<HloOpTy>::bufferAssignment->computeAllocPosition(result);
auto alloc = allocPosition.insertAlloc<AllocOp>(result, loc, memref_type); // we are going to remove result from the list of arguments in the next commit since it's unnecessary. Later on, --buffer-assignment flag must be passed to tf-opt to move Alloc and Dealloc operations in their proper positions. If there is no Dealloc for a buffer, it will be automatically inserted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get this landed and improve further in tree. Thanks!
773c9c7
to
4be191f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
} | ||
} | ||
return result; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a test covering this function? (our test coverage shows it uncovered)
} | ||
}); | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm missing where is this pass covered by tests?
Lacking my comment being addressed, I issued a revert here: #38291 |
This unfortunately leaves this PR to a terminal state. @dfki-ehna would you mind to open a new one? Thanks! |
@joker-eph Oh, I see 🔢 Maybe we can add a test dialect including a legalization step in order to simulate lowering from one dialect to another one (or even the same) with buffers? |
Why do we need a test dialect? I may be missing something but the description of the pass is:
I was expecting this to be able to run on something like LHLO? |
@joker-eph The test dialect will be needed if we want to have this pass in MLIR core, since there is no LHLO there. I think @dfki-mako was assuming this. |
@joker-eph I have already thought about this transfer and future features at the same time. It might be useful to have a small test dialect that contains additional features that we might want to think about and include in the general BA pass. |
@joker-eph Please note that this is not a strict requirement at the moment. We can include several Linalg-based tests in the MLIR core version and apply BA to them. |
I am a bit lost (but it is quite late here, my brain may be slow...): I was looking at this PR in TensorFlow, in a disconnected way from Core, and I see code that does not seem to have any test here. |
Yes and no. We had to redesign several parts and split some features (regarding legalization and use) into other PRs. No, because the test pass basically computes all required information to move allocs and deallocs. Yes, because the actual movement part is not covered. |
@joker-eph you are right with respect to this PR. It has never been our intention to push an untested pass. We address the missing-tests issue and add a complete test case to test the whole BA pass including movement of allocs and deallocs. |
Is there already a PR up for review? |
In this PR, we have provided our first draft for generic XLA buffer assignment. This generic BufferAssignment class automatically analyzes the values and their aliases (also in other blocks) and returns the positions of allocations and deallocations. To find these positions, the algorithm uses the block Dominator and Post-Dominator analyses. In our proposed algorithm, we have considered aliasing, liveness analysis, nested regions, branches, conditional branches, critical edges, and independency to custom block terminators. This implementation doesn't support block loops. However, we have considered this in our design. For this purpose, we only need to have a loop analysis to allocate and deallocate some special cases outside of these loops.
This is the sample usage of BufferAssignment class:
Or alternatively:
Please note that this class should be used during the legalization (i.e. HLO-To-LHLO).