-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][linalg][NFC] Make LinalgOp
inherit from DestinationStyleOpInterface
#66995
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
Merged
matthias-springer
merged 1 commit into
llvm:main
from
matthias-springer:linalg_op_dest_style_interface
Sep 21, 2023
Merged
[mlir][linalg][NFC] Make LinalgOp
inherit from DestinationStyleOpInterface
#66995
matthias-springer
merged 1 commit into
llvm:main
from
matthias-springer:linalg_op_dest_style_interface
Sep 21, 2023
Conversation
This file contains hidden or 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
…nterface` Dependent interfaces have been added a while ago and these TODOs can be addressed now.
nicolasvasilache
approved these changes
Sep 21, 2023
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.
nice thanks!
@llvm/pr-subscribers-mlir-linalg @llvm/pr-subscribers-mlir ChangesDependent interfaces have been added a while ago and these TODOs can be addressed now. Full diff: https://github.com/llvm/llvm-project/pull/66995.diff 1 Files Affected:
diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
index 78431b9f66f9014..839861c2369ca1d 100644
--- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
+++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
@@ -13,6 +13,7 @@
#ifndef LINALG_IR_LINALGINTERFACES
#define LINALG_IR_LINALGINTERFACES
+include "mlir/Interfaces/DestinationStyleOpInterface.td"
include "mlir/IR/OpBase.td"
// The 'LinalgContractionOpInterface' provides access to the
@@ -178,7 +179,8 @@ def LinalgFillOpInterface : OpInterface<"FillOpInterface"> {
}
// The 'LinalgStructuredInterface' provides access to the 'LinalgOp' interface.
-def LinalgStructuredInterface : OpInterface<"LinalgOp"> {
+def LinalgStructuredInterface
+ : OpInterface<"LinalgOp", [DestinationStyleOpInterface]> {
let cppNamespace = "::mlir::linalg";
let methods = [
//===------------------------------------------------------------------===//
@@ -321,13 +323,7 @@ def LinalgStructuredInterface : OpInterface<"LinalgOp"> {
/*args=*/(ins),
/*methodBody=*/"",
/*defaultImplementation=*/[{
- // MLIR currently does not support dependent interfaces or interface
- // inheritance. By construction all ops with StructuredOpInterface must
- // implement DestinationStyleOpInterface.
- // TODO: reevaluate the need for a cast when a better mechanism exists.
- return getBlock()->getArguments().take_front(
- cast<DestinationStyleOpInterface>(*this->getOperation())
- .getNumDpsInputs());
+ return getBlock()->getArguments().take_front($_op.getNumDpsInputs());
}]
>,
InterfaceMethod<
@@ -339,13 +335,7 @@ def LinalgStructuredInterface : OpInterface<"LinalgOp"> {
/*args=*/(ins),
/*methodBody=*/"",
/*defaultImplementation=*/[{
- // MLIR currently does not support dependent interfaces or interface
- // inheritance. By construction all ops with StructuredOpInterface must
- // implement DestinationStyleOpInterface.
- // TODO: reevaluate the need for a cast when a better mechanism exists.
- return getBlock()->getArguments().take_back(
- cast<DestinationStyleOpInterface>(*this->getOperation())
- .getNumDpsInits());
+ return getBlock()->getArguments().take_back($_op.getNumDpsInits());
}]
>,
InterfaceMethod<
@@ -418,13 +408,7 @@ def LinalgStructuredInterface : OpInterface<"LinalgOp"> {
assert(result.getOwner() == this->getOperation());
auto indexingMaps =
$_op.getIndexingMaps().template getAsValueRange<AffineMapAttr>();
- // MLIR currently does not support dependent interfaces or interface
- // inheritance. By construction all ops with StructuredOpInterface must
- // implement DestinationStyleOpInterface.
- // TODO: reevaluate the need for a cast when a better mechanism exists.
- return *(indexingMaps.begin() +
- cast<DestinationStyleOpInterface>(*this->getOperation())
- .getNumDpsInputs() +
+ return *(indexingMaps.begin() + $_op.getNumDpsInputs() +
result.getResultNumber());
}]
>,
@@ -439,14 +423,8 @@ def LinalgStructuredInterface : OpInterface<"LinalgOp"> {
/*methodBody=*/"",
/*defaultImplementation=*/[{
assert(opOperand->getOwner() == this->getOperation());
- // MLIR currently does not support dependent interfaces or interface
- // inheritance. By construction all ops with StructuredOpInterface must
- // implement DestinationStyleOpInterface.
- // TODO: reevaluate the need for a cast when a better mechanism exists.
int64_t resultIndex =
- opOperand->getOperandNumber() -
- cast<DestinationStyleOpInterface>(*this->getOperation())
- .getNumDpsInputs();
+ opOperand->getOperandNumber() - $_op.getNumDpsInputs();
assert(resultIndex >= 0 &&
resultIndex < this->getOperation()->getNumResults());
Operation *yieldOp = getBlock()->getTerminator();
@@ -800,80 +778,6 @@ def LinalgStructuredInterface : OpInterface<"LinalgOp"> {
/// Return the index in the indexingMaps vector that corresponds to this `opOperand`
int64_t getIndexingMapIndex(OpOperand *opOperand);
-
- //========================================================================//
- // Forwarding functions to access interface methods from the
- // DestinationStyleOpInterface.
- // MLIR currently does not support dependent interfaces or interface
- // inheritance. By construction all ops with StructuredOpInterface must
- // implement DestinationStyleOpInterface.
- // TODO: reevaluate the need for a cast when a better mechanism exists.
- //========================================================================//
-
- int64_t getNumDpsInputs() {
- return cast<DestinationStyleOpInterface>(*this->getOperation())
- .getNumDpsInputs();
- }
-
- int64_t getNumDpsInits() {
- return cast<DestinationStyleOpInterface>(*this->getOperation())
- .getNumDpsInits();
- }
-
- OpOperandVector getDpsInputOperands() {
- return cast<DestinationStyleOpInterface>(*this->getOperation())
- .getDpsInputOperands();
- }
-
- OpOperand *getDpsInputOperand(int64_t i) {
- return cast<DestinationStyleOpInterface>(*this->getOperation())
- .getDpsInputOperand(i);
- }
-
- void setDpsInitOperand(int64_t i, Value value) {
- return cast<DestinationStyleOpInterface>(*this->getOperation())
- .setDpsInitOperand(i, value);
- }
-
- OpOperandVector getDpsInitOperands() {
- return cast<DestinationStyleOpInterface>(*this->getOperation())
- .getDpsInitOperands();
- }
-
- OpOperand *getDpsInitOperand(int64_t i) {
- return cast<DestinationStyleOpInterface>(*this->getOperation())
- .getDpsInitOperand(i);
- }
-
- bool isDpsInput(OpOperand *opOperand) {
- return cast<DestinationStyleOpInterface>(*this->getOperation())
- .isDpsInput(opOperand);
- }
-
- bool isDpsInit(OpOperand *opOperand) {
- return cast<DestinationStyleOpInterface>(*this->getOperation())
- .isDpsInit(opOperand);
- }
-
- bool isScalar(OpOperand *opOperand) {
- return cast<DestinationStyleOpInterface>(*this->getOperation())
- .isScalar(opOperand);
- }
-
- OpResult getTiedOpResult(OpOperand *opOperand) {
- return cast<DestinationStyleOpInterface>(*this->getOperation())
- .getTiedOpResult(opOperand);
- }
-
- bool hasBufferSemantics() {
- return cast<DestinationStyleOpInterface>(*this->getOperation())
- .hasBufferSemantics();
- }
-
- bool hasTensorSemantics() {
- return cast<DestinationStyleOpInterface>(*this->getOperation())
- .hasTensorSemantics();
- }
}];
let verify = [{ return detail::verifyStructuredOpInterface($_op); }];
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Dependent interfaces have been added a while ago and these TODOs can be addressed now.