Skip to content

Commit 2985a52

Browse files
author
Sergey Kanaev
committed
[SYCL] Store original message and code of build result
Signed-off-by: Sergey Kanaev <[email protected]>
1 parent 494c169 commit 2985a52

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

sycl/include/CL/sycl/detail/kernel_program_cache.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ namespace detail {
2525
class context_impl;
2626
class KernelProgramCache {
2727
public:
28+
struct BuildResultT {
29+
std::string Msg;
30+
cl_int Code;
31+
};
32+
2833
/// Denotes pointer to some entity with its state.
2934
/// The pointer is not null if and only if the entity is usable.
3035
/// State of the entity is provided by the user of cache instance.
@@ -33,6 +38,7 @@ class KernelProgramCache {
3338
struct EntityWithState {
3439
std::atomic<T *> Ptr;
3540
std::atomic<int> State;
41+
std::unique_ptr<BuildResultT> BuildResult;
3642

3743
EntityWithState(T* P, int S)
3844
: Ptr{P}, State{S}

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,16 @@ waitUntilBuilt(KernelProgramCache &Cache,
121121
return State == BS_Done || State == BS_Failed;
122122
});
123123

124+
if (WithBuildState->BuildResult.get()) {
125+
using BuildResult = KernelProgramCache::BuildResultT;
126+
const BuildResult &Res = *WithBuildState->BuildResult.get();
127+
throw ExceptionT(Res.Msg, Res.Code);
128+
}
129+
124130
RetT *Result = WithBuildState->Ptr.load();
125131

126132
if (!Result)
127-
throw ExceptionT("The other thread tried to build the program/kernel but "
128-
"did not succeed.");
133+
throw ExceptionT("Build of the program/kernel did not succeed previously.");
129134

130135
return Result;
131136
}
@@ -190,6 +195,14 @@ RetT *getOrBuild(KernelProgramCache &KPCache, const KeyT &CacheKey,
190195
KPCache.notifyAllBuild();
191196

192197
return Desired;
198+
} catch (const exception &Ex) {
199+
using BuildResultT = KernelProgramCache::BuildResultT;
200+
WithState->BuildResult.reset(new BuildResultT{Ex.what(), Ex.get_cl_code()});
201+
WithState->State.store(BS_Failed);
202+
203+
KPCache.notifyAllBuild();
204+
205+
std::rethrow_exception(std::current_exception());
193206
} catch (...) {
194207
WithState->State.store(BS_Failed);
195208

0 commit comments

Comments
 (0)