summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp
AgeCommit message (Collapse)Author
2025-07-23[mlir] Remove unused includes (NFC) (#150266)Kazu Hirata
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-07-22[mlir][NFC] update `mlir/Dialect` create APIs (19/n) (#149926)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2025-07-13[mlir] Remove unused includes (NFC) (#148535)Kazu Hirata
2025-03-11[mlir][math] add benefit arg to populate math approximations/expansions ↵Emilio Cota
(#130782) This is a follow-up to #127291, which added the benefit arg to lowerings to intrinsics and libm. In this change we add the benefit arg to the math approximation and expansion lowerings, which allows users to establish a preferred order among all three math lowerings, namely approximations, intrinsics and libm. Note that we're only updating the new API added in #126103. The legacy one (`mlir::populateMathPolynomialApproximationPatterns`) is left unmodified to encourage users to move out of it.
2025-02-18[MLIR][Math] Add erfc to math dialect (#126439)Jan Leyonberg
This patch adds the erfc op to the math dialect. It also does lowering of the math.erfc op to libm calls. There is also a f32 polynomial approximation for the function based on https://stackoverflow.com/questions/35966695/vectorizable-implementation-of-complementary-error-function-erfcf This is in turn based on M. M. Shepherd and J. G. Laframboise, "Chebyshev Approximation of (1+2x)exp(x^2)erfc x in 0 <= x < INF", Mathematics of Computation, Vol. 36, No. 153, January 1981, pp. 249-253. The code has a ULP error less than 3, which was tested, and MLIR test values were verified against the C implementation.
2025-02-10[MLIR][Math] Add fine-grained populate-patterns functions for math function ↵Benoit Jacob
rewrites. (#126103) The existing `mlir::populateMathPolynomialApproximationPatterns` is coarse-grained and inflexible: - It populates 2 distinct classes of patterns: (1) polynomial approximations, (2) expansions of operands to f32. - It does not offer knobs to select which math functions to apply the rewrites to. This PR adds finer-grained populate-patterns functions, which take a predicate lambda allowing the caller to control which math functions to apply rewrites to. Signed-off-by: Benoit Jacob <jacob.benoit.1@gmail.com>
2024-11-05[mlir][Math] Fix 0-rank support for PolynomialApproximation (#114826)Kunwar Grover
This patch disambiguates 0-rank vectors and scalars in PolynomialApproximation. This fixes a bug in PolynomialApproximation where 0-rank vectors would be treated as scalars and arguments would not be broadcasted properly.
2024-08-04[mlir] Construct SmallVector with ArrayRef (NFC) (#101896)Kazu Hirata
2024-07-31[mlir][math] Fix polynomial `math.asin` approximation (#101247)Rob Suderman
The polynomial approximation for asin is only good between [-9/16, 9/16]. Values beyond that range must be remapped to achieve good numeric results. This is done by the equation below: `arcsin(x) = PI/2 - arcsin(sqrt(1.0 - x*x))`
2024-05-07[mlir][math] Add Polynomial Approximation for acos, asin op (#90962)Prashant Kumar
Adds the Polynomial Approximation for math.acos and math.asin op. Also, it adds integration tests. The Approximation has been borrowed from https://stackoverflow.com/a/42683455 I added this script: https://gist.github.com/pashu123/cd3e682b21a64ac306f650fb842a422b to test 50 values between -1 and 1. The results are https://gist.github.com/pashu123/8acb233bd045bacabfa8c992d4040465. It's well within the bounds.
2024-03-15[mlir][math] Propagate scalability in polynomial approximation (#84949)Benjamin Maxwell
This simply updates the rewrites to propagate the scalable flags (which as they do not alter the vector shape, is pretty simple). The added tests are simply scalable versions of the existing vector tests.
2024-02-23[MLIR] Expose approximation patterns for tanh/erf. (#82750)Johannes Reifferscheid
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.
2024-01-22Apply clang-tidy fixes for readability-identifier-naming in ↵Mehdi Amini
PolynomialApproximation.cpp (NFC)
2023-06-24[mlir][polyapprox] Use llvm::numbers for constants.Jacques Pienaar
Fixes windows build.
2023-06-23[mlir][math] Improved math.atan approximationRobert Suderman
Used the cephes numerical approximation for `math.atan`. This is a significant accuracy improvement over the previous taylor series approximation. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D153656
2023-06-23[mlir][math] Modified the 'math.exp' lowering for higher precisionRobert Suderman
The existing lowering has lower precision for certain use cases, e.g. tanh. Improved version should demonstrate an overall higher level of precision. Reviewed By: cota, jpienaar Differential Revision: https://reviews.llvm.org/D153592
2023-05-12[mlir] Move casting calls from methods to function callsTres Popp
The MLIR classes Type/Attribute/Operation/Op/Value support cast/dyn_cast/isa/dyn_cast_or_null functionality through llvm's doCast functionality in addition to defining methods with the same name. This change begins the migration of uses of the method to the corresponding function call as has been decided as more consistent. Note that there still exist classes that only define methods directly, such as AffineExpr, and this does not include work currently to support a functional cast/isa call. Caveats include: - This clang-tidy script probably has more problems. - This only touches C++ code, so nothing that is being generated. Context: - https://mlir.llvm.org/deprecation/ at "Use the free function variants for dyn_cast/cast/isa/…" - Original discussion at https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443 Implementation: This first patch was created with the following steps. The intention is to only do automated changes at first, so I waste less time if it's reverted, and so the first mass change is more clear as an example to other teams that will need to follow similar steps. Steps are described per line, as comments are removed by git: 0. Retrieve the change from the following to build clang-tidy with an additional check: https://github.com/llvm/llvm-project/compare/main...tpopp:llvm-project:tidy-cast-check 1. Build clang-tidy 2. Run clang-tidy over your entire codebase while disabling all checks and enabling the one relevant one. Run on all header files also. 3. Delete .inc files that were also modified, so the next build rebuilds them to a pure state. 4. Some changes have been deleted for the following reasons: - Some files had a variable also named cast - Some files had not included a header file that defines the cast functions - Some files are definitions of the classes that have the casting methods, so the code still refers to the method instead of the function without adding a prefix or removing the method declaration at the same time. ``` ninja -C $BUILD_DIR clang-tidy run-clang-tidy -clang-tidy-binary=$BUILD_DIR/bin/clang-tidy -checks='-*,misc-cast-functions'\ -header-filter=mlir/ mlir/* -fix rm -rf $BUILD_DIR/tools/mlir/**/*.inc git restore mlir/lib/IR mlir/lib/Dialect/DLTI/DLTI.cpp\ mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp\ mlir/lib/**/IR/\ mlir/lib/Dialect/SparseTensor/Transforms/SparseVectorization.cpp\ mlir/lib/Dialect/Vector/Transforms/LowerVectorMultiReduction.cpp\ mlir/test/lib/Dialect/Test/TestTypes.cpp\ mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.cpp\ mlir/test/lib/Dialect/Test/TestAttributes.cpp\ mlir/unittests/TableGen/EnumsGenTest.cpp\ mlir/test/python/lib/PythonTestCAPI.cpp\ mlir/include/mlir/IR/ ``` Differential Revision: https://reviews.llvm.org/D150123
2023-04-20[mlir] Prevent implicit downcasting to interfacesRahul Kayaith
Currently conversions to interfaces may happen implicitly (e.g. `Attribute -> TypedAttr`), failing a runtime assert if the interface isn't actually implemented. This change marks the `Interface(ValueT)` constructor as explicit so that a cast is required. Where it was straightforward to I adjusted code to not require casts, otherwise I just made them explicit. Depends on D148491, D148492 Reviewed By: rriddle Differential Revision: https://reviews.llvm.org/D148493
2023-03-27[mlir] Add support for non-f32 polynomial approximationRobert Suderman
Polynomial approximations assume F32 values. We can convert all non-f32 cases to operate on f32s with intermediate casts. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D146677
2023-03-14[mlir][DialectUtils] Cleanup IndexingUtils and provide more affine variants ↵Nicolas Vasilache
while reusing implementations Differential Revision: https://reviews.llvm.org/D145784
2023-03-06[mlir][math] Add math.cbrt polynomial approximationRobert Suderman
Cbrt can be approximated with some relatively simple polynomial operators. This includes a lit test validating the implementation and some run tests that validate numerical correct. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D145019
2023-01-10Move from llvm::makeArrayRef to ArrayRef deduction guides - last partserge-sans-paille
This is a follow-up to https://reviews.llvm.org/D140896, split into several parts as it touches a lot of files. Differential Revision: https://reviews.llvm.org/D141298
2022-11-22[NFC][mlir] VectorUtils / IndexingUtils simplifications and cleanupsNicolas Vasilache
This revision refactors and cleans up a bunch of infra related to vector, shapes and indexing into more reusable APIs. Differential Revision: https://reviews.llvm.org/D138501
2022-10-15[mlir] Fix warningsKazu Hirata
This patch fixes: mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp:171:30: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses] mlir/lib/Dialect/Math/Transforms/PolynomialApproximation.cpp:283:30: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
2022-10-14Add f16 type support in math.erf op.Prashant Kumar
f16 type support was missing in the math.erf op. Reviewed By: ezhulenev Differential Revision: https://reviews.llvm.org/D135770
2022-09-29[mlir][arith] Change dialect name from Arithmetic to ArithJakub Kuderski
Suggested by @lattner in https://discourse.llvm.org/t/rfc-define-precise-arith-semantics/65507/22. Tested with: `ninja check-mlir check-mlir-integration check-mlir-mlir-spirv-cpu-runner check-mlir-mlir-vulkan-runner check-mlir-examples` and `bazel build --config=generic_clang @llvm-project//mlir:all`. Reviewed By: lattner, Mogball, rriddle, jpienaar, mehdi_amini Differential Revision: https://reviews.llvm.org/D134762
2022-08-08[mlir][math] Rename math.abs -> math.absfJeff Niu
To make room for introducing `math.absi`. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D131325
2022-02-18[mlir] Propagate NaNs in PolynomialApproximationTres Popp
Previously, NaNs would be dropped in favor of bounded values which was strictly incorrect. Now the min/max operation propagate this information. Not all uses of min/max need this, but the given change will help protect future additions, and this prevents the need for an additional cmpf and select operation to handle NaNs. Differential Revision: https://reviews.llvm.org/D120020
2022-02-15[mlir][Math] Fix NaN handling in Exp approximationAdrian Kuegel
Differential Revision: https://reviews.llvm.org/D119832
2022-02-15[mlir][Math] Fix NaN handling in ExpM1 approximation.Adrian Kuegel
Differential Revision: https://reviews.llvm.org/D119822
2022-02-08[mlir][math] Expand coverage of atan2 expansionJacques Pienaar
Reuse the higher precision F32 approximation for the F16 one (by expanding and truncating). This is partly RFC as I'm not sure what the expectations are here (e.g., these are only for F32 and should not be expanded, that reusing higher-precision ones for lower precision is undesirable due to increased compute cost and only approximations per exact type is preferred, or this is appropriate [at least as fallback] but we need to see how to make it more generic across all the patterns here). Differential Revision: https://reviews.llvm.org/D118968
2022-02-07[mlir][NFC] Remove a few op builders that simply swap parameter orderRiver Riddle
Differential Revision: https://reviews.llvm.org/D119093
2022-02-02[mlir:Standard] Remove support for creating a `unit` ConstantOpRiver Riddle
This is completely unused upstream, and does not really have well defined semantics on what this is supposed to do/how this fits into the ecosystem. Given that, as part of splitting up the standard dialect it's best to just remove this behavior, instead of try to awkwardly fit it somewhere upstream. Downstream users are encouraged to define their own operations that clearly can define the semantics of this. This also uncovered several lingering uses of ConstantOp that weren't updated to use arith::ConstantOp, and worked during conversions because the constant was removed/converted into something else before verification. See https://llvm.discourse.group/t/standard-dialect-the-final-chapter/ for more discussion. Differential Revision: https://reviews.llvm.org/D118654
2022-02-02[mlir] Move SelectOp from Standard to ArithmeticRiver Riddle
This is part of splitting up the standard dialect. See https://llvm.discourse.group/t/standard-dialect-the-final-chapter/ for discussion. Differential Revision: https://reviews.llvm.org/D118648
2022-01-31[mlir][vector][NFC] Split into IR, Transforms and UtilsMatthias Springer
This reduces the dependencies of the MLIRVector target and makes the dialect consistent with other dialects. Differential Revision: https://reviews.llvm.org/D118533
2022-01-30[mlir] Silence warnings when building with MSVCAlexandre Ganea
Differential Revision: https://reviews.llvm.org/D118536
2022-01-30Apply clang-tidy fixes for readability-identifier-naming in ↵Mehdi Amini
PolynomialApproximation.cpp (NFC)
2022-01-21[mlir] Add polynomial approximation for atan and atan2Rob Suderman
Implement a taylor series approximation for atan and add an atan2 lowering that uses atan's appromation. This includes tests for edge cases and tests for each quadrant. Reviewed By: NatashaKnk Differential Revision: https://reviews.llvm.org/D115682
2022-01-02Apply clang-tidy fixes for performance-unnecessary-value-param to MLIR (NFC)Mehdi Amini
Reviewed By: Mogball Differential Revision: https://reviews.llvm.org/D116250
2022-01-02Apply clang-tidy fixes for performance-for-range-copy to MLIR (NFC)Mehdi Amini
Differential Revision: https://reviews.llvm.org/D116248
2022-01-02Apply clang-tidy fixes for bugprone-argument-comment to MLIR (NFC)Mehdi Amini
Differential Revision: https://reviews.llvm.org/D116244
2021-12-20Fix clang-tidy issues in mlir/ (NFC)Mehdi Amini
Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D115956
2021-11-30[mlir] Update accessors prefixed form (NFC)Jacques Pienaar
2021-11-30[mlir] Move bufferization-related passes to `bufferization` dialect.Alexander Belyaev
[RFC](https://llvm.discourse.group/t/rfc-dialect-for-bufferization-related-ops/4712) Differential Revision: https://reviews.llvm.org/D114698
2021-10-29[mlir] MathApproximations: scalars shape must be 0-rankEugene Zhulenev
Using [1] for representing shape of a scalar is incorrect, and will break with vectors of size 1. - remove redundant helper functions - fix couple of style warnings Reviewed By: cota Differential Revision: https://reviews.llvm.org/D112764
2021-10-28[mlir] MathApproximations: unroll virtual vectors into hardware vectors for ↵Eugene Zhulenev
ISA specific operation Reviewed By: cota Differential Revision: https://reviews.llvm.org/D112736
2021-10-26[mlir] Use float literals to make Windows build happy.Alexander Belyaev
2021-10-26[mlir] Update Erf approximation.Alexander Belyaev
2021-10-26[mlir] Allow polynomial approximations for N-d vectors.Alexander Belyaev
Polynomial approximation can be extented to support N-d vectors. N-dimensional vectors are useful when vectorizing operations on N-dimensional tiles. Before lowering to LLVM these vectors are usually unrolled or flattened to 1-dimensional vectors. Differential Revision: https://reviews.llvm.org/D112566
2021-10-25[MLIR][Math] Add erf to math dialectBoian Petkantchin
Add math.erf lowering to libm call. Add math.erf polynomial approximation. Reviewed By: silvas, ezhulenev Differential Revision: https://reviews.llvm.org/D112200