Skip to content

[SYCL] Implement more verbose error handling. #4013

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

Merged
merged 16 commits into from
Jul 10, 2021
Merged
2 changes: 1 addition & 1 deletion sycl/source/detail/global_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void shutdown() {
// some parameters in the plugin tear-down process.
// Currently, it is not used.
void *PluginParameter = nullptr;
Plugin.call_nocheck<PiApiKind::piTearDown>(PluginParameter);
Plugin.call<PiApiKind::piTearDown>(PluginParameter);
Plugin.unload();
}
GlobalHandler::instance().MPlugins.reset(nullptr);
Expand Down
5 changes: 5 additions & 0 deletions sycl/source/detail/memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ void *MemoryManager::allocateMemSubBuffer(ContextImplPtr TargetContext,
"Specified offset of the sub-buffer being constructed is not a "
"multiple of the memory base address alignment",
PI_INVALID_VALUE);

if (Error != PI_SUCCESS) {
Plugin.reportPiError(Error, "allocateMemSubBuffer()");
}

return NewMem;
}

Expand Down
4 changes: 2 additions & 2 deletions sycl/source/detail/pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ void contextSetExtendedDeleter(const cl::sycl::context &context,
auto impl = getSyclObjImpl(context);
auto contextHandle = reinterpret_cast<pi_context>(impl->getHandleRef());
auto plugin = impl->getPlugin();
plugin.call_nocheck<PiApiKind::piextContextSetExtendedDeleter>(
contextHandle, func, user_data);
plugin.call<PiApiKind::piextContextSetExtendedDeleter>(contextHandle, func,
user_data);
}

std::string platformInfoToString(pi_platform_info info) {
Expand Down
10 changes: 10 additions & 0 deletions sycl/source/detail/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ class plugin {
__SYCL_CHECK_OCL_CODE_THROW(pi_result, Exception);
}

void reportPiError(RT::PiResult pi_result, const char *context) const {
if (pi_result != PI_SUCCESS) {
throw cl::sycl::runtime_error(
std::string(context) + " API failed with error: " +
cl::sycl::detail::codeToString(pi_result),
pi_result);
}
}

/// Calls the PiApi, traces the call, and returns the result.
///
/// Usage:
Expand All @@ -66,6 +75,7 @@ class plugin {
/// \endcode
///
/// \sa plugin::checkPiResult

template <PiApiKind PiApiOffset, typename... ArgsT>
RT::PiResult call_nocheck(ArgsT... Args) const {
RT::PiFuncInfo<PiApiOffset> PiCallInfo;
Expand Down
4 changes: 4 additions & 0 deletions sycl/source/detail/program_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ void program_impl::create_cl_program_with_source(const std::string &Source) {
"program::compile_with_source is not supported by the selected backend",
PI_INVALID_OPERATION);
}

if (Err != PI_SUCCESS) {
Plugin.reportPiError(Err, "create_cl_program_with_source()");
}
}

void program_impl::compile(const std::string &Options) {
Expand Down
9 changes: 5 additions & 4 deletions sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1497,10 +1497,11 @@ ProgramManager::link(const std::vector<device_image_plain> &DeviceImages,
/*user_data=*/nullptr, &LinkedProg);

if (Error != PI_SUCCESS) {
const std::string ErrorMsg =
LinkedProg ? getProgramBuildLog(LinkedProg, ContextImpl)
: "Online link operation failed";
throw sycl::exception(make_error_code(errc::build), ErrorMsg);
if (LinkedProg) {
const string_class ErrorMsg = getProgramBuildLog(LinkedProg, ContextImpl);
throw sycl::exception(make_error_code(errc::build), ErrorMsg);
}
Plugin.reportPiError(Error, "link()");
}

std::vector<kernel_id> KernelIDs;
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class queue_impl {

// If creating out-of-order queue failed and this property is not
// supported (for example, on FPGA), it will return
// CL_INVALID_QUEUE_PROPERTIES and will try to create in-order queue.
// PI_INVALID_QUEUE_PROPERTIES and will try to create in-order queue.
if (MSupportOOO && Error == PI_INVALID_QUEUE_PROPERTIES) {
MSupportOOO = false;
Queue = createQueue(QueueOrder::Ordered);
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/usm/usm_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ alloc get_pointer_type(const void *Ptr, const context &Ctxt) {
return alloc::unknown;
// otherwise PI_SUCCESS is expected
if (Err != PI_SUCCESS) {
throw runtime_error("Error querying USM pointer: ", Err);
Plugin.reportPiError(Err, "get_pointer_type()");
}

alloc ResultAlloc;
Expand Down