Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sycl/include/CL/sycl/detail/kernel_program_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ namespace detail {
class context_impl;
class KernelProgramCache {
public:
struct BuildResultT {
std::string Msg;
cl_int Code;
};

/// Denotes pointer to some entity with its state.
/// The pointer is not null if and only if the entity is usable.
/// State of the entity is provided by the user of cache instance.
Expand All @@ -33,6 +38,7 @@ class KernelProgramCache {
struct EntityWithState {
std::atomic<T *> Ptr;
std::atomic<int> State;
std::unique_ptr<BuildResultT> BuildResult;

EntityWithState(T* P, int S)
: Ptr{P}, State{S}
Expand Down
17 changes: 15 additions & 2 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,16 @@ waitUntilBuilt(KernelProgramCache &Cache,
return State == BS_Done || State == BS_Failed;
});

if (WithBuildState->BuildResult.get()) {
using BuildResult = KernelProgramCache::BuildResultT;
const BuildResult &Res = *WithBuildState->BuildResult.get();
throw ExceptionT(Res.Msg, Res.Code);
}

RetT *Result = WithBuildState->Ptr.load();

if (!Result)
throw ExceptionT("The other thread tried to build the program/kernel but "
"did not succeed.");
throw ExceptionT("Build of the program/kernel did not succeed previously.");

return Result;
}
Expand Down Expand Up @@ -190,6 +195,14 @@ RetT *getOrBuild(KernelProgramCache &KPCache, const KeyT &CacheKey,
KPCache.notifyAllBuild();

return Desired;
} catch (const exception &Ex) {
using BuildResultT = KernelProgramCache::BuildResultT;
WithState->BuildResult.reset(new BuildResultT{Ex.what(), Ex.get_cl_code()});
WithState->State.store(BS_Failed);

KPCache.notifyAllBuild();

std::rethrow_exception(std::current_exception());
} catch (...) {
WithState->State.store(BS_Failed);

Expand Down