Skip to content

Commit 2afbdad

Browse files
authored
feat(tosa): sink tosa ops through tosa.concat (#671)
2 parents fe67dea + 62a23c4 commit 2afbdad

5 files changed

Lines changed: 1597 additions & 0 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
// Modifications (c) Copyright 2025 Advanced Micro Devices, Inc. or its
7+
// affiliates
68
//
79
//===----------------------------------------------------------------------===//
810
//
@@ -44,6 +46,9 @@ std::unique_ptr<Pass> createTosaLayerwiseConstantFoldPass(
4446
const TosaLayerwiseConstantFoldPassOptions &options);
4547
std::unique_ptr<Pass> createTosaInferShapesPass();
4648
std::unique_ptr<Pass> createTosaMakeBroadcastablePass();
49+
std::unique_ptr<Pass>
50+
createSinkInputOpsThroughConcatPass(SinkInputOpsThroughConcatOptions &,
51+
llvm::raw_ostream &);
4752
std::unique_ptr<Pass> createTosaTestQuantUtilAPIPass();
4853
std::unique_ptr<Pass> createTosaOptionalDecompositions();
4954

mlir/include/mlir/Dialect/Tosa/Transforms/Passes.td

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
// Modifications (c) Copyright 2025 Advanced Micro Devices, Inc. or its affiliates
67
//
78
// Modifications (c) Copyright 2023-2025 Advanced Micro Devices, Inc. or its
89
// affiliates
@@ -148,4 +149,41 @@ def TosaReduceTransposes : Pass<"tosa-reduce-transposes", "func::FuncOp"> {
148149
}];
149150
}
150151

152+
def SinkInputOpsThroughConcat : Pass<"sink-input-ops-through-concat", "mlir::ModuleOp"> {
153+
let summary = "Sinks same operation through a Concat operation";
154+
let description = [{
155+
Pass that sinks the same operation through a concatenation, simplifying
156+
later optimizations.
157+
158+
To explain with a picture:
159+
```
160+
Replacing with
161+
- Op -\ -\
162+
- Op ---> Concat ==> ---> Concat -> Op
163+
- Op -/ -/
164+
```
165+
166+
The pass works greedy (i.e., it sinks operator chains) and does not do any
167+
cost-benefit assessment. It it restricted to an explicit list of tosa
168+
operations as input for the concatentation that are known to be "sinkable".
169+
}];
170+
let options = [
171+
Option<"enableElementwises", "enable-elementwises", "bool",
172+
/*default=*/"true",
173+
"Sink down elementwise operations.">,
174+
Option<"enableReductions", "enable-reductions", "bool",
175+
/*default=*/"true",
176+
"Sink down reduce operations.">,
177+
Option<"enableReshape", "enable-reshape", "bool",
178+
/*default=*/"true",
179+
"Sink down the reshape operation.">,
180+
Option<"enableMatmul", "enable-matmul", "bool",
181+
/*default=*/"true",
182+
"Sink down the matrix multiplication.">,
183+
Option<"matchUntransformedOperations", "match-untransformed-operations", "bool",
184+
/*default=*/"false",
185+
"Print operations that have potential to be sunken but are not actually sunken down.">,
186+
];
187+
}
188+
151189
#endif // MLIR_DIALECT_TOSA_TRANSFORMS_PASSES

mlir/lib/Dialect/Tosa/Transforms/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Modifications (c) Copyright 2025 Advanced Micro Devices, Inc. or its affiliates
2+
13
add_mlir_dialect_library(MLIRTosaTransforms
24
TosaDecomposeTransposeConv.cpp
35
TosaDecomposeDepthwise.cpp
@@ -9,6 +11,7 @@ add_mlir_dialect_library(MLIRTosaTransforms
911
TosaReduceTransposes.cpp
1012
TosaTypeConverters.cpp
1113
TosaValidation.cpp
14+
SinkInputOpsThroughConcat.cpp
1215

1316
ADDITIONAL_HEADER_DIRS
1417
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/Tosa/Transforms

0 commit comments

Comments
 (0)