[mlir][tosa] Constant folding for reciprocal
authorTina Jung <tina.maria.jung@xilinx.com>
Wed, 5 Jul 2023 07:37:47 +0000 (08:37 +0100)
committerMatthias Gehre <matthias.gehre@xilinx.com>
Wed, 5 Jul 2023 09:38:46 +0000 (11:38 +0200)
commitd84d418e2adc421c98e484ab3b09e2f4f3e5c1ef
tree18c5fe0c90cdb3b6ab7beb77b3555f4aa5260b39
parent2e903709de003dc6ae980197f4a0850a158dd9b8
[mlir][tosa] Constant folding for reciprocal

Add constant fold for tosa.reciprocal, which can be applied if the input is a dense constant tensor. The reciprocal is computed for every element and the result is a tensor with the same dimensions as the input tensor.

As the input tensor might require a lot of memory and the folding might double the required memory, a heuristic decides when to actually apply the folding. Currently, the operation will be replaced only if the input constant is a splat (i.e. requires little memory) or has in single user (similar to the already existing fold for constant transposes). This keeps the additionally required space low.

Differential Revision: https://reviews.llvm.org/D150578
mlir/include/mlir/Dialect/Tosa/Transforms/Passes.h
mlir/lib/Dialect/Tosa/Transforms/CMakeLists.txt
mlir/lib/Dialect/Tosa/Transforms/TosaFoldConstantTranspose.cpp [deleted file]
mlir/lib/Dialect/Tosa/Transforms/TosaFolders.cpp [new file with mode: 0644]
mlir/lib/Dialect/Tosa/Transforms/TosaLayerwiseConstantFoldPass.cpp
mlir/test/Dialect/Tosa/constant-reciprocal-fold.mlir [new file with mode: 0644]