-
Notifications
You must be signed in to change notification settings - Fork 798
[SYCL] Preserve original message and code of kernel/program build result #1108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
2985a52
eb8f4f5
96e92a8
5495889
0c19b88
5e64424
be30bc3
0a4dbad
44fa8c5
4e7bcb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,29 +25,42 @@ namespace detail { | |
| class context_impl; | ||
| class KernelProgramCache { | ||
| public: | ||
| /// Denotes pointer to some entity with its state. | ||
| /// Denotes build error data. The data is filled in from cl::sycl::exception | ||
| /// class instance. | ||
| struct BuildError { | ||
| std::string Msg; | ||
| pi_int32 Code; | ||
|
|
||
| /// Equals to true if the Msg and Code are initialized. This flag is added | ||
| /// due to possibility of Code equal to zero even if there is a | ||
| /// cl::sycl::exception thrown | ||
| bool FilledIn; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe it may be. Though, flag is more explicit data and more understandable to read. On the other hand the struct may have a distinct method
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for replacing this flag with public member function. |
||
| }; | ||
|
|
||
| /// Denotes pointer to some entity with its general state and build error. | ||
| /// 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. | ||
| /// Currently there is only a single user - ProgramManager class. | ||
| template<typename T> | ||
| struct EntityWithState { | ||
| struct BuildResult { | ||
| std::atomic<T *> Ptr; | ||
| std::atomic<int> State; | ||
| BuildError Error; | ||
|
|
||
| EntityWithState(T* P, int S) | ||
| : Ptr{P}, State{S} | ||
| BuildResult(T* P, int S) | ||
| : Ptr{P}, State{S}, Error{"", 0, false} | ||
| {} | ||
| }; | ||
|
|
||
| using PiProgramT = std::remove_pointer<RT::PiProgram>::type; | ||
| using PiProgramPtrT = std::atomic<PiProgramT *>; | ||
| using ProgramWithBuildStateT = EntityWithState<PiProgramT>; | ||
| using ProgramWithBuildStateT = BuildResult<PiProgramT>; | ||
| using ProgramCacheT = std::map<OSModuleHandle, ProgramWithBuildStateT>; | ||
| using ContextPtr = context_impl *; | ||
|
|
||
| using PiKernelT = std::remove_pointer<RT::PiKernel>::type; | ||
| using PiKernelPtrT = std::atomic<PiKernelT *>; | ||
| using KernelWithBuildStateT = EntityWithState<PiKernelT>; | ||
| using KernelWithBuildStateT = BuildResult<PiKernelT>; | ||
| using KernelByNameT = std::map<string_class, KernelWithBuildStateT>; | ||
| using KernelCacheT = std::map<RT::PiProgram, KernelByNameT>; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // RUN: %clangxx -fsycl %s -o %t.out | ||
| // RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
|
|
||
| #include <CL/sycl.hpp> | ||
| // FIXME do not use internal methods in tests. | ||
| #include <CL/sycl/detail/program_impl.hpp> | ||
|
|
||
| namespace RT = cl::sycl::RT; | ||
| namespace detail = cl::sycl::detail; | ||
| namespace pi = detail::pi; | ||
|
|
||
| using ProgramCacheT = detail::KernelProgramCache::ProgramCacheT; | ||
s-kanaev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| using KernelCacheT = detail::KernelProgramCache::KernelCacheT; | ||
|
|
||
| class Functor { | ||
| public: | ||
| void operator()(cl::sycl::item<1> Item) { (void)Item; } | ||
| }; | ||
|
|
||
| SYCL_EXTERNAL | ||
| void undefined(); | ||
|
|
||
| void test() { | ||
| cl::sycl::queue Queue; | ||
|
|
||
| auto Kernel = []() { | ||
| #ifdef __SYCL_DEVICE_ONLY__ | ||
| undefined(); | ||
| #endif | ||
| }; | ||
|
|
||
| std::string Msg; | ||
| int Result; | ||
|
|
||
| for (int Idx = 0; Idx < 2; ++Idx) { | ||
| try { | ||
| Queue.submit([&](cl::sycl::handler &CGH) { | ||
| CGH.single_task<class SingleTask>(Kernel); | ||
| }); | ||
| assert(false && "There must be compilation error"); | ||
| } catch (const cl::sycl::compile_program_error &e) { | ||
| fprintf(stderr, "Exception: %s, %d\n", e.what(), e.get_cl_code()); | ||
| if (Idx == 0) { | ||
| Msg = e.what(); | ||
| Result = e.get_cl_code(); | ||
| } else { | ||
| // Exception constantly adds info on its error code in the message | ||
| assert(Msg.find_first_of(e.what()) == 0 && "Exception text differs"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| assert(Result == e.get_cl_code() && "Exception code differs"); | ||
| } | ||
| } catch (...) { | ||
| assert(false && "There must be cl::sycl::compile_program_error"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| int main() { | ||
| test(); | ||
|
|
||
| return 0; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.