Skip to content

Commit b8b5d86

Browse files
committed
Throw exception with errc::invalid when unsupported build option is detected
Signed-off-by: Julian Oppermann <[email protected]>
1 parent cef9fc0 commit b8b5d86

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

sycl-jit/jit-compiler/include/KernelFusion.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,32 +86,37 @@ class RTCHashResult {
8686
sycl::detail::string HashOrLog;
8787
};
8888

89+
enum class RTCErrorCode { SUCCESS, BUILD, INVALID };
90+
8991
class RTCResult {
9092
public:
91-
explicit RTCResult(const char *BuildLog)
92-
: Failed{true}, BundleInfo{}, BuildLog{BuildLog} {}
93+
explicit RTCResult(const char *BuildLog,
94+
RTCErrorCode ErrorCode = RTCErrorCode::BUILD)
95+
: ErrorCode{ErrorCode}, BundleInfo{}, BuildLog{BuildLog} {
96+
assert(ErrorCode != RTCErrorCode::SUCCESS);
97+
}
9398

9499
RTCResult(RTCBundleInfo &&BundleInfo, RTCDeviceCodeIR &&DeviceCodeIR,
95100
const char *BuildLog)
96-
: Failed{false}, BundleInfo{std::move(BundleInfo)},
101+
: ErrorCode{RTCErrorCode::SUCCESS}, BundleInfo{std::move(BundleInfo)},
97102
DeviceCodeIR(std::move(DeviceCodeIR)), BuildLog{BuildLog} {}
98103

99-
bool failed() const { return Failed; }
104+
RTCErrorCode getErrorCode() const { return ErrorCode; }
100105

101106
const char *getBuildLog() const { return BuildLog.c_str(); }
102107

103108
const RTCBundleInfo &getBundleInfo() const {
104-
assert(!failed() && "No bundle info");
109+
assert(ErrorCode == RTCErrorCode::SUCCESS && "No bundle info");
105110
return BundleInfo;
106111
}
107112

108113
const RTCDeviceCodeIR &getDeviceCodeIR() const {
109-
assert(!failed() && "No device code IR");
114+
assert(ErrorCode == RTCErrorCode::SUCCESS && "No device code IR");
110115
return DeviceCodeIR;
111116
}
112117

113118
private:
114-
bool Failed;
119+
RTCErrorCode ErrorCode;
115120
RTCBundleInfo BundleInfo;
116121
RTCDeviceCodeIR DeviceCodeIR;
117122
sycl::detail::string BuildLog;

sycl-jit/jit-compiler/lib/KernelFusion.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ static std::string formatError(llvm::Error &&Err, const std::string &Msg) {
4545
return ErrMsg.str();
4646
}
4747

48-
template <typename ResultType>
49-
static ResultType errorTo(llvm::Error &&Err, const std::string &Msg) {
48+
template <typename ResultType, typename... ExtraArgTypes>
49+
static ResultType errorTo(llvm::Error &&Err, const std::string &Msg,
50+
ExtraArgTypes... ExtraArgs) {
5051
// Cannot throw an exception here if LLVM itself is compiled without exception
5152
// support.
52-
return ResultType{formatError(std::move(Err), Msg).c_str()};
53+
return ResultType{formatError(std::move(Err), Msg).c_str(), ExtraArgs...};
5354
}
5455

5556
static std::vector<jit_compiler::NDRange>
@@ -288,7 +289,8 @@ compileSYCL(InMemoryFile SourceFile, View<InMemoryFile> IncludeFiles,
288289
auto UserArgListOrErr = parseUserArgs(UserArgs);
289290
if (!UserArgListOrErr) {
290291
return errorTo<RTCResult>(UserArgListOrErr.takeError(),
291-
"Parsing of user arguments failed");
292+
"Parsing of user arguments failed",
293+
RTCErrorCode::INVALID);
292294
}
293295
llvm::opt::InputArgList UserArgList = std::move(*UserArgListOrErr);
294296

sycl/source/detail/jit_compiler.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,9 +1302,16 @@ std::pair<sycl_device_binaries, std::string> jit_compiler::compileSYCL(
13021302
auto Result = CompileSYCLHandle(SourceFile, IncludeFilesView, UserArgsView,
13031303
CachedIR, /*SaveIR=*/!CacheKey.empty());
13041304

1305-
appendToLog(Result.getBuildLog());
1306-
if (Result.failed()) {
1307-
throw sycl::exception(sycl::errc::build, Result.getBuildLog());
1305+
const char *BuildLog = Result.getBuildLog();
1306+
appendToLog(BuildLog);
1307+
switch (Result.getErrorCode()) {
1308+
using RTCErrC = ::jit_compiler::RTCErrorCode;
1309+
case RTCErrC::BUILD:
1310+
throw sycl::exception(sycl::errc::build, BuildLog);
1311+
case RTCErrC::INVALID:
1312+
throw sycl::exception(sycl::errc::invalid, BuildLog);
1313+
default: // RTCErrC::SUCCESS
1314+
break;
13081315
}
13091316

13101317
const auto &IR = Result.getDeviceCodeIR();

sycl/test-e2e/KernelCompiler/sycl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ int test_unsupported_options() {
558558
syclex::build_options{"-fsycl-targets=intel_gpu_pvc"}});
559559
assert(false && "unsupported option not detected");
560560
} catch (sycl::exception &e) {
561-
assert(e.code() == sycl::errc::build);
561+
assert(e.code() == sycl::errc::invalid);
562562
assert(std::string(e.what()).find("Parsing of user arguments failed") !=
563563
std::string::npos);
564564
}

0 commit comments

Comments
 (0)