llvm-project/mlir
Sean Silva 53a0d45db6 [mlir] Add pass to convert elementwise ops to linalg.
This patch converts elementwise ops on tensors to linalg.generic ops
with the same elementwise op in the payload (except rewritten to
operate on scalars, obviously). This is a great form for later fusion to
clean up.

E.g.

```
// Compute: %arg0 + %arg1 - %arg2
func @f(%arg0: tensor<?xf32>, %arg1: tensor<?xf32>, %arg2: tensor<?xf32>) -> tensor<?xf32> {
  %0 = addf %arg0, %arg1 : tensor<?xf32>
  %1 = subf %0, %arg2 : tensor<?xf32>
  return %1 : tensor<?xf32>
}
```

Running this through
`mlir-opt -convert-std-to-linalg -linalg-fusion-for-tensor-ops` we get:

```
func @f(%arg0: tensor<?xf32>, %arg1: tensor<?xf32>, %arg2: tensor<?xf32>) -> tensor<?xf32> {
  %0 = linalg.generic {indexing_maps = [#map0, #map0, #map0, #map0], iterator_types = ["parallel"]} ins(%arg0, %arg1, %arg2 : tensor<?xf32>, tensor<?xf32>, tensor<?xf32>) {
  ^bb0(%arg3: f32, %arg4: f32, %arg5: f32):  // no predecessors
    %1 = addf %arg3, %arg4 : f32
    %2 = subf %1, %arg5 : f32
    linalg.yield %2 : f32
  } -> tensor<?xf32>
  return %0 : tensor<?xf32>
}
```

So the elementwise ops on tensors have nicely collapsed into a single
linalg.generic, which is the form we want for further transformations.

Differential Revision: https://reviews.llvm.org/D90354
2020-11-10 13:44:44 -08:00
..
cmake/modules [mlir] Refactor finding python 2020-11-10 21:21:40 +01:00
docs [mlir] Add ElementwiseMappable trait and apply it to std elementwise ops. 2020-11-10 13:44:44 -08:00
examples [MLIR] Add setPublic(), setPrivate(), and setNested() to Symbol interface 2020-11-09 13:56:38 -08:00
include [mlir] Add pass to convert elementwise ops to linalg. 2020-11-10 13:44:44 -08:00
integration_test [mlir] Add pass to convert elementwise ops to linalg. 2020-11-10 13:44:44 -08:00
lib [mlir] Add pass to convert elementwise ops to linalg. 2020-11-10 13:44:44 -08:00
test [mlir] Add pass to convert elementwise ops to linalg. 2020-11-10 13:44:44 -08:00
tools Add basic Python bindings for the PassManager and bind libTransforms 2020-11-10 19:55:21 +00:00
unittests [mlir] Fix missing namespaces in OpBuildGen.cpp 2020-11-05 18:11:01 +01:00
utils
.clang-format
.clang-tidy
CMakeLists.txt [mlir] Refactor finding python 2020-11-10 21:21:40 +01:00
LICENSE.TXT
README.md

README.md

Multi-Level Intermediate Representation

See https://mlir.llvm.org/ for more information.