Skip to content

Commit

Permalink
Add onnx-mlir option to debug small optimizations (#2895)
Browse files Browse the repository at this point in the history
> Use this to check optimizations
> CheckONNXModel.py -m model.mlir -r "-O3 -mcpu=z16 -maccel=NNPA" -a "-test-compiler-opt"

Signed-off-by: Alexandre Eichenberger <[email protected]>
Co-authored-by: Tung D. Le <[email protected]>
  • Loading branch information
AlexandreEichenberger and tungld authored Aug 2, 2024
1 parent 36aa0ba commit 225c8c4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Compiler/CompilerOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,25 @@ static llvm::cl::opt<bool, true> enable_bound_check("enable-bound-check",
llvm::cl::location(enableBoundCheck), llvm::cl::init(false),
llvm::cl::cat(OnnxMlirOptions));

#if defined(_DEBUG)
// Option only available in debug mode: set using command options.
static llvm::cl::opt<bool, true> test_compiler_opt("test-compiler-opt",
llvm::cl::desc(
"Help compiler writers test a new (small) optimization. When false, "
"the old approach should be used. When true, the new opt should be "
"used. Utilities such as CheckONNXModel.py can then verify that the "
"new opt deliver the same results.\n"
"E.g. CheckONNXModel.py -m test.mlir -t -O3 -a test-compiler-opt=true\n"
"Once the new opt works, it should not rely this option any more.\n"
"Only defined in DEBUG build and default to false.\n"),
llvm::cl::location(debugTestCompilerOpt), llvm::cl::init(false),
llvm::cl::cat(OnnxMlirOptions));
bool debugTestCompilerOpt;
#else
// Option only available in debug mode: disable when not in debug.
bool debugTestCompilerOpt = false;
#endif

// Options for onnx-mlir-opt only
static llvm::cl::opt<bool, true> split_input_file_opt("split-input-file",
llvm::cl::desc("Split the input file into pieces and process each "
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/CompilerOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ extern OptReport optReport; // onnx-mlir only
extern bool useOldBufferization; // onnx-mlir only
extern bool enableTiming; // onnx-mlir only
extern bool enableBoundCheck; // onnx-mlir only
extern bool debugTestCompilerOpt; // onnx-mlir only

extern bool split_input_file; // onnx-mlir-opt only
extern bool verify_diagnostics; // onnx-mlir-opt only
extern bool verify_passes; // onnx-mlir-opt only
Expand Down

0 comments on commit 225c8c4

Please sign in to comment.