Skip to content

Commit bc893dd

Browse files
authored
Add an option to disable op fusion in ONNXToKrnl pass (#2807)
* parallel for Signed-off-by: Chen Tong <[email protected]> * run through Signed-off-by: Tong Chen <[email protected]> * flag Signed-off-by: Tong Chen <[email protected]> * format Signed-off-by: chentong319 <[email protected]> * Revert "format" This reverts commit ebd27e2. * Revert "flag" This reverts commit 432e4be. * fix merge error Signed-off-by: chentong319 <[email protected]> * add function Signed-off-by: chentong319 <[email protected]> * format Signed-off-by: chentong319 <[email protected]> * cmake Signed-off-by: chentong319 <[email protected]> --------- Signed-off-by: Chen Tong <[email protected]> Signed-off-by: Tong Chen <[email protected]> Signed-off-by: Tong Chen <[email protected]> Signed-off-by: chentong319 <[email protected]>
1 parent 060b370 commit bc893dd

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

src/Compiler/CompilerOptions.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ std::vector<std::string> onnxConstPropDisablePatterns; // common for both
4141
bool enableONNXHybridPass; // common for both
4242
std::vector<std::string> functionsToDecompose; // common for both
4343
std::string opsForCall; // common for both
44+
bool disableKrnlOpFusion; // common for both
4445
EmissionTargetType emissionTarget; // onnx-mlir only
4546
bool invokeOnnxVersionConverter; // onnx-mlir only
4647
bool preserveLocations; // onnx-mlir only
@@ -201,6 +202,13 @@ static llvm::cl::list<std::string, std::vector<std::string>>
201202
llvm::cl::location(functionsToDecompose),
202203
llvm::cl::cat(OnnxMlirCommonOptions));
203204

205+
static llvm::cl::opt<bool, true> disableKrnlOpFusionOpt(
206+
"disable-krnl-op-fusion",
207+
llvm::cl::desc("disable op fusion in onnx-to-krnl pass (default=false)\n"
208+
"Set to 'true' if you want to disable fusion."),
209+
llvm::cl::location(disableKrnlOpFusion), llvm::cl::init(false),
210+
llvm::cl::cat(OnnxMlirCommonOptions));
211+
204212
static llvm::cl::opt<bool, true> disableRecomposeOptionOpt("disable-recompose",
205213
llvm::cl::desc("Disable recomposition of ONNX operations."),
206214
llvm::cl::location(disableRecomposeOption), llvm::cl::init(false),

src/Compiler/CompilerOptions.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ extern std::vector<std::string> onnxConstPropDisablePatterns; // common for both
8484
extern bool enableONNXHybridPass; // common for both
8585
extern std::vector<std::string> functionsToDecompose; // common for both
8686
extern std::string opsForCall; // common for both
87+
extern bool disableKrnlOpFusion; // common for both
8788
extern EmissionTargetType emissionTarget; // onnx-mlir only
8889
extern bool invokeOnnxVersionConverter; // onnx-mlir only
8990
extern bool preserveLocations; // onnx-mlir only

src/Conversion/ONNXToKrnl/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ add_onnx_mlir_library(OMONNXToKrnl
8080

8181
LINK_LIBS PUBLIC
8282
OMAccelerator
83+
OMCompilerOptions
8384
OMONNXConversionCommon
8485
OMONNXOps
8586
OMSupport

src/Conversion/ONNXToKrnl/Math/Elementwise.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "llvm/Support/Debug.h"
1919

20+
#include "src/Compiler/CompilerOptions.hpp"
2021
#include "src/Conversion/ONNXToKrnl/ONNXToKrnlCommon.hpp"
2122
#include "src/Dialect/Krnl/DialectBuilder.hpp"
2223
#include "src/Dialect/ONNX/ONNXOps/ShapeHelper.hpp"
@@ -1884,6 +1885,9 @@ bool OpFusionHelper::areInputsValidForFusion(
18841885
// A successor op (user) is fusible if it is the only user, it is in the
18851886
// fusible elementwise op list, and its inputs are valid for fusion.
18861887
void OpFusionHelper::findFusibleOps() {
1888+
// Direct return if fusion is disabled
1889+
if (disableKrnlOpFusion)
1890+
return;
18871891
Operation *defOp = rootOp;
18881892
while (defOp->hasOneUse()) {
18891893
// the possible ONNX Ops.

0 commit comments

Comments
 (0)