Skip to content

Commit

Permalink
Tune compiler tracing usage of 'frame's. (iree-org#15216)
Browse files Browse the repository at this point in the history
Compiler tracing was a bit confusing when profiling to find
iree-org#15209.

First, this fixes an issue where frame frames were unbalanced upon
recursing into the compiler, leading to confusing rendering in the Tracy
UI that could misattribute sections of the compiler running to the
"GlobalOptimization" pass pipeline:

![image](https://github.com/openxla/iree/assets/4010439/9407b54d-4e5f-4ed1-9232-4f870561ac48)

Second, this tweaks how frames are defined for unnamed pipelines and
adds a scope for bytecode translation (which happens outside of a pass
pipeline):

![image](https://github.com/openxla/iree/assets/4010439/43cc02ba-e9e6-4a49-8ebe-972be2ca7106)
  • Loading branch information
ScottTodd authored Oct 17, 2023
1 parent bb087a1 commit 0b2997e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 2 additions & 0 deletions compiler/src/iree/compiler/API/Internal/CompilerDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,8 @@ bool Invocation::runPipeline(enum iree_compiler_pipeline_t pipeline) {
if (failed(passManager->run(parsedModule))) {
return false;
}
// Done with the pipeline, mark the start of a new 'frame'.
IREE_TRACE_FRAME_MARK();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ translateModuleToBytecode(IREE::VM::ModuleOp moduleOp,
IREE::VM::TargetOptions vmOptions,
IREE::VM::BytecodeTargetOptions bytecodeOptions,
llvm::raw_ostream &output) {
IREE_TRACE_SCOPE();
moduleOp.getContext()->getOrLoadDialect<IREE::Util::UtilDialect>();

if (failed(canonicalizeModule(bytecodeOptions, moduleOp))) {
Expand Down
25 changes: 21 additions & 4 deletions compiler/src/iree/compiler/Pipelines/Pipelines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,36 @@ void buildIREEPrecompileTransformPassPipeline(
break;
default:
if (compileFrom < IREEVMPipelinePhase::Preprocessing) { // late-entry.
IREE_TRACE_ADD_BEGIN_FRAME_PASS(passManager, "Preprocessing");
// Not a large enough phase for IREE_TRACE_ADD_[BEGIN,END]_FRAME_PASS.
IREE::buildPreprocessingPassPipeline(passManager, preprocessingOptions,
hooks.pipelineExtensions);
IREE_TRACE_ADD_END_FRAME_PASS(passManager, "Preprocessing");
}
if (compileTo == IREEVMPipelinePhase::Preprocessing)
return; // early-exit

if (compileFrom < IREEVMPipelinePhase::GlobalOptimization) { // late-entry
IREE_TRACE_ADD_BEGIN_FRAME_PASS(passManager, "GlobalOptimization");
// This pass pipeline recursively invokes the compiler if constEval is
// enabled. In that case, we have to be careful to not emit unbalanced
// trace frames:
// begin 'GlobalOptimization'
// begin 'Input'
// end 'Input'
// begin 'GlobalOptimization' <-- unbalanced! Use a different name.
// end 'GlobalOptimization'
// ...
// end 'GlobalOptimization'
if (globalOptimizationOptions.constEval) {
IREE_TRACE_ADD_BEGIN_FRAME_PASS(passManager, "GlobalOptimizationConst");
} else {
IREE_TRACE_ADD_BEGIN_FRAME_PASS(passManager, "GlobalOptimization");
}
GlobalOptimization::buildGlobalOptimizationPassPipeline(
passManager, globalTransformOptions);
IREE_TRACE_ADD_END_FRAME_PASS(passManager, "GlobalOptimization");
if (globalOptimizationOptions.constEval) {
IREE_TRACE_ADD_END_FRAME_PASS(passManager, "GlobalOptimizationConst");
} else {
IREE_TRACE_ADD_END_FRAME_PASS(passManager, "GlobalOptimization");
}
}
if (compileTo == IREEVMPipelinePhase::GlobalOptimization)
return; // early-exit
Expand Down
4 changes: 1 addition & 3 deletions compiler/src/iree/compiler/Utils/TracingUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ class TraceFrameMarkBeginPass
TraceFrameMarkBeginPass(llvm::StringRef name) { this->name = name; }

void runOnOperation() override {
// Always mark the top level (unnamed) frame.
IREE_TRACE_FRAME_MARK();

if (!name.empty()) {
IREE_TRACE_FRAME_MARK(); // Top level (unnamed) frame.
IREE_TRACE_FRAME_MARK_BEGIN_NAMED(name.data());
}
}
Expand Down

0 comments on commit 0b2997e

Please sign in to comment.