-
Notifications
You must be signed in to change notification settings - Fork 74k
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] Add constant folder for xla_hlo.broadcast_in_dim op #40745
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This one particularly is more than a splat: it is a splat into a 0d scalar tensor type (the splat is somewhat incidental?). By having this as a folding rule, I lose the ability to represent a scalar-constant broadcast in HLO (since it will always be folded to fully materialized). Having that structure (not unconditionally materializing scalar broadcasts) is fairly important from an analysis on tensors perspective as having this knowledge enables various size-sensitive optimizations.
I agree that this is a valid folding from a correctness perspective, but it limits what we can express in mhlo (since this is the current idiom for representing a scalar broadcast and is used quite extensively).
I'm struggling with an "HLO principles" reason why this folding should be disallowed and the following allowed, though. This may actually be pointing at a missing op (i.e. mhlo.broadcast_scalar) if this case is important to represent at this level.
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.
@stellaraccident: this one is a splat! :-) (a trivial splat). Please see lines 550-551 in hlo_ops.cc where I'm explicitly checking for splat attributes. For the rest that you mention below, please see my post below on why having one form is important.
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 for bearing with me (and side note: I'm sorry to have triggered another round of review on such a simple PR -- I know how frustrating that can be).
Now re-reading this, I realize I was missing the syntactic distinction of the splat being preserved in this transformation (while more verbose, I did appreciate that we used to actually spell out "splat"). I had gotten used to keying off of the 0d-ness of the tensor as the distinguishing characteristic while treating the originating SplatElementsAttr as incidental. So you are right: this preserves the same information when considering the attribute type of the constant and as long as the splat is handled correctly all the way down, then this can be fine (modulo bugs).
As one of the things that we've found challenging in the past, the IREE team is a bit wired to see unnecessary constant expansions as problematic, and the bias there certainly kept me from seeing this alternative simplification.