From 562adaea1e2e8508ba00c30e58ce4f8bb128a1b0 Mon Sep 17 00:00:00 2001 From: Alexandre Eichenberger Date: Fri, 30 Sep 2022 14:34:36 -0400 Subject: [PATCH] Warning and instructions that --onnx-op-stats needs more than EmitONNXIR (#1719) Signed-off-by: Alexandre Eichenberger Co-authored-by: chentong319 --- src/Compiler/CompilerOptions.cpp | 6 ++++-- src/Compiler/CompilerPasses.cpp | 2 +- src/onnx-mlir.cpp | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Compiler/CompilerOptions.cpp b/src/Compiler/CompilerOptions.cpp index 352d3c6e09..2203be40c3 100644 --- a/src/Compiler/CompilerOptions.cpp +++ b/src/Compiler/CompilerOptions.cpp @@ -160,8 +160,10 @@ llvm::cl::opt instrumentONNXSignature("instrument-onnx-signature", llvm::cl::opt ONNXOpStats("onnx-op-stats", llvm::cl::desc( "Report the occurrence frequency of ONNX ops in JSON or TXT format:\n" - "\"TXT\" for report as text, \n" - "\"JSON\" for report as JSON."), + "\"TXT\" for report as text,\n" + "\"JSON\" for report as JSON.\n" + "Requires targets like --EmitMLIR, --EmitLLVMIR, or binary-generating " + "commands."), llvm::cl::init(""), llvm::cl::cat(OnnxMlirOptions)); llvm::cl::opt enableMemoryBundling("enable-memory-bundling", diff --git a/src/Compiler/CompilerPasses.cpp b/src/Compiler/CompilerPasses.cpp index bd186978ad..532a931dd2 100644 --- a/src/Compiler/CompilerPasses.cpp +++ b/src/Compiler/CompilerPasses.cpp @@ -104,7 +104,7 @@ void addONNXToKrnlPasses(mlir::PassManager &pm, int optLevel, bool enableCSE, // TODO: we should write the output of this pass in a file but I was not // able to use raw_fd_ostream of a file without it crashing. pm.addNestedPass( - mlir::createPrintOpStatsPass(llvm::errs(), printAsJSON)); + mlir::createPrintOpStatsPass(llvm::outs(), printAsJSON)); } else { llvm::errs() << "Skip onnx-ops-stats: expected JSON or TXT format, got \"" << ONNXOpsStatFormat << "\"\n"; diff --git a/src/onnx-mlir.cpp b/src/onnx-mlir.cpp index 59032b81bc..7906d50e44 100644 --- a/src/onnx-mlir.cpp +++ b/src/onnx-mlir.cpp @@ -66,6 +66,11 @@ int main(int argc, char *argv[]) { llvm::errs() << "Failed to parse options\n"; return 1; } + // Test option requirements. + if (!ONNXOpStats.empty() && emissionTarget <= EmitONNXIR) + llvm::errs() + << "Warning: --onnx-op-stats requires targets like --EmitMLIR, " + "--EmitLLVMIR, or binary-generating emit commands.\n"; mlir::OwningOpRef module; std::string errorMessage;