Skip to content

Commit ed093ce

Browse files
committed
Alt design for RTCHashResult
Signed-off-by: Julian Oppermann <[email protected]>
1 parent 2d16c10 commit ed093ce

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,35 @@ class JITResult {
5858

5959
class RTCHashResult {
6060
public:
61-
explicit RTCHashResult(const char *PreprocLog)
62-
: Failed{true}, Hash{}, PreprocLog{PreprocLog} {}
63-
RTCHashResult(const char *Hash, const char *PreprocLog)
64-
: Failed{false}, Hash{Hash}, PreprocLog{PreprocLog} {}
61+
static RTCHashResult success(const char *Hash) {
62+
return RTCHashResult{/*Failed=*/false, Hash};
63+
}
64+
65+
static RTCHashResult failure(const char *PreprocLog) {
66+
return RTCHashResult{/*Failed=*/true, PreprocLog};
67+
}
6568

6669
bool failed() { return Failed; }
6770

68-
const char *getPreprocLog() { return PreprocLog.c_str(); }
71+
const char *getPreprocLog() {
72+
assert(failed() && "No preprocessor log");
73+
return PreprocLog.c_str();
74+
}
6975

7076
const char *getHash() {
7177
assert(!failed() && "No hash");
7278
return Hash.c_str();
7379
}
7480

7581
private:
82+
RTCHashResult(bool Failed, const char *Str) : Failed(Failed) {
83+
if (!Failed) {
84+
this->Hash = Str;
85+
} else {
86+
this->PreprocLog = Str;
87+
}
88+
}
89+
7690
bool Failed;
7791
sycl::detail::string Hash;
7892
sycl::detail::string PreprocLog;

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,18 @@ calculateHash(InMemoryFile SourceFile, View<InMemoryFile> IncludeFiles,
252252
View<const char *> UserArgs) {
253253
auto UserArgListOrErr = parseUserArgs(UserArgs);
254254
if (!UserArgListOrErr) {
255-
return errorTo<RTCHashResult>(UserArgListOrErr.takeError(),
256-
"Parsing of user arguments failed");
255+
return RTCHashResult::failure(
256+
formatError(UserArgListOrErr.takeError(),
257+
"Parsing of user arguments failed")
258+
.c_str());
257259
}
258260
llvm::opt::InputArgList UserArgList = std::move(*UserArgListOrErr);
259261

260262
auto Start = std::chrono::high_resolution_clock::now();
261263
auto HashOrError = calculateHash(SourceFile, IncludeFiles, UserArgList);
262264
if (!HashOrError) {
263-
return errorTo<RTCHashResult>(HashOrError.takeError(), "Hashing failed");
265+
return RTCHashResult::failure(
266+
formatError(HashOrError.takeError(), "Hashing failed").c_str());
264267
}
265268
auto Hash = *HashOrError;
266269
auto Stop = std::chrono::high_resolution_clock::now();
@@ -271,7 +274,7 @@ calculateHash(InMemoryFile SourceFile, View<InMemoryFile> IncludeFiles,
271274
<< int(HashTime.count()) << " ms\n";
272275
}
273276

274-
return RTCHashResult{Hash.c_str(), /*PreprocLog=*/""};
277+
return RTCHashResult::success(Hash.c_str());
275278
}
276279

277280
extern "C" KF_EXPORT_SYMBOL RTCResult

sycl/source/detail/jit_compiler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,8 +1284,9 @@ sycl_device_binaries jit_compiler::compileSYCL(
12841284
auto Result =
12851285
CalculateHashHandle(SourceFile, IncludeFilesView, UserArgsView);
12861286

1287-
appendToLog(Result.getPreprocLog());
1288-
if (!Result.failed()) {
1287+
if (Result.failed()) {
1288+
appendToLog(Result.getPreprocLog());
1289+
} else {
12891290
CacheKey = Result.getHash();
12901291
CachedIR = PersistentDeviceCodeCache::getDeviceCodeIRFromDisc(CacheKey);
12911292
}

0 commit comments

Comments
 (0)