Skip to content

Commit ad885ed

Browse files
Added file name and time elapsed to onnx-mlir messages (#2914)
Signed-off-by: Alexandre Eichenberger <[email protected]>
1 parent df9a32d commit ad885ed

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

src/Compiler/CompilerUtils.cpp

+23-8
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace onnx_mlir {
6262
// Values to report the current phase of compilation.
6363
// Increase TOTAL_COMPILE_PHASE when having more phases.
6464
uint64_t CURRENT_COMPILE_PHASE = 1;
65-
uint64_t TOTAL_COMPILE_PHASE = 5;
65+
uint64_t TOTAL_COMPILE_PHASE = 6;
6666

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

172172
void showCompilePhase(std::string msg) {
173-
time_t rawtime;
174-
struct tm *timeinfo;
173+
time_t rawTime;
174+
struct tm *timeInfo;
175175
char buffer[80];
176+
// Remember first time.
177+
static time_t firstRawTime;
178+
static bool hasFirstRawTime = false;
176179

177180
// Get current date.
178-
time(&rawtime);
179-
timeinfo = localtime(&rawtime);
180-
strftime(buffer, 80, "%c", timeinfo);
181+
time(&rawTime);
182+
timeInfo = localtime(&rawTime);
183+
strftime(buffer, 80, "%c", timeInfo);
181184
std::string currentTime(buffer);
182185

186+
// Compute time difference in seconds.
187+
int diff = 0;
188+
if (hasFirstRawTime) {
189+
diff = difftime(rawTime, firstRawTime);
190+
} else {
191+
firstRawTime = rawTime;
192+
hasFirstRawTime = true;
193+
}
183194
llvm::outs() << "[" << CURRENT_COMPILE_PHASE++ << "/" << TOTAL_COMPILE_PHASE
184-
<< "] " << currentTime << " " << msg << "\n";
195+
<< "] " << currentTime << " (" << diff << "s) " << msg << "\n";
185196
// Flush so that if there are errors, we know where it came from.
186197
llvm::outs().flush();
187198

188199
// Reset current phase.
189-
if (CURRENT_COMPILE_PHASE > TOTAL_COMPILE_PHASE)
200+
if (CURRENT_COMPILE_PHASE > TOTAL_COMPILE_PHASE) {
190201
CURRENT_COMPILE_PHASE = 1;
202+
hasFirstRawTime = false;
203+
}
191204
}
192205

193206
} // namespace onnx_mlir
@@ -813,6 +826,8 @@ static int emitOutputFiles(std::string outputNameNoExt,
813826
}
814827
}
815828
}
829+
showCompilePhase("Compilation completed");
830+
816831
return CompilerSuccess;
817832
} // end anonymous namespace
818833

test/mlir/driver/compile_phases.mlir

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// RUN: onnx-mlir %s -o %t| FileCheck %s && rm %t.so
22

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

0 commit comments

Comments
 (0)