Skip to content

Commit 3fc814b

Browse files
committed
feat(tosa): sink tosa ops through tosa.concat
1 parent 687b78d commit 3fc814b

File tree

5 files changed

+1446
-0
lines changed

5 files changed

+1446
-0
lines changed

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

Lines changed: 4 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,8 @@ 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> createSinkInputOpsThroughConcatPass(llvm::raw_ostream &);
50+
std::unique_ptr<Pass> createSinkInputOpsThroughConcatPass();
4751
std::unique_ptr<Pass> createTosaTestQuantUtilAPIPass();
4852
std::unique_ptr<Pass> createTosaOptionalDecompositions();
4953

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

Lines changed: 21 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
//===----------------------------------------------------------------------===//
89
//
@@ -142,4 +143,24 @@ def TosaReduceTransposes : Pass<"tosa-reduce-transposes", "func::FuncOp"> {
142143
}];
143144
}
144145

146+
def SinkInputOpsThroughConcat : Pass<"sink-input-ops-through-concat", "mlir::ModuleOp"> {
147+
let summary = "Sinks same operation through a Concat operation";
148+
let description = [{
149+
Pass that sinks the same operation through a concatenation, simplifying
150+
later optimizations.
151+
152+
To explain with a picture:
153+
```
154+
Replacing with
155+
- Op -\ -\
156+
- Op ---> Concat ==> ---> Concat -> Op
157+
- Op -/ -/
158+
```
159+
160+
The pass works greedy (i.e., it sinks operator chains) and does not do any
161+
cost-benefit assessment. It it restricted to an explicit list of tosa
162+
operations as input for the concatentation that are known to be "sinkable".
163+
}];
164+
}
165+
145166
#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)