-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add runtime tracing support to passes under IREE's PassManager usage. (…
…#5160) Thanks to [this tip](https://discord.com/channels/689900678990135345/760577505840463893/772892255106105365) way back on Discord :D Sample instrumented trace: ![image](https://user-images.githubusercontent.com/4010439/111682242-59dd5180-87e1-11eb-8c16-cbb8ed4a7ef7.png) That trace is measuring a debug compile of this model/flag combination: https://github.com/google/iree/blob/789689dd12a7d17292e2371945d72e56447f53f6/iree/test/e2e/models/CMakeLists.txt#L54-L65
- Loading branch information
Showing
7 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef IREE_COMPILER_UTILS_TRACINGUTILS_H_ | ||
#define IREE_COMPILER_UTILS_TRACINGUTILS_H_ | ||
|
||
#include "iree/base/tracing.h" | ||
#include "mlir/Pass/Pass.h" | ||
#include "mlir/Pass/PassInstrumentation.h" | ||
|
||
namespace mlir { | ||
namespace iree_compiler { | ||
|
||
// Instruments passes using IREE's runtime tracing support. | ||
// | ||
// Usage: | ||
// passManager.addInstrumentation(std::make_unique<PassTracing>()); | ||
struct PassTracing : public PassInstrumentation { | ||
PassTracing() {} | ||
~PassTracing() override = default; | ||
|
||
#if IREE_TRACING_FEATURES & IREE_TRACING_FEATURE_INSTRUMENTATION | ||
// Note: we could also trace pipelines and analyses. | ||
|
||
void runBeforePass(Pass *pass, Operation *op) override { | ||
std::string passName = pass->getName().str(); | ||
IREE_TRACE_ZONE_BEGIN_NAMED_DYNAMIC(z0, passName.data(), passName.size()); | ||
passTraceZonesStack.push_back(z0); | ||
} | ||
void runAfterPass(Pass *pass, Operation *op) override { | ||
IREE_TRACE_ZONE_END(passTraceZonesStack.back()); | ||
passTraceZonesStack.pop_back(); | ||
} | ||
void runAfterPassFailed(Pass *pass, Operation *op) override { | ||
IREE_TRACE_ZONE_END(passTraceZonesStack.back()); | ||
passTraceZonesStack.pop_back(); | ||
} | ||
#endif // IREE_TRACING_FEATURES & IREE_TRACING_FEATURE_INSTRUMENTATION | ||
|
||
llvm::SmallVector<iree_zone_id_t, 8> passTraceZonesStack; | ||
}; | ||
|
||
} // namespace iree_compiler | ||
} // namespace mlir | ||
|
||
#endif // IREE_COMPILER_UTILS_TRACINGUTILS_H_ |