-
Notifications
You must be signed in to change notification settings - Fork 348
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
Changes from 5 commits
a471dc3
c7f84b1
056dd74
3c015f0
68f25f2
f95a047
69cba4e
fff854f
d8f2812
7f49357
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,16 @@ | |
#include "CompilerUtils.hpp" | ||
|
||
#include <fstream> | ||
#include <memory> | ||
#include <regex> | ||
|
||
#include "mlir/Dialect/Func/IR/FuncOps.h" | ||
#include "mlir/Dialect/LLVMIR/LLVMDialect.h" | ||
#include "mlir/Parser/Parser.h" | ||
#include "mlir/Pass/Pass.h" | ||
#include "mlir/Pass/PassManager.h" | ||
#include "mlir/Support/FileUtilities.h" | ||
#include "mlir/Support/Timing.h" | ||
#include "mlir/Target/LLVMIR/Dialect/Builtin/BuiltinToLLVMIRTranslation.h" | ||
#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h" | ||
#include "mlir/Target/LLVMIR/Export.h" | ||
|
@@ -35,6 +38,7 @@ | |
#include "llvm/Support/SourceMgr.h" | ||
#include "llvm/Support/TargetSelect.h" | ||
#include "llvm/Support/ToolOutputFile.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
#include "llvm/Target/TargetMachine.h" | ||
|
||
#include "src/Accelerators/Accelerator.hpp" | ||
|
@@ -49,6 +53,9 @@ | |
using namespace mlir; | ||
using namespace onnx_mlir; | ||
|
||
mlir::DefaultTimingManager timingManager; | ||
mlir::TimingScope rootScope; | ||
|
||
namespace onnx_mlir { | ||
|
||
// Make a function that forces preserving all files using the runtime arguments | ||
|
@@ -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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert this change, it caused clang-format failed. |
||
return rc; | ||
} | ||
|
||
|
@@ -327,6 +333,8 @@ std::string getTargetFilename( | |
// Returns 0 on success, error code on failure. | ||
static int genLLVMBitcode(const mlir::OwningOpRef<ModuleOp> &module, | ||
std::string outputNameNoExt, std::string optimizedBitcodeNameWithExt) { | ||
auto llvmTiming = rootScope.nest( | ||
"[onnx-mlir] Compiling MLIR module to LLVM Optimized Bitcode"); | ||
std::error_code error; | ||
|
||
// Write bitcode to a file. | ||
|
@@ -397,7 +405,8 @@ static int genLLVMBitcode(const mlir::OwningOpRef<ModuleOp> &module, | |
// Return 0 on success, error code on failure. | ||
static int genModelObject( | ||
std::string bitcodeNameWithExt, std::string &modelObjNameWithExt) { | ||
|
||
auto objectTiming = | ||
rootScope.nest("[onnx-mlir] Compiling LLVM Bitcode to Object File"); | ||
std::string llcPath = getToolPath("llc"); | ||
Command llvmToObj(/*exePath=*/llcPath); | ||
setXllcOption({"--code-model", modelSizeStr[modelSize]}); | ||
|
@@ -418,6 +427,7 @@ static int genModelObject( | |
// Return 0 on success, error code on failure. | ||
static int genJniObject(const mlir::OwningOpRef<ModuleOp> &module, | ||
std::string jniSharedLibPath, std::string jniObjPath) { | ||
auto jniTiming = rootScope.nest("[onnx-mlir] Compiling JNI Object File"); | ||
Command ar(/*exePath=*/getToolPath("ar", true)); | ||
int rc = ar.appendStr("x") | ||
// old version of ar does not support --output so comment out | ||
|
@@ -436,7 +446,6 @@ static int genJniObject(const mlir::OwningOpRef<ModuleOp> &module, | |
static int genSharedLib(std::string sharedLibNameWithExt, | ||
std::vector<std::string> opts, std::vector<std::string> objs, | ||
std::vector<std::string> libs, std::vector<std::string> libDirs) { | ||
|
||
#ifdef _WIN32 | ||
std::vector<std::string> outputOpt = {"/Fe:" + sharedLibNameWithExt}; | ||
// link has to be before libpath since they need to be passed through to the | ||
|
@@ -486,6 +495,7 @@ static int genSharedLib(std::string sharedLibNameWithExt, | |
// Return 0 on success, error code on failure. | ||
static int genJniJar(const mlir::OwningOpRef<ModuleOp> &module, | ||
std::string modelSharedLibPath, std::string modelJniJarPath) { | ||
auto jniJarTiming = rootScope.nest("[onnx-mlir] Creating JNI Jar"); | ||
llvm::SmallString<8> libraryPath(getLibraryPath()); | ||
llvm::sys::path::append(libraryPath, "javaruntime.jar"); | ||
std::string javaRuntimeJarPath = llvm::StringRef(libraryPath).str(); | ||
|
@@ -568,8 +578,7 @@ static int compileModuleToJniJar( | |
#define NOEXECSTACK \ | ||
{} | ||
#else | ||
#define NOEXECSTACK \ | ||
{ "-z", "noexecstack" } | ||
#define NOEXECSTACK {"-z", "noexecstack"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert this change, it caused clang-format failed. |
||
#endif | ||
std::string modelSharedLibPath = getTargetFilename(jniLibBase, EmitLib); | ||
rc = genSharedLib(modelSharedLibPath, NOEXECSTACK, | ||
|
@@ -879,6 +888,9 @@ static int emitOutput(mlir::OwningOpRef<ModuleOp> &module, | |
int compileModule(mlir::OwningOpRef<ModuleOp> &module, | ||
mlir::MLIRContext &context, std::string outputNameNoExt, | ||
EmissionTargetType emissionTarget) { | ||
auto compileModuleTiming = | ||
rootScope.nest("[onnx-mlir] Compiling Module using MLIR"); | ||
|
||
int rc = setupModule(module, context, outputNameNoExt); | ||
if (rc != CompilerSuccess) | ||
return rc; | ||
|
@@ -904,10 +916,14 @@ int compileModule(mlir::OwningOpRef<ModuleOp> &module, | |
heapLogFileame, reportHeapBefore, reportHeapAfter)); | ||
} | ||
(void)mlir::applyPassManagerCLOptions(pm); | ||
mlir::applyDefaultTimingPassManagerCLOptions(pm); | ||
|
||
if (enableTiming) { | ||
pm.enableTiming(compileModuleTiming); | ||
} | ||
|
||
if (mlir::failed(pm.run(*module))) | ||
return CompilerFailure; | ||
compileModuleTiming.stop(); | ||
return emitOutput(module, context, outputNameNoExt, pm, emissionTarget); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1073,8 +1073,8 @@ ElementsAttr ElementsAttrBuilder::nonZero(ElementsAttr elms) { | |
} | ||
|
||
/*static*/ | ||
auto ElementsAttrBuilder::getElementsProperties(ElementsAttr elements) | ||
-> ElementsProperties { | ||
auto ElementsAttrBuilder::getElementsProperties( | ||
ElementsAttr elements) -> ElementsProperties { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert this change, it caused clang-format failed. |
||
static Transformer nullTransformer = nullptr; | ||
if (auto disposable = elements.dyn_cast<DisposableElementsAttr>()) { | ||
ArrayRef<int64_t> strides = disposable.getStrides(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change
rootScope
torootTimingScope
.