-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir][linalg] Edit the yieldOutputs method's builder #73900
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
base: main
Are you sure you want to change the base?
[mlir][linalg] Edit the yieldOutputs method's builder #73900
Conversation
@llvm/pr-subscribers-mlir-core @llvm/pr-subscribers-mlir-linalg Author: Amir Bishara (amirBish) ChangesPassing the Full diff: https://github.com/llvm/llvm-project/pull/73900.diff 3 Files Affected:
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
index 58af9995548e939..11ebbabe9773787 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
@@ -480,8 +480,8 @@ class RegionBuilderHelper {
llvm_unreachable("unsupported type conversion function");
}
- void yieldOutputs(ValueRange values) {
- OpBuilder builder = getBuilder();
+ void yieldOutputs(OpBuilder builder, ValueRange values) {
+ builder.setInsertionPointToEnd(&block);
Location loc = builder.getUnknownLoc();
builder.create<YieldOp>(loc, values);
}
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorPasses.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorPasses.cpp
index 375e10f9068e43b..e14efd8def0920d 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorPasses.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorPasses.cpp
@@ -260,6 +260,7 @@ struct SparseTensorCodegenPass
// The following operations and dialects may be introduced by the
// codegen rules, and are therefore marked as legal.
target.addLegalOp<linalg::FillOp>();
+ target.addLegalOp<linalg::YieldOp>();
target.addLegalDialect<
arith::ArithDialect, bufferization::BufferizationDialect,
complex::ComplexDialect, memref::MemRefDialect, scf::SCFDialect>();
diff --git a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
index fb3c9d48f9a9821..cd8398b973a5677 100644
--- a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
+++ b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
@@ -1012,7 +1012,7 @@ void {0}::regionBuilder(ImplicitLocOpBuilder &b,
SmallVector<Value> yields;
{2}
{3}
- helper.yieldOutputs(yields);
+ helper.yieldOutputs(b, yields);
}
)FMT";
auto &args = opConfig.structuredOp->args;
|
A reproduction for the stack trace that I've encountered
|
void yieldOutputs(ValueRange values) { | ||
OpBuilder builder = getBuilder(); | ||
void yieldOutputs(OpBuilder builder, ValueRange values) { | ||
builder.setInsertionPointToEnd(&block); |
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.
What's the difference here exactly with before? Looking at the implementation of getBuilder()
I'm not spotting it immediately.
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.
In the previous one the builder is being constructed from the block's argument context block.getArgument(0).getContext()
, here is not the case It is being passed as is.
when using the rewriter of the MatchAndRewrite pattern we should use the rewriter which has been passed and not creating a new builder. That what has made the memory leakage.
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.
ping
@@ -260,6 +260,7 @@ struct SparseTensorCodegenPass | |||
// The following operations and dialects may be introduced by the | |||
// codegen rules, and are therefore marked as legal. | |||
target.addLegalOp<linalg::FillOp>(); | |||
target.addLegalOp<linalg::YieldOp>(); |
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 a test failing if you don't add that?
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.
yep, without this legalizing YieldOp
, the RewritePattern
won't be applied (since YieldOp it's not legal).
@MaheshRavishankar are you familiar with these |
Passing the
RegionBuilder
's builder to theyieldOutputs
method, Instead of creating a new one within theyieldOutputs
method. This change is being made since having memory leaks issues (when compiling with address sanitizer) when applyingRewritePattern
onLinalgStructuredOp
(creating and erasing op withinmatchAndRewrite
method would reproduce the issue).