Skip to content

Commit eba7b7e

Browse files
[OpenCL-aot] Return a Friendlier Error When Build Kernel Failed (#12124)
There is no useful information output, when compilation fails, unless "verbose" (-v) is set to true. This PR is to output the build log when compiling the kernel fails, and has no effect on the functionality of the original "-v" option. --------- Co-authored-by: Alexey Sachkov <[email protected]>
1 parent 7bd51c6 commit eba7b7e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

opencl/opencl-aot/source/main.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ int main(int Argc, char *Argv[]) {
593593
break;
594594
}
595595

596-
std::string CompilerBuildLog;
596+
std::string CompilerBuildLog, CompilerBuildLogMessage;
597597
std::tie(CompilerBuildLog, ErrorMessage, std::ignore) =
598598
getCompilerBuildLog(ProgramUPtr, DeviceId);
599599

@@ -604,18 +604,20 @@ int main(int Argc, char *Argv[]) {
604604
}
605605

606606
if (!CompilerBuildLog.empty()) {
607-
std::string CompilerBuildLogMessage = "\n" +
608-
CmdToCmdInfoMap[OptCommand].first +
609-
" log:\n" + CompilerBuildLog + '\n';
610-
if (!ErrorMessage.empty())
611-
std::cerr << CompilerBuildLogMessage;
612-
else
613-
logs() << CompilerBuildLogMessage;
607+
// According to the return value of getCompilerBuildLog(), ErrorMessage is
608+
// always empty if CompilerBuildLog is not empty.
609+
CompilerBuildLogMessage = "\n" + CmdToCmdInfoMap[OptCommand].first +
610+
" log:\n" + CompilerBuildLog + '\n';
611+
logs() << CompilerBuildLogMessage;
614612
}
615613

616614
if (clFailed(CLErr)) {
617615
std::string ErrMsg =
618616
"Failed to " + CmdToCmdInfoMap[OptCommand].first + ": ";
617+
// will print CompilerBuildLogMessage when build failed in case verbose is
618+
// false, in order to provide a friendlier compile error for users.
619+
if (!verbose)
620+
std::cerr << CompilerBuildLogMessage;
619621
std::cerr << formatCLError(ErrMsg, CLErr) << '\n';
620622
return CLErr;
621623
}

0 commit comments

Comments
 (0)