-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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][Linalg] Expose linalg.matmul and linalg.contract via Python API #126377
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e3f2a7c
[MLIR][Linalg] Expose linalg.matmul and linalg.contract via Python API
rolfmorel 57b2509
Fix linalg.matmul tests which encoded different placements of indexin…
rolfmorel 18ff3a6
Python formatting
rolfmorel 2e6bf66
Make indexing_maps optional on matmul, as it should be
rolfmorel 85426f6
Fix matmul's indexing_maps issue
rolfmorel e98838d
Get rid of "whole new type" by introducing "context dependent" defaul…
rolfmorel 931b473
Move builderCall parameter from custom attr class to DefaultValued(Op…
rolfmorel 538566a
Remove junk
rolfmorel c81c97f
Allow access to `$_builder` in Attr's `defaultValue`
rolfmorel f83f7ae
Switch argument format to that of OpDSL-derived linalg ops
rolfmorel 7a5234f
Py formatting fix
rolfmorel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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.
I get what you're going for here but the right way to do this is just add a custom builder that constructs this attribute rather than adding a whole new type. That won't work for python because python can only call the default builder (which is maybe why you went this direction) but there it's the same story - the MatmulOp builder just needs to construct the correct indexing maps.
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.
The thing is, as far as I understand now no builder (really no op-specific C++ code at all) is called when an op gets constructed from Python (see from here to here to here to here to finally here ). The only thing one can do is pass in default values for attributes. Could you point me to an example of specifying "the default builder" for an op?
And yes, preferably I would just have
DefaultValuedOptionalAttr<AffineMapArrayAttr, "MatmulOp::getDefaultIndexingMaps($_builder.getContext())">:$indexing_maps
in MatmulOp'sarguments
(note, to my knowledge, we cannot specify custom "builders" in this list), but that doesn't work. The problem is thatDefaultValuedOptionalAttr
assumes that thedefaultValue
can be given without access to the context. However, that is not true in this case (that is, attempting the above leads toerror: use of undeclared identifier '$_builder'
). The workaround is to just expand whatDefaultValuedOptionalAttr
does to getDefaultValuedMatmulIndexingMapsAttr
in which we can modifyconstBuilderCall
so that we can pass the context in case of thedefaultValue
. That the resulting attr is not "anonymous" - and hence we get a whole newtypeattr - is rather unfortunate though.If you have suggestions for how to effect a cleaner approach, I am all ears!
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.
Note, latest commit gets rid of whole new type: now no other code is needed/aware of that we aren't using
DefaultValuedOptionalAttr<AffineMapArrayAttr, ...>
.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.
Latest commit now moves the
builderCall
parameter to DefaultValued(Optional)Attr.Probably an even cleaner solution is to just allow
$_builder
in Attr'sdefaultValue
... (that's an exploration for another time though).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.
Rather than let my dreams be dreams, I decided to just get this to work. I doubt we will get to a cleaner solution than this.
Nevertheless, @makslevental, if you could give some pointers to info on "default builders" and how Python is supposed to invoke those, that would be much appreciated!