Skip to content

Commit

Permalink
Added file name and time elapsed to onnx-mlir messages (#2914)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Eichenberger <[email protected]>
  • Loading branch information
AlexandreEichenberger authored Aug 22, 2024
1 parent df9a32d commit ad885ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
31 changes: 23 additions & 8 deletions src/Compiler/CompilerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace onnx_mlir {
// Values to report the current phase of compilation.
// Increase TOTAL_COMPILE_PHASE when having more phases.
uint64_t CURRENT_COMPILE_PHASE = 1;
uint64_t TOTAL_COMPILE_PHASE = 5;
uint64_t TOTAL_COMPILE_PHASE = 6;

// Make a function that forces preserving all files using the runtime arguments
// and/or the overridePreserveFiles enum.
Expand Down Expand Up @@ -170,24 +170,37 @@ int Command::exec(std::string wdir) const {
}

void showCompilePhase(std::string msg) {
time_t rawtime;
struct tm *timeinfo;
time_t rawTime;
struct tm *timeInfo;
char buffer[80];
// Remember first time.
static time_t firstRawTime;
static bool hasFirstRawTime = false;

// Get current date.
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, 80, "%c", timeinfo);
time(&rawTime);
timeInfo = localtime(&rawTime);
strftime(buffer, 80, "%c", timeInfo);
std::string currentTime(buffer);

// Compute time difference in seconds.
int diff = 0;
if (hasFirstRawTime) {
diff = difftime(rawTime, firstRawTime);
} else {
firstRawTime = rawTime;
hasFirstRawTime = true;
}
llvm::outs() << "[" << CURRENT_COMPILE_PHASE++ << "/" << TOTAL_COMPILE_PHASE
<< "] " << currentTime << " " << msg << "\n";
<< "] " << currentTime << " (" << diff << "s) " << msg << "\n";
// Flush so that if there are errors, we know where it came from.
llvm::outs().flush();

// Reset current phase.
if (CURRENT_COMPILE_PHASE > TOTAL_COMPILE_PHASE)
if (CURRENT_COMPILE_PHASE > TOTAL_COMPILE_PHASE) {
CURRENT_COMPILE_PHASE = 1;
hasFirstRawTime = false;
}
}

} // namespace onnx_mlir
Expand Down Expand Up @@ -813,6 +826,8 @@ static int emitOutputFiles(std::string outputNameNoExt,
}
}
}
showCompilePhase("Compilation completed");

return CompilerSuccess;
} // end anonymous namespace

Expand Down
11 changes: 6 additions & 5 deletions test/mlir/driver/compile_phases.mlir
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// RUN: onnx-mlir %s -o %t| FileCheck %s && rm %t.so

// CHECK: [1/5] {{.*}} Importing ONNX Model to MLIR Module
// CHECK: [2/5] {{.*}} Compiling and Optimizing MLIR Module
// CHECK: [3/5] {{.*}} Translating MLIR Module to LLVM and Generating LLVM Optimized Bitcode
// CHECK: [4/5] {{.*}} Generating Object from LLVM Bitcode
// CHECK: [5/5] {{.*}} Linking and Generating the Output Shared Library
// CHECK: [1/6] {{.*}} Importing ONNX Model to MLIR Module from
// CHECK: [2/6] {{.*}} Compiling and Optimizing MLIR Module
// CHECK: [3/6] {{.*}} Translating MLIR Module to LLVM and Generating LLVM Optimized Bitcode
// CHECK: [4/6] {{.*}} Generating Object from LLVM Bitcode
// CHECK: [5/6] {{.*}} Linking and Generating the Output Shared Library
// CHECK: [6/6] {{.*}} Compilation completed
module {
func.func @main_graph(%arg0: tensor<?xf32>) -> tensor<?xf32> {
onnx.Return %arg0 : tensor<?xf32>
Expand Down

0 comments on commit ad885ed

Please sign in to comment.