[Mlir-commits] [mlir] [MLIR] Expose approximation patterns for tanh/erf. (PR #82750)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Feb 23 02:54:27 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Johannes Reifferscheid (jreiffers)
<details>
<summary>Changes</summary>
These patterns can already be used via
populateMathPolynomialApproximationPatterns, but that includes a number of other patterns that may not be needed.
There are already similar functions for expansion.
For now only adding tanh and erf since I have a concrete use case for these two.
---
Full diff: https://github.com/llvm/llvm-project/pull/82750.diff
2 Files Affected:
- (modified) mlir/include/mlir/Dialect/Math/Transforms/Passes.h (+4)
- (modified) mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp (+10)
``````````diff
diff --git a/mlir/include/mlir/Dialect/Math/Transforms/Passes.h b/mlir/include/mlir/Dialect/Math/Transforms/Passes.h
index 010dde5ea73847..c0b5c0080bdcef 100644
--- a/mlir/include/mlir/Dialect/Math/Transforms/Passes.h
+++ b/mlir/include/mlir/Dialect/Math/Transforms/Passes.h
@@ -45,6 +45,10 @@ struct MathPolynomialApproximationOptions {
bool enableAvx2 = false;
};
+
+void populatePolynomialApproximateTanhPattern(RewritePatternSet &patterns);
+void populatePolynomialApproximateErfPattern(RewritePatternSet &patterns);
+
void populateMathPolynomialApproximationPatterns(
RewritePatternSet &patterns,
const MathPolynomialApproximationOptions &options = {});
diff --git a/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp b/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
index 71e4e13103f514..962cb28b7c2ab9 100644
--- a/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
+++ b/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
@@ -1471,6 +1471,16 @@ RsqrtApproximation::matchAndRewrite(math::RsqrtOp op,
//----------------------------------------------------------------------------//
+void mlir::populatePolynomialApproximateTanhPattern(
+ RewritePatternSet &patterns) {
+ patterns.add<TanhApproximation>(patterns.getContext());
+}
+
+void mlir::populatePolynomialApproximateErfPattern(
+ RewritePatternSet &patterns) {
+ patterns.add<ErfPolynomialApproximation>(patterns.getContext());
+}
+
void mlir::populateMathPolynomialApproximationPatterns(
RewritePatternSet &patterns,
const MathPolynomialApproximationOptions &options) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/82750
More information about the Mlir-commits
mailing list