Skip to content

Commit bcf9826

Browse files
authored
[MLIR] Expose approximation patterns for tanh/erf. (#82750)
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.
1 parent 3b3d097 commit bcf9826

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

mlir/include/mlir/Dialect/Math/Transforms/Passes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ struct MathPolynomialApproximationOptions {
4545
bool enableAvx2 = false;
4646
};
4747

48+
void populatePolynomialApproximateTanhPattern(RewritePatternSet &patterns);
49+
void populatePolynomialApproximateErfPattern(RewritePatternSet &patterns);
50+
4851
void populateMathPolynomialApproximationPatterns(
4952
RewritePatternSet &patterns,
5053
const MathPolynomialApproximationOptions &options = {});

mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,16 @@ RsqrtApproximation::matchAndRewrite(math::RsqrtOp op,
14711471

14721472
//----------------------------------------------------------------------------//
14731473

1474+
void mlir::populatePolynomialApproximateTanhPattern(
1475+
RewritePatternSet &patterns) {
1476+
patterns.add<TanhApproximation>(patterns.getContext());
1477+
}
1478+
1479+
void mlir::populatePolynomialApproximateErfPattern(
1480+
RewritePatternSet &patterns) {
1481+
patterns.add<ErfPolynomialApproximation>(patterns.getContext());
1482+
}
1483+
14741484
void mlir::populateMathPolynomialApproximationPatterns(
14751485
RewritePatternSet &patterns,
14761486
const MathPolynomialApproximationOptions &options) {

0 commit comments

Comments
 (0)