Skip to content

Timing tool that adds the flag “--enable-timing" for a detailed report #2801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 25, 2024

Conversation

ParamvirSran
Copy link
Contributor

Detailed timing report printed to the terminal for the entire onnx-mlir execution process, including setup in main() in onnx-mlir.cpp, input file processing before compilation, the passes run in the pass manager, and finally, the lower level compilation/generation stages (LLVM, Object, Shared Library, JNI). This tool will print the detailed execution report as a tree of all the timed stages to the terminal with the (wall time) and (relative percentage of program execution) for each timed stage and the total execution time of the onnx-mlir compiler. I used the DefaultTimingManager from llvm-project “timing.cpp” and timing scopes to time and name essential code sections where work is being done.

Example:
image

@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@tungld
Copy link
Collaborator

tungld commented Apr 16, 2024

@jenkins-droid test this please

@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

…art a detailed timing report for the entire onnx-mlir execution process, including setup in main() in onnx-mlir.cpp, input file processing before compilation, the passes run in the pass manager, and finally, the lower level compilation/generation stages (LLVM, Object, Shared Library, JNI). This tool will print the detailed execution report as a tree of all the timed stages to the terminal with the (wall time) and (relative percentage of program execution) for each timed stage and the total execution time of the onnx-mlir compiler. I used the DefaultTimingManager from llvm-project “timing.cpp” and timing scopes to time and name essential code sections where work is being done.

Signed-off-by: Paramvir Sran <[email protected]>
@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

Copy link
Collaborator

@tungld tungld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great feature! Thank you very much for working on this!

Just some comments. They are mainly about changing text messages. Please fix DCO also so that it can be merged.

CMakeLists.txt Outdated
@@ -7,7 +7,7 @@ project(onnx-mlir)

option(ONNX_MLIR_BUILD_TESTS "Build ONNX-MLIR test executables. If OFF, just generate build targets." ON)
option(ONNX_MLIR_CCACHE_BUILD "Set to ON for a ccache enabled build." OFF)
option(ONNX_MLIR_ENABLE_STABLEHLO "Enable StableHLO support." ON)
option(ONNX_MLIR_ENABLE_STABLEHLO "Enable StableHLO support." OFF)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the final commit, please change this back to ON.

"terminal.integrated.defaultProfile.linux": "bash",
"cmake.mergedCompileCommands": "${workspaceFolder}/compile_commands.json",
"cmakeExplorer.suiteDelimiter": ".",
"cmakeExplorer.debugConfig": "(gdb) Launch",
"editor.formatOnSave": true,
"[cpp]": {
"editor.defaultFormatter": "xaver.clang-format",
"editor.tabSize": 2
"editor.tabSize":2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this space redundant? It looks like an accidental change.

@@ -546,6 +547,12 @@ static llvm::cl::opt<OptReport, true> optReportOpt("opt-report",
clEnumVal(Simd, "Provide report on how SIMD is applied to ONNX ops.")),
llvm::cl::init(OptReport::NoReport), llvm::cl::cat(OnnxMlirOptions));

static llvm::cl::opt<bool, true> enable_timing("enable-timing",
llvm::cl::desc("Enable pass timing (default is false)\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe Enable compile timing is easier to understand.

@@ -579,6 +586,7 @@ static llvm::cl::opt<bool, true> useOldBufferizationOpt("use-old-bufferization",
llvm::cl::location(useOldBufferization), llvm::cl::init(true),
llvm::cl::cat(OnnxMlirOptions));


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this redundant line.

#include "llvm/Target/TargetMachine.h"
#include <fstream>
#include <memory>
#include <regex>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you include these three lines first? They are from C++, and we often include them first before mlir stuffs.

initCompilerConfig();

// timing manager reporting enabled via "--enable-timing" compiler flag
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typos: timing => Timing

initCompilerConfig();

// timing manager reporting enabled via "--enable-timing" compiler flag
// mlir::applyDefaultTimingManagerCLOptions(timingManager);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be removed?

// mlir::applyDefaultTimingManagerCLOptions(timingManager);
timingManager.setEnabled(enableTiming);
rootScope = timingManager.getRootScope();
auto setupScope = rootScope.nest("[onnx-mlir] Preparing for Compilation");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setupScope => setupTiming.

Perhaps, change the message to [onnx-mlir] Loading Dialects

@@ -71,7 +74,8 @@ int main(int argc, char *argv[]) {
LLVM_DEBUG(llvm::dbgs() << "multithreading is disabled\n");
}
loadDialects(context);

setupScope.stop();
auto inputFileScope = rootScope.nest("[onnx-mlir] Processing of Input File");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inputFileScope => inputFileTiming

I think [onnx-mlir] Importing Input Model to MLIR is easier to understand.

timing.diff Outdated
@@ -0,0 +1,143 @@
diff --git a/src/Compiler/CompilerUtils.cpp b/src/Compiler/CompilerUtils.cpp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this file.

@tungld
Copy link
Collaborator

tungld commented Apr 22, 2024

@ParamvirSran follow the instruction here to fix DCO: https://github.com/onnx/onnx-mlir/pull/2801/checks?check_run_id=24080750134.

For Clang Format, you can run git clang-format to format the code, see https://github.com/onnx/onnx-mlir/blob/main/docs/Workflow.md#code-style

Signed-off-by: Paramvir Sran <[email protected]>
@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@tungld
Copy link
Collaborator

tungld commented Apr 22, 2024

@jenkins-droid test this please

@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@tungld
Copy link
Collaborator

tungld commented Apr 22, 2024

@jenkins-droid test this please

@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@tungld
Copy link
Collaborator

tungld commented Apr 22, 2024

@jenkins-droid test this please

@@ -146,8 +153,7 @@ int Command::exec(std::string wdir) const {
llvm::errs() << llvm::join(argsRef, " ") << "\n"
<< "Error message: " << errMsg << "\n"
<< "Program path: " << _path << "\n"
<< "Command execution failed."
<< "\n";
<< "Command execution failed." << "\n";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change, it caused clang-format failed.

@@ -568,8 +578,7 @@ static int compileModuleToJniJar(
#define NOEXECSTACK \
{}
#else
#define NOEXECSTACK \
{ "-z", "noexecstack" }
#define NOEXECSTACK {"-z", "noexecstack"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change, it caused clang-format failed.

auto ElementsAttrBuilder::getElementsProperties(ElementsAttr elements)
-> ElementsProperties {
auto ElementsAttrBuilder::getElementsProperties(
ElementsAttr elements) -> ElementsProperties {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change, it caused clang-format failed.

@@ -49,6 +53,9 @@
using namespace mlir;
using namespace onnx_mlir;

mlir::DefaultTimingManager timingManager;
mlir::TimingScope rootScope;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change rootScope to rootTimingScope.

Signed-off-by: Paramvir Sran <[email protected]>
@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

Copy link
Collaborator

@tungld tungld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for adding this useful option!

@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@jenkins-droid
Copy link
Collaborator

Can one of the admins verify this patch?

@tungld
Copy link
Collaborator

tungld commented Apr 25, 2024

@jenkins-droid test this please

@tungld tungld merged commit 060b370 into onnx:main Apr 25, 2024
6 of 7 checks passed
@jenkins-droid
Copy link
Collaborator

Jenkins Linux s390x Build #14756 [push] Timing tool that adds th... started at 01:06

@jenkins-droid
Copy link
Collaborator

Jenkins Linux ppc64le Build #13751 [push] Timing tool that adds th... started at 01:17

@jenkins-droid
Copy link
Collaborator

Jenkins Linux amd64 Build #14726 [push] Timing tool that adds th... started at 00:06

@jenkins-droid
Copy link
Collaborator

Jenkins Linux amd64 Build #14726 [push] Timing tool that adds th... passed after 1 hr 11 min

@jenkins-droid
Copy link
Collaborator

Jenkins Linux s390x Build #14756 [push] Timing tool that adds th... passed after 1 hr 23 min

@jenkins-droid
Copy link
Collaborator

Jenkins Linux ppc64le Build #13751 [push] Timing tool that adds th... passed after 1 hr 59 min

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants