Skip to content

Commit

Permalink
Emit print statement only when the verbose option is in effect. (llvm…
Browse files Browse the repository at this point in the history
…#1097)

Signed-off-by: Ettore Tiotto <etiotto@ca.ibm.com>

Co-authored-by: Alexandre Eichenberger <alexe@us.ibm.com>
  • Loading branch information
Ettore Tiotto and AlexandreEichenberger authored Jan 14, 2022
1 parent 9f90fb7 commit 76fce87
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
28 changes: 14 additions & 14 deletions src/Compiler/CompilerUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ struct Command {
// restored after the command is executed.
void exec(std::string wdir = "") const {
auto argsRef = std::vector<llvm::StringRef>(_args.begin(), _args.end());
bool verbose = false;
if (const auto &verboseStr = getEnvVar("ONNX_MLIR_VERBOSE"))
istringstream(verboseStr.getValue()) >> verbose;

// If a work directory is specified, save the current work directory
// and switch into it. Note that if wdir is empty, new_wdir will be
Expand All @@ -277,8 +274,7 @@ struct Command {
exit(ec.value());
}

// If in verbose mode, print out command before execution.
if (VerboseOutput || verbose)
if (VerboseOutput)
llvm::errs() << "[" << StringRef(new_wdir).str() << "]" << _path << ": "
<< llvm::join(argsRef, " ") << "\n";

Expand Down Expand Up @@ -741,17 +737,20 @@ void emitOutputFiles(string outputBaseName, EmissionTargetType emissionTarget,
if (keepFiles(KeepFilesOfType::MLIR)) {
outputCode(module, outputBaseName, ".llvm.mlir");
}
printf("Shared library %s has been compiled.\n", sharedLib.c_str());
if (VerboseOutput)
printf("Shared library %s has been compiled.\n", sharedLib.c_str());
} else if (emissionTarget == EmitJNI) {
compileModuleToJniJar(module, outputBaseName);
if (keepFiles(KeepFilesOfType::MLIR))
outputCode(module, outputBaseName, ".llvm.mlir");
printf("JNI archive %s.jar has been compiled.\n", outputBaseName.c_str());
if (VerboseOutput)
printf("JNI archive %s.jar has been compiled.\n", outputBaseName.c_str());
} else {
// Emit the version with all constants included.
outputCode(module, outputBaseName, ".onnx.mlir");
printf("Full MLIR code written to: \n\t%s\n\n",
(outputBaseName + ".onnx.mlir").c_str());
if (VerboseOutput)
printf("Full MLIR code written to: \n\t%s\n\n",
(outputBaseName + ".onnx.mlir").c_str());

// Apply specific passes to clean up the code where necessary.
mlir::PassManager cleanSourcePM(
Expand All @@ -767,11 +766,12 @@ void emitOutputFiles(string outputBaseName, EmissionTargetType emissionTarget,
if (mlir::failed(cleanSourcePM.run(*module)))
llvm::errs() << "Could not apply simplification passes.\n";
outputCode(module, outputBaseName, ".tmp");
printf("Constant-free MLIR Code written to: \n\t%s\n\n",
(outputBaseName + ".tmp").c_str());

printf("Use:\n\t%s\nto continue lowering the code to other dialects.\n",
(outputBaseName + ".onnx.mlir").c_str());
if (VerboseOutput) {
printf("Constant-free MLIR Code written to: \n\t%s\n\n",
(outputBaseName + ".tmp").c_str());
printf("Use:\n\t%s\nto continue lowering the code to other dialects.\n",
(outputBaseName + ".onnx.mlir").c_str());
}
}
}
}
Expand Down
23 changes: 13 additions & 10 deletions test/backend/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def compile_model(model, emit):
model_dir = os.path.join(result_dir, name)
os.makedirs(model_dir, exist_ok=True)

print("ONNX_HOME=" + os.getenv("ONNX_HOME"))
if args.verbose:
print("ONNX_HOME=" + os.getenv("ONNX_HOME"))

# For real models, the onnx files are downloaded, no need to save again.
if (name + "_cpu") in list(map(lambda x: x[0], variables.real_model_tests)):
Expand All @@ -86,15 +87,16 @@ def compile_model(model, emit):
# Save model to disk as model_name.onnx.
onnx.save(model, model_name)

print(
(
"Success downloading/saving "
if os.path.exists(model_name)
else "Failure downloading/saving "
if args.verbose:
print(
(
"Success downloading/saving "
if os.path.exists(model_name)
else "Failure downloading/saving "
)
+ model_name,
file=sys.stderr,
)
+ model_name,
file=sys.stderr,
)

exec_base = os.path.join(model_dir, name)
exec_name = exec_base + suffix[emit]
Expand All @@ -114,7 +116,8 @@ def compile_model(model, emit):

# Call frontend to process model_name.onnx, bit code will be generated.
dynamic_inputs_dims = determine_dynamic_parameters(name)
print("cwd: " + os.getcwd(), file=sys.stderr)
if args.verbose:
print("cwd: " + os.getcwd(), file=sys.stderr)
execute_commands(command_list, dynamic_inputs_dims)

# Check if compiled model file exists
Expand Down

0 comments on commit 76fce87

Please sign in to comment.