-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][linalg]: Fixed possible memory leak in cloneToCollapsedOp #87595
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 Author: Aviad Cohen (AviadCo) Changes
Full diff: https://github.com/llvm/llvm-project/pull/87595.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp b/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp
index 9453502a253f16..34a5adec07bbea 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp
@@ -1497,9 +1497,12 @@ LinalgOp cloneToCollapsedOp<LinalgOp>(RewriterBase &rewriter, LinalgOp origOp,
SmallVector<Type> resultTypes;
collapseOperandsAndResults(origOp, collapsingInfo, rewriter, inputOperands,
outputOperands, resultTypes);
- return cast<LinalgOp>(clone(
- rewriter, origOp, resultTypes,
- llvm::to_vector(llvm::concat<Value>(inputOperands, outputOperands))));
+ IRMapping mapper;
+ for (auto [orig, input] : llvm::zip(origOp.getDpsInputs(), inputOperands))
+ mapper.map(orig, input);
+ for (auto [orig, output] : llvm::zip(origOp.getDpsInits(), outputOperands))
+ mapper.map(orig, output);
+ return cast<LinalgOp>(rewriter.clone(*origOp.getOperation(), mapper));
}
/// Collapse a `GenericOp`
|
@llvm/pr-subscribers-mlir-linalg Author: Aviad Cohen (AviadCo) Changes
Full diff: https://github.com/llvm/llvm-project/pull/87595.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp b/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp
index 9453502a253f16..34a5adec07bbea 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp
@@ -1497,9 +1497,12 @@ LinalgOp cloneToCollapsedOp<LinalgOp>(RewriterBase &rewriter, LinalgOp origOp,
SmallVector<Type> resultTypes;
collapseOperandsAndResults(origOp, collapsingInfo, rewriter, inputOperands,
outputOperands, resultTypes);
- return cast<LinalgOp>(clone(
- rewriter, origOp, resultTypes,
- llvm::to_vector(llvm::concat<Value>(inputOperands, outputOperands))));
+ IRMapping mapper;
+ for (auto [orig, input] : llvm::zip(origOp.getDpsInputs(), inputOperands))
+ mapper.map(orig, input);
+ for (auto [orig, output] : llvm::zip(origOp.getDpsInits(), outputOperands))
+ mapper.map(orig, output);
+ return cast<LinalgOp>(rewriter.clone(*origOp.getOperation(), mapper));
}
/// Collapse a `GenericOp`
|
@srcarroll I found this memory leak using Asan checks. Can you please take a look on the fix? |
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!
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.
Oh interesting. Good catch. Thanks for the fix!
f09c16e
to
32d51f1
Compare
@MaheshRavishankar @srcarroll |
32d51f1
to
06fe902
Compare
since I dont understand why the original code causes memory leaks and why this fixes it, you should have @MaheshRavishankar or @nicolasvasilache give the final approval. |
* Direct call to `clone` function leads to memory leak. Instead, we would can use `RewriterBase` clone function.
06fe902
to
d03112b
Compare
clone
function leads to memory leak. Instead, we would can useRewriterBase
clone function.