From a3be22b4dda7dcb0a3fb8a6174adad3a63689b15 Mon Sep 17 00:00:00 2001 From: Alexandre Eichenberger Date: Wed, 13 Aug 2025 15:25:13 -0400 Subject: [PATCH 1/5] disable profiling of constant by default, but enable it with -profile-all-ops option (default off) Signed-off-by: Alexandre Eichenberger --- .../NNPA/Compiler/NNPACompilerUtils.cpp | 8 ++++---- src/Compiler/CompilerOptions.cpp | 10 ++++++++++ src/Compiler/CompilerOptions.hpp | 1 + src/Compiler/CompilerPasses.cpp | 12 ++++++++---- .../Transforms/InstrumentONNXSignaturePass.cpp | 17 ++++++++++++----- src/Pass/Passes.hpp | 5 +++-- src/Tools/onnx-mlir-opt/RegisterPasses.cpp | 2 +- src/Transform/InstrumentPass.cpp | 15 +++++++++++---- 8 files changed, 50 insertions(+), 20 deletions(-) diff --git a/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp b/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp index 07e38a57da..b202eb465d 100644 --- a/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp +++ b/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp @@ -198,10 +198,10 @@ void addONNXToZHighPasses(mlir::PassManager &pm) { // not to include timing of the signature printing. if (hasSignatureInstrumentation(onnx_mlir::InstrumentStages::ZHigh)) pm.addNestedPass(onnx_mlir::createInstrumentONNXSignaturePass( - instrumentSignatures, instrumentOnnxNode)); + instrumentSignatures, instrumentOnnxNode, !profileAllOps)); if (hasInstrumentation(onnx_mlir::InstrumentStages::ZHigh)) - pm.addNestedPass( - onnx_mlir::createInstrumentPass(instrumentOps, instrumentActions)); + pm.addNestedPass(onnx_mlir::createInstrumentPass( + instrumentOps, instrumentActions, !profileAllOps)); } void normalizeMemRefsPasses(mlir::PassManager &pm) { @@ -298,7 +298,7 @@ void addPassesNNPA(mlir::OwningOpRef &module, "stage is currently unsupported"); if (hasInstrumentation(onnx_mlir::InstrumentStages::ZLow)) pm.addNestedPass(onnx_mlir::createInstrumentPass( - instrumentOps, instrumentControlBits)); + instrumentOps, instrumentControlBits, !profileAllOps)); } } diff --git a/src/Compiler/CompilerOptions.cpp b/src/Compiler/CompilerOptions.cpp index 6a92557749..d8d77f9afc 100644 --- a/src/Compiler/CompilerOptions.cpp +++ b/src/Compiler/CompilerOptions.cpp @@ -93,6 +93,7 @@ bool disableConstantProp; // onnx-mlir only std::vector extraLibPaths; // onnx-mlir only std::vector extraLibs; // onnx-mlir only ProfileIRs profileIR; // onnx-mlir only +bool profileAllOps; // onnx-mlir only OptReport optReport; // onnx-mlir only bool enableTiming; // onnx-mlir only bool enableBoundCheck; // onnx-mlir only @@ -700,6 +701,15 @@ static llvm::cl::opt profileIROpt("profile-ir", APPLY_TO_ACCELERATORS(ACCEL_PROFILEIR_CL_ENUM)), llvm::cl::init(ProfileIRs::None), llvm::cl::cat(OnnxMlirOptions)); +static llvm::cl::opt profileAllOpsOpt("profile-all-ops", + llvm::cl::desc( + "Normally we prune/disable generating profiling information for\n" + "constant-generating operations as well as operations that are\n" + "optimized away.\nUse this option to force profiling for all ops" + " (default is false)."), + llvm::cl::location(profileAllOps), llvm::cl::init(false), + llvm::cl::cat(OnnxMlirOptions)); + static llvm::cl::opt optReportOpt("opt-report", llvm::cl::desc("Provide information on a specific compiler optimization:"), llvm::cl::location(optReport), diff --git a/src/Compiler/CompilerOptions.hpp b/src/Compiler/CompilerOptions.hpp index 294839eb62..762bedbc99 100644 --- a/src/Compiler/CompilerOptions.hpp +++ b/src/Compiler/CompilerOptions.hpp @@ -138,6 +138,7 @@ extern bool disableConstantProp; // onnx-mlir only extern std::vector extraLibPaths; // onnx-mlir only extern std::vector extraLibs; // onnx-mlir only extern ProfileIRs profileIR; // onnx-mlir only +extern bool profileAllOps; // onnx-mlir only extern OptReport optReport; // onnx-mlir only extern bool enableTiming; // onnx-mlir only extern bool enableBoundCheck; // onnx-mlir only diff --git a/src/Compiler/CompilerPasses.cpp b/src/Compiler/CompilerPasses.cpp index c975ce31f6..0328face7c 100644 --- a/src/Compiler/CompilerPasses.cpp +++ b/src/Compiler/CompilerPasses.cpp @@ -167,15 +167,19 @@ void addONNXToMLIRPasses(mlir::PassManager &pm, bool targetCPU, instrumentActions |= (1 << 3) - 1; // Also enable instrumentation of signatures. instrumentSignatures = "onnx.*"; + if (profileAllOps) { + instrumentOps += ",krnl.global"; + instrumentSignatures += ",krnl.global"; + } } // Add createInstrument (timing) second so that it will guarantee not to // include timing of the signature printing. if (hasSignatureInstrumentation(onnx_mlir::InstrumentStages::Onnx)) pm.addNestedPass(onnx_mlir::createInstrumentONNXSignaturePass( - instrumentSignatures, instrumentOnnxNode)); + instrumentSignatures, instrumentOnnxNode, !profileAllOps)); if (hasInstrumentation(onnx_mlir::InstrumentStages::Onnx)) - pm.addNestedPass( - onnx_mlir::createInstrumentPass(instrumentOps, instrumentActions)); + pm.addNestedPass(onnx_mlir::createInstrumentPass( + instrumentOps, instrumentActions, !profileAllOps)); } void addONNXToKrnlPasses(mlir::PassManager &pm, int optLevel, bool enableCSE, @@ -276,7 +280,7 @@ void addKrnlToLLVMPasses( pm.addPass(mlir::memref::createFoldMemRefAliasOpsPass()); - if (profileIR) + if (profileIR && !profileAllOps) pm.addNestedPass(onnx_mlir::createInstrumentCleanupPass()); if (enableBoundCheck) diff --git a/src/Dialect/ONNX/Transforms/InstrumentONNXSignaturePass.cpp b/src/Dialect/ONNX/Transforms/InstrumentONNXSignaturePass.cpp index 23c75be41a..d143557f44 100644 --- a/src/Dialect/ONNX/Transforms/InstrumentONNXSignaturePass.cpp +++ b/src/Dialect/ONNX/Transforms/InstrumentONNXSignaturePass.cpp @@ -52,14 +52,17 @@ class InstrumentONNXSignaturePass OperationPass>() { signaturePattern = pass.signaturePattern; nodeNamePattern = pass.nodeNamePattern; + skipConstants = pass.skipConstants; } - InstrumentONNXSignaturePass( - const std::string opPattern, const std::string nodePattern) - : signaturePattern(opPattern), nodeNamePattern(nodePattern) {} + InstrumentONNXSignaturePass(const std::string opPattern, + const std::string nodePattern, bool skipConstants) + : signaturePattern(opPattern), nodeNamePattern(nodePattern), + skipConstants(skipConstants) {} private: std::string signaturePattern; std::string nodeNamePattern; + bool skipConstants; public: StringRef getArgument() const override { @@ -113,6 +116,8 @@ class InstrumentONNXSignaturePass isa(op)) { // Always skip function dialects (such as function call/return), as well // as ONNX instrument operations. + } else if (skipConstants && (isa(op))) { + // Asked to skip constants, do nothing. } else { // If has both a print of data and print of signature, favor the // printing of data as it also will print the signature. @@ -141,6 +146,8 @@ class InstrumentONNXSignaturePass * Create an instrumentation pass. */ std::unique_ptr onnx_mlir::createInstrumentONNXSignaturePass( - const std::string pattern, const std::string nodePattern) { - return std::make_unique(pattern, nodePattern); + const std::string pattern, const std::string nodePattern, + bool skipConstants) { + return std::make_unique( + pattern, nodePattern, skipConstants); } diff --git a/src/Pass/Passes.hpp b/src/Pass/Passes.hpp index c696845b59..918aba1274 100644 --- a/src/Pass/Passes.hpp +++ b/src/Pass/Passes.hpp @@ -56,14 +56,15 @@ std::unique_ptr createConstPropONNXToONNXPass(); /// Pass for instrument the ops in specific stage. std::unique_ptr createInstrumentPass(); std::unique_ptr createInstrumentPass( - const std::string &ops, unsigned actions); + const std::string &ops, unsigned actions, bool skipConstants); /// Pass for instrument cleanup. std::unique_ptr createInstrumentCleanupPass(); /// Passes for instrumenting the ONNX ops to print their operand type /// signatures at runtime. std::unique_ptr createInstrumentONNXSignaturePass( - const std::string opPattern, const std::string nodePattern); + const std::string opPattern, const std::string nodePattern, + bool skipConstants); /// Pass for simplifying shape-related ONNX operations. std::unique_ptr createSimplifyShapeRelatedOpsPass(); diff --git a/src/Tools/onnx-mlir-opt/RegisterPasses.cpp b/src/Tools/onnx-mlir-opt/RegisterPasses.cpp index 1af70b866e..b15af4c3c0 100644 --- a/src/Tools/onnx-mlir-opt/RegisterPasses.cpp +++ b/src/Tools/onnx-mlir-opt/RegisterPasses.cpp @@ -75,7 +75,7 @@ void registerOMPasses(int optLevel) { }); mlir::registerPass([]() -> std::unique_ptr { - return createInstrumentONNXSignaturePass("NONE", "NONE"); + return createInstrumentONNXSignaturePass("NONE", "NONE", true); }); mlir::registerPass([]() -> std::unique_ptr { diff --git a/src/Transform/InstrumentPass.cpp b/src/Transform/InstrumentPass.cpp index 9ee74cbcfe..e70dc1f921 100644 --- a/src/Transform/InstrumentPass.cpp +++ b/src/Transform/InstrumentPass.cpp @@ -70,11 +70,14 @@ class InstrumentPass llvm::cl::desc("instrument runtime reports memory usage"), llvm::cl::init(false)}; + Option skipConstants{*this, "skip-constants", + llvm::cl::desc("do not instrument constant ops"), llvm::cl::init(true)}; + InstrumentPass() : allowedOps(/*emptyIsNone*/ true){}; InstrumentPass(const InstrumentPass &pass) : mlir::PassWrapper>(), allowedOps(/*emptyIsNone*/ true) {} - InstrumentPass(const std::string &ops, unsigned actions) + InstrumentPass(const std::string &ops, unsigned actions, bool skipConstants) : allowedOps(/*emptyIsNone*/ true) { this->instrumentOps = ops; unsigned long long tag = actions; @@ -82,6 +85,7 @@ class InstrumentPass this->instrumentAfter = IS_INSTRUMENT_AFTER_OP(tag); this->reportTime = IS_INSTRUMENT_REPORT_TIME(tag); this->reportMemory = IS_INSTRUMENT_REPORT_MEMORY(tag); + this->skipConstants = skipConstants; } private: @@ -144,7 +148,10 @@ class InstrumentPass if (op->getNumResults() == 1 && isa(op->getResult(0).getType())) return WalkResult::advance(); // Skip other instrument ops. - if (isa(op) || isa(op)) + if (isa(op)) + return WalkResult::advance(); + if (skipConstants && isa(op)) + // Asked to skip constants, do nothing. return WalkResult::advance(); std::string opName = op->getName().getStringRef().str(); @@ -185,6 +192,6 @@ std::unique_ptr onnx_mlir::createInstrumentPass() { } std::unique_ptr onnx_mlir::createInstrumentPass( - const std::string &ops, unsigned actions) { - return std::make_unique(ops, actions); + const std::string &ops, unsigned actions, bool skipConstants) { + return std::make_unique(ops, actions, skipConstants); } From 752166e961a592ef035a005b649b670db7841434 Mon Sep 17 00:00:00 2001 From: Alexandre Eichenberger Date: Thu, 14 Aug 2025 14:37:30 -0400 Subject: [PATCH 2/5] change option name as requested Signed-off-by: Alexandre Eichenberger --- .../NNPA/Compiler/NNPACompilerUtils.cpp | 6 +++--- src/Compiler/CompilerOptions.cpp | 14 ++++++-------- src/Compiler/CompilerOptions.hpp | 2 +- src/Compiler/CompilerPasses.cpp | 8 ++++---- src/Transform/InstrumentCleanupPass.cpp | 2 +- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp b/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp index b202eb465d..10765e02bc 100644 --- a/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp +++ b/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp @@ -198,10 +198,10 @@ void addONNXToZHighPasses(mlir::PassManager &pm) { // not to include timing of the signature printing. if (hasSignatureInstrumentation(onnx_mlir::InstrumentStages::ZHigh)) pm.addNestedPass(onnx_mlir::createInstrumentONNXSignaturePass( - instrumentSignatures, instrumentOnnxNode, !profileAllOps)); + instrumentSignatures, instrumentOnnxNode, !profileConstOps)); if (hasInstrumentation(onnx_mlir::InstrumentStages::ZHigh)) pm.addNestedPass(onnx_mlir::createInstrumentPass( - instrumentOps, instrumentActions, !profileAllOps)); + instrumentOps, instrumentActions, !profileConstOps)); } void normalizeMemRefsPasses(mlir::PassManager &pm) { @@ -298,7 +298,7 @@ void addPassesNNPA(mlir::OwningOpRef &module, "stage is currently unsupported"); if (hasInstrumentation(onnx_mlir::InstrumentStages::ZLow)) pm.addNestedPass(onnx_mlir::createInstrumentPass( - instrumentOps, instrumentControlBits, !profileAllOps)); + instrumentOps, instrumentControlBits, !profileConstOps)); } } diff --git a/src/Compiler/CompilerOptions.cpp b/src/Compiler/CompilerOptions.cpp index d8d77f9afc..f4388e1523 100644 --- a/src/Compiler/CompilerOptions.cpp +++ b/src/Compiler/CompilerOptions.cpp @@ -93,7 +93,7 @@ bool disableConstantProp; // onnx-mlir only std::vector extraLibPaths; // onnx-mlir only std::vector extraLibs; // onnx-mlir only ProfileIRs profileIR; // onnx-mlir only -bool profileAllOps; // onnx-mlir only +bool profileConstOps; // onnx-mlir only OptReport optReport; // onnx-mlir only bool enableTiming; // onnx-mlir only bool enableBoundCheck; // onnx-mlir only @@ -701,13 +701,11 @@ static llvm::cl::opt profileIROpt("profile-ir", APPLY_TO_ACCELERATORS(ACCEL_PROFILEIR_CL_ENUM)), llvm::cl::init(ProfileIRs::None), llvm::cl::cat(OnnxMlirOptions)); -static llvm::cl::opt profileAllOpsOpt("profile-all-ops", - llvm::cl::desc( - "Normally we prune/disable generating profiling information for\n" - "constant-generating operations as well as operations that are\n" - "optimized away.\nUse this option to force profiling for all ops" - " (default is false)."), - llvm::cl::location(profileAllOps), llvm::cl::init(false), +static llvm::cl::opt profileConstOpOpt("profile-constant-ops", + llvm::cl::desc("Normally we disable generating profiling information for\n" + "constant-generating operations.\nUse this option to force" + " profiling for all ops (default is false)."), + llvm::cl::location(profileConstOps), llvm::cl::init(false), llvm::cl::cat(OnnxMlirOptions)); static llvm::cl::opt optReportOpt("opt-report", diff --git a/src/Compiler/CompilerOptions.hpp b/src/Compiler/CompilerOptions.hpp index 762bedbc99..f07029a583 100644 --- a/src/Compiler/CompilerOptions.hpp +++ b/src/Compiler/CompilerOptions.hpp @@ -138,7 +138,7 @@ extern bool disableConstantProp; // onnx-mlir only extern std::vector extraLibPaths; // onnx-mlir only extern std::vector extraLibs; // onnx-mlir only extern ProfileIRs profileIR; // onnx-mlir only -extern bool profileAllOps; // onnx-mlir only +extern bool profileConstOps; // onnx-mlir only extern OptReport optReport; // onnx-mlir only extern bool enableTiming; // onnx-mlir only extern bool enableBoundCheck; // onnx-mlir only diff --git a/src/Compiler/CompilerPasses.cpp b/src/Compiler/CompilerPasses.cpp index 0328face7c..2e8b1aeef0 100644 --- a/src/Compiler/CompilerPasses.cpp +++ b/src/Compiler/CompilerPasses.cpp @@ -167,7 +167,7 @@ void addONNXToMLIRPasses(mlir::PassManager &pm, bool targetCPU, instrumentActions |= (1 << 3) - 1; // Also enable instrumentation of signatures. instrumentSignatures = "onnx.*"; - if (profileAllOps) { + if (profileConstOps) { instrumentOps += ",krnl.global"; instrumentSignatures += ",krnl.global"; } @@ -176,10 +176,10 @@ void addONNXToMLIRPasses(mlir::PassManager &pm, bool targetCPU, // include timing of the signature printing. if (hasSignatureInstrumentation(onnx_mlir::InstrumentStages::Onnx)) pm.addNestedPass(onnx_mlir::createInstrumentONNXSignaturePass( - instrumentSignatures, instrumentOnnxNode, !profileAllOps)); + instrumentSignatures, instrumentOnnxNode, !profileConstOps)); if (hasInstrumentation(onnx_mlir::InstrumentStages::Onnx)) pm.addNestedPass(onnx_mlir::createInstrumentPass( - instrumentOps, instrumentActions, !profileAllOps)); + instrumentOps, instrumentActions, !profileConstOps)); } void addONNXToKrnlPasses(mlir::PassManager &pm, int optLevel, bool enableCSE, @@ -280,7 +280,7 @@ void addKrnlToLLVMPasses( pm.addPass(mlir::memref::createFoldMemRefAliasOpsPass()); - if (profileIR && !profileAllOps) + if (profileIR && !profileConstOps) pm.addNestedPass(onnx_mlir::createInstrumentCleanupPass()); if (enableBoundCheck) diff --git a/src/Transform/InstrumentCleanupPass.cpp b/src/Transform/InstrumentCleanupPass.cpp index 43fb340a35..31f863aaea 100644 --- a/src/Transform/InstrumentCleanupPass.cpp +++ b/src/Transform/InstrumentCleanupPass.cpp @@ -105,7 +105,7 @@ class InstrumentCleanupPass : public mlir::PassWrapper Date: Thu, 14 Aug 2025 14:55:39 -0400 Subject: [PATCH 3/5] response to comments Signed-off-by: Alexandre Eichenberger --- src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp | 6 +++--- src/Compiler/CompilerOptions.cpp | 7 ++++--- src/Compiler/CompilerOptions.hpp | 2 +- src/Compiler/CompilerPasses.cpp | 8 ++++---- .../ONNX/Transforms/InstrumentONNXSignaturePass.cpp | 4 ++-- src/Pass/Passes.hpp | 4 ++-- src/Tools/onnx-mlir-opt/RegisterPasses.cpp | 2 +- src/Transform/InstrumentPass.cpp | 4 ++-- 8 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp b/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp index 10765e02bc..de6c79da0d 100644 --- a/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp +++ b/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp @@ -198,10 +198,10 @@ void addONNXToZHighPasses(mlir::PassManager &pm) { // not to include timing of the signature printing. if (hasSignatureInstrumentation(onnx_mlir::InstrumentStages::ZHigh)) pm.addNestedPass(onnx_mlir::createInstrumentONNXSignaturePass( - instrumentSignatures, instrumentOnnxNode, !profileConstOps)); + instrumentSignatures, instrumentOnnxNode, enableConstantOpProfiling)); if (hasInstrumentation(onnx_mlir::InstrumentStages::ZHigh)) pm.addNestedPass(onnx_mlir::createInstrumentPass( - instrumentOps, instrumentActions, !profileConstOps)); + instrumentOps, instrumentActions, enableConstantOpProfiling)); } void normalizeMemRefsPasses(mlir::PassManager &pm) { @@ -298,7 +298,7 @@ void addPassesNNPA(mlir::OwningOpRef &module, "stage is currently unsupported"); if (hasInstrumentation(onnx_mlir::InstrumentStages::ZLow)) pm.addNestedPass(onnx_mlir::createInstrumentPass( - instrumentOps, instrumentControlBits, !profileConstOps)); + instrumentOps, instrumentControlBits, enableConstantOpProfiling)); } } diff --git a/src/Compiler/CompilerOptions.cpp b/src/Compiler/CompilerOptions.cpp index f4388e1523..c49d3f6b8d 100644 --- a/src/Compiler/CompilerOptions.cpp +++ b/src/Compiler/CompilerOptions.cpp @@ -93,7 +93,7 @@ bool disableConstantProp; // onnx-mlir only std::vector extraLibPaths; // onnx-mlir only std::vector extraLibs; // onnx-mlir only ProfileIRs profileIR; // onnx-mlir only -bool profileConstOps; // onnx-mlir only +bool enableConstantOpProfiling; // onnx-mlir only OptReport optReport; // onnx-mlir only bool enableTiming; // onnx-mlir only bool enableBoundCheck; // onnx-mlir only @@ -701,11 +701,12 @@ static llvm::cl::opt profileIROpt("profile-ir", APPLY_TO_ACCELERATORS(ACCEL_PROFILEIR_CL_ENUM)), llvm::cl::init(ProfileIRs::None), llvm::cl::cat(OnnxMlirOptions)); -static llvm::cl::opt profileConstOpOpt("profile-constant-ops", +static llvm::cl::opt enableConstantOpProfilingOpt( + "enable-constant-op-profiling", llvm::cl::desc("Normally we disable generating profiling information for\n" "constant-generating operations.\nUse this option to force" " profiling for all ops (default is false)."), - llvm::cl::location(profileConstOps), llvm::cl::init(false), + llvm::cl::location(enableConstantOpProfiling), llvm::cl::init(false), llvm::cl::cat(OnnxMlirOptions)); static llvm::cl::opt optReportOpt("opt-report", diff --git a/src/Compiler/CompilerOptions.hpp b/src/Compiler/CompilerOptions.hpp index f07029a583..c790727948 100644 --- a/src/Compiler/CompilerOptions.hpp +++ b/src/Compiler/CompilerOptions.hpp @@ -138,7 +138,7 @@ extern bool disableConstantProp; // onnx-mlir only extern std::vector extraLibPaths; // onnx-mlir only extern std::vector extraLibs; // onnx-mlir only extern ProfileIRs profileIR; // onnx-mlir only -extern bool profileConstOps; // onnx-mlir only +extern bool enableConstantOpProfiling; // onnx-mlir only extern OptReport optReport; // onnx-mlir only extern bool enableTiming; // onnx-mlir only extern bool enableBoundCheck; // onnx-mlir only diff --git a/src/Compiler/CompilerPasses.cpp b/src/Compiler/CompilerPasses.cpp index 2e8b1aeef0..422f0b511a 100644 --- a/src/Compiler/CompilerPasses.cpp +++ b/src/Compiler/CompilerPasses.cpp @@ -167,7 +167,7 @@ void addONNXToMLIRPasses(mlir::PassManager &pm, bool targetCPU, instrumentActions |= (1 << 3) - 1; // Also enable instrumentation of signatures. instrumentSignatures = "onnx.*"; - if (profileConstOps) { + if (enableConstantOpProfiling) { instrumentOps += ",krnl.global"; instrumentSignatures += ",krnl.global"; } @@ -176,10 +176,10 @@ void addONNXToMLIRPasses(mlir::PassManager &pm, bool targetCPU, // include timing of the signature printing. if (hasSignatureInstrumentation(onnx_mlir::InstrumentStages::Onnx)) pm.addNestedPass(onnx_mlir::createInstrumentONNXSignaturePass( - instrumentSignatures, instrumentOnnxNode, !profileConstOps)); + instrumentSignatures, instrumentOnnxNode, enableConstantOpProfiling)); if (hasInstrumentation(onnx_mlir::InstrumentStages::Onnx)) pm.addNestedPass(onnx_mlir::createInstrumentPass( - instrumentOps, instrumentActions, !profileConstOps)); + instrumentOps, instrumentActions, enableConstantOpProfiling)); } void addONNXToKrnlPasses(mlir::PassManager &pm, int optLevel, bool enableCSE, @@ -280,7 +280,7 @@ void addKrnlToLLVMPasses( pm.addPass(mlir::memref::createFoldMemRefAliasOpsPass()); - if (profileIR && !profileConstOps) + if (profileIR && !enableConstantOpProfiling) pm.addNestedPass(onnx_mlir::createInstrumentCleanupPass()); if (enableBoundCheck) diff --git a/src/Dialect/ONNX/Transforms/InstrumentONNXSignaturePass.cpp b/src/Dialect/ONNX/Transforms/InstrumentONNXSignaturePass.cpp index d143557f44..5dd234370d 100644 --- a/src/Dialect/ONNX/Transforms/InstrumentONNXSignaturePass.cpp +++ b/src/Dialect/ONNX/Transforms/InstrumentONNXSignaturePass.cpp @@ -147,7 +147,7 @@ class InstrumentONNXSignaturePass */ std::unique_ptr onnx_mlir::createInstrumentONNXSignaturePass( const std::string pattern, const std::string nodePattern, - bool skipConstants) { + bool profileConstantOps) { return std::make_unique( - pattern, nodePattern, skipConstants); + pattern, nodePattern, !profileConstantOps); } diff --git a/src/Pass/Passes.hpp b/src/Pass/Passes.hpp index 918aba1274..114db9eb53 100644 --- a/src/Pass/Passes.hpp +++ b/src/Pass/Passes.hpp @@ -56,7 +56,7 @@ std::unique_ptr createConstPropONNXToONNXPass(); /// Pass for instrument the ops in specific stage. std::unique_ptr createInstrumentPass(); std::unique_ptr createInstrumentPass( - const std::string &ops, unsigned actions, bool skipConstants); + const std::string &ops, unsigned actions, bool profileConstantOps); /// Pass for instrument cleanup. std::unique_ptr createInstrumentCleanupPass(); @@ -64,7 +64,7 @@ std::unique_ptr createInstrumentCleanupPass(); /// signatures at runtime. std::unique_ptr createInstrumentONNXSignaturePass( const std::string opPattern, const std::string nodePattern, - bool skipConstants); + bool profileConstantOps); /// Pass for simplifying shape-related ONNX operations. std::unique_ptr createSimplifyShapeRelatedOpsPass(); diff --git a/src/Tools/onnx-mlir-opt/RegisterPasses.cpp b/src/Tools/onnx-mlir-opt/RegisterPasses.cpp index b15af4c3c0..55f73c309b 100644 --- a/src/Tools/onnx-mlir-opt/RegisterPasses.cpp +++ b/src/Tools/onnx-mlir-opt/RegisterPasses.cpp @@ -75,7 +75,7 @@ void registerOMPasses(int optLevel) { }); mlir::registerPass([]() -> std::unique_ptr { - return createInstrumentONNXSignaturePass("NONE", "NONE", true); + return createInstrumentONNXSignaturePass("NONE", "NONE", false); }); mlir::registerPass([]() -> std::unique_ptr { diff --git a/src/Transform/InstrumentPass.cpp b/src/Transform/InstrumentPass.cpp index e70dc1f921..280aad592a 100644 --- a/src/Transform/InstrumentPass.cpp +++ b/src/Transform/InstrumentPass.cpp @@ -192,6 +192,6 @@ std::unique_ptr onnx_mlir::createInstrumentPass() { } std::unique_ptr onnx_mlir::createInstrumentPass( - const std::string &ops, unsigned actions, bool skipConstants) { - return std::make_unique(ops, actions, skipConstants); + const std::string &ops, unsigned actions, bool profileConstantOps) { + return std::make_unique(ops, actions, !profileConstantOps); } From 8166340791b71a4581d78b9a087db7db775872eb Mon Sep 17 00:00:00 2001 From: Alexandre Eichenberger Date: Thu, 14 Aug 2025 14:57:29 -0400 Subject: [PATCH 4/5] removed debugging Signed-off-by: Alexandre Eichenberger --- src/Transform/InstrumentCleanupPass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Transform/InstrumentCleanupPass.cpp b/src/Transform/InstrumentCleanupPass.cpp index 31f863aaea..43fb340a35 100644 --- a/src/Transform/InstrumentCleanupPass.cpp +++ b/src/Transform/InstrumentCleanupPass.cpp @@ -105,7 +105,7 @@ class InstrumentCleanupPass : public mlir::PassWrapper Date: Thu, 14 Aug 2025 15:01:33 -0400 Subject: [PATCH 5/5] added krnl.global on the NNPA path Signed-off-by: Alexandre Eichenberger --- src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp b/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp index de6c79da0d..fcb887fae5 100644 --- a/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp +++ b/src/Accelerators/NNPA/Compiler/NNPACompilerUtils.cpp @@ -190,6 +190,10 @@ void addONNXToZHighPasses(mlir::PassManager &pm) { instrumentActions |= (1 << 3) - 1; // Also enable instrumentation of signatures. instrumentSignatures = "onnx.*,zhigh.*"; + if (enableConstantOpProfiling) { + instrumentOps += ",krnl.global"; + instrumentSignatures += ",krnl.global"; + } } // Insert an instrumentation after lowering onnx to zhigh to get profiling /