-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][Interface] Factor out common IndexingMapOpInterface behavior in a new generic interface #145313
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
Conversation
@llvm/pr-subscribers-mlir-linalg @llvm/pr-subscribers-mlir-vector Author: Nicolas Vasilache (nicolasvasilache) Changes…contract Full diff: https://github.com/llvm/llvm-project/pull/145313.diff 1 Files Affected:
diff --git a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
index 926a92eff2ebb..7ac661d8bbf69 100644
--- a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
+++ b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
@@ -207,6 +207,39 @@ def Vector_ContractionOp :
.template getAsValueRange<IteratorTypeAttr, IteratorType>();
return {range.begin(), range.end()};
}
+
+ //===------------------------------------------------------------------===//
+ // The code below is shared with LinalgStructuredInterface.
+ // vector.contract is really a linalg.generic on vectors without region.
+ // TODO: factor out in a common interface to inherit from ince identified.
+ //===------------------------------------------------------------------===//
+ ArrayRef<int64_t> getShape(OpOperand * opOperand) {
+ assert(opOperand->getOwner() == this->getOperation());
+ Type t = opOperand->get().getType();
+ return cast<VectorType>(t).getShape();
+ }
+
+ AffineMap getLoopsToShapesMap() {
+ auto maps = getIndexingMapsArray();
+ return concatAffineMaps(maps);
+ }
+
+ AffineMap getShapesToLoopsMap() {
+ return inversePermutation(getLoopsToShapesMap());
+ }
+
+ SmallVector<int64_t> getStaticShape(){
+ SmallVector<int64_t> res;
+ for (OpOperand &opOperand : this->getOperation()->getOpOperands())
+ llvm::append_range(res, getShape(&opOperand));
+ return res;
+ }
+
+ SmallVector<int64_t> getStaticLoopRanges() {
+ SmallVector<int64_t> viewSizes = getStaticShape();
+ AffineMap invertedMap = getShapesToLoopsMap();
+ return invertedMap.compose(viewSizes);
+ }
}];
let hasCanonicalizer = 1;
|
a1373fb
to
91f7ea2
Compare
This allows external systems to make use of IREE's vector_distribute functionality in a composable manner. This depends on llvm/llvm-project#145313 landing and being integrated into IREE. Signed-off-by: Nicolas Vasilache <[email protected]>
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.
LGTM, but add comments pointing each member to the corresponding LinalgStructuredInterface
method, otherwise the methods appear undocumented and it's unclear what they do without looking at the header.
NIT, fix description.
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 think a better implementation would to add these methods to IndexingMapOpInterface and make vector.contract implement it.
I agree, but that's a can of worms in RFCs, as we don't have a |
I don't think it is. The Interface lives in lib/Interfaces right? |
|
I'm OK with this change in principle, but we should either add dedicated tests or ensure there are in-tree uses of this interface. Otherwise, it becomes "dead code," and there's nothing stopping it from being removed in the future by someone upstream. |
@rengolin @Groverkss @banach-space I have a WIP followup to put stuff in lib/Interface but I think I am limited atm. TL;DR:
I can put up a followup PR and we can discuss there |
good point ! |
#145332 if someone sees a way to do this better |
I like that PR much more. I think we should go with that instead. |
778833f
to
8b3665b
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.
LGTM! This is really nice and will be good for other operations as well.
I think there is an issue with dps interface implementation and indexingmapopinterface being in opposite files, but rest lgtm.
Also, would be good to change the pr title.
8b3665b
to
8e819cf
Compare
…n a new generic interface
8e819cf
to
6c53f21
Compare
c563af4
to
ef7ee8e
Compare
…n a new generic interface (llvm#145313) Refactor the verifiers to make use of the common bits and make `vector.contract` also use this interface. In the process, the confusingly named getStaticShape has disappeared. Note: the verifier for IndexingMapOpInterface is currently called manually from other verifiers as it was unclear how to avoid it taking precedence over more meaningful error messages
Refactor the verifiers to make use of the common bits and make
vector.contract
also use this interface.In the process, the confusingly named getStaticShape has disappeared.
Note: the verifier for IndexingMapOpInterface is currently called manually from other verifiers as it was unclear how to avoid it taking precedence over more meaningful error messages