Skip to content

Commit 84ee39a

Browse files
authored
[SYCL] Implement more verbose error handling. (#4013)
This ensures that no exception is silently ignored by sycl. This also includes API names and error codes in the error messages. Signed-off-by: rehana begam <[email protected]>
1 parent c19294f commit 84ee39a

File tree

8 files changed

+29
-9
lines changed

8 files changed

+29
-9
lines changed

sycl/source/detail/global_handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void shutdown() {
9090
// some parameters in the plugin tear-down process.
9191
// Currently, it is not used.
9292
void *PluginParameter = nullptr;
93-
Plugin.call_nocheck<PiApiKind::piTearDown>(PluginParameter);
93+
Plugin.call<PiApiKind::piTearDown>(PluginParameter);
9494
Plugin.unload();
9595
}
9696
GlobalHandler::instance().MPlugins.Inst.reset(nullptr);

sycl/source/detail/memory_manager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ void *MemoryManager::allocateMemSubBuffer(ContextImplPtr TargetContext,
230230
"Specified offset of the sub-buffer being constructed is not a "
231231
"multiple of the memory base address alignment",
232232
PI_INVALID_VALUE);
233+
234+
if (Error != PI_SUCCESS) {
235+
Plugin.reportPiError(Error, "allocateMemSubBuffer()");
236+
}
237+
233238
return NewMem;
234239
}
235240

sycl/source/detail/pi.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ void contextSetExtendedDeleter(const cl::sycl::context &context,
141141
auto impl = getSyclObjImpl(context);
142142
auto contextHandle = reinterpret_cast<pi_context>(impl->getHandleRef());
143143
auto plugin = impl->getPlugin();
144-
plugin.call_nocheck<PiApiKind::piextContextSetExtendedDeleter>(
145-
contextHandle, func, user_data);
144+
plugin.call<PiApiKind::piextContextSetExtendedDeleter>(contextHandle, func,
145+
user_data);
146146
}
147147

148148
std::string platformInfoToString(pi_platform_info info) {

sycl/source/detail/plugin.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ class plugin {
5656
__SYCL_CHECK_OCL_CODE_THROW(pi_result, Exception);
5757
}
5858

59+
void reportPiError(RT::PiResult pi_result, const char *context) const {
60+
if (pi_result != PI_SUCCESS) {
61+
throw cl::sycl::runtime_error(
62+
std::string(context) + " API failed with error: " +
63+
cl::sycl::detail::codeToString(pi_result),
64+
pi_result);
65+
}
66+
}
67+
5968
/// Calls the PiApi, traces the call, and returns the result.
6069
///
6170
/// Usage:
@@ -66,6 +75,7 @@ class plugin {
6675
/// \endcode
6776
///
6877
/// \sa plugin::checkPiResult
78+
6979
template <PiApiKind PiApiOffset, typename... ArgsT>
7080
RT::PiResult call_nocheck(ArgsT... Args) const {
7181
RT::PiFuncInfo<PiApiOffset> PiCallInfo;

sycl/source/detail/program_impl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ void program_impl::create_cl_program_with_source(const std::string &Source) {
360360
"program::compile_with_source is not supported by the selected backend",
361361
PI_INVALID_OPERATION);
362362
}
363+
364+
if (Err != PI_SUCCESS) {
365+
Plugin.reportPiError(Err, "create_cl_program_with_source()");
366+
}
363367
}
364368

365369
void program_impl::compile(const std::string &Options) {

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,10 +1502,11 @@ ProgramManager::link(const std::vector<device_image_plain> &DeviceImages,
15021502
/*user_data=*/nullptr, &LinkedProg);
15031503

15041504
if (Error != PI_SUCCESS) {
1505-
const std::string ErrorMsg =
1506-
LinkedProg ? getProgramBuildLog(LinkedProg, ContextImpl)
1507-
: "Online link operation failed";
1508-
throw sycl::exception(make_error_code(errc::build), ErrorMsg);
1505+
if (LinkedProg) {
1506+
const string_class ErrorMsg = getProgramBuildLog(LinkedProg, ContextImpl);
1507+
throw sycl::exception(make_error_code(errc::build), ErrorMsg);
1508+
}
1509+
Plugin.reportPiError(Error, "link()");
15091510
}
15101511

15111512
std::vector<kernel_id> KernelIDs;

sycl/source/detail/queue_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class queue_impl {
263263

264264
// If creating out-of-order queue failed and this property is not
265265
// supported (for example, on FPGA), it will return
266-
// CL_INVALID_QUEUE_PROPERTIES and will try to create in-order queue.
266+
// PI_INVALID_QUEUE_PROPERTIES and will try to create in-order queue.
267267
if (MSupportOOO && Error == PI_INVALID_QUEUE_PROPERTIES) {
268268
MSupportOOO = false;
269269
Queue = createQueue(QueueOrder::Ordered);

sycl/source/detail/usm/usm_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ alloc get_pointer_type(const void *Ptr, const context &Ctxt) {
351351
return alloc::unknown;
352352
// otherwise PI_SUCCESS is expected
353353
if (Err != PI_SUCCESS) {
354-
throw runtime_error("Error querying USM pointer: ", Err);
354+
Plugin.reportPiError(Err, "get_pointer_type()");
355355
}
356356

357357
alloc ResultAlloc;

0 commit comments

Comments
 (0)