Skip to content

[SYCL][UR] Include backend name in exception messages #18889

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 1 commit into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 3 additions & 5 deletions sycl/include/sycl/detail/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,9 @@ class __SYCL_EXPORT tls_code_loc_t {
#define __SYCL_ASSERT(x) assert(x)
#endif // #ifdef __SYCL_DEVICE_ONLY__

#define __SYCL_UR_ERROR_REPORT \
"Native API failed. " /*__FILE__*/ \
/* TODO: replace __FILE__ to report only relative path*/ \
/* ":" __SYCL_STRINGIFY(__LINE__) ": " */ \
"Native API returns: "
#define __SYCL_UR_ERROR_REPORT(backend) \
std::string(sycl::detail::get_backend_name_no_vendor(backend)) + \
" backend failed with error: "

#include <sycl/exception.hpp>

Expand Down
15 changes: 10 additions & 5 deletions sycl/source/detail/adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <detail/config.hpp>
#include <detail/ur.hpp>
#include <sycl/backend_types.hpp>
#include <sycl/detail/common.hpp>
#include <sycl/detail/iostream_proxy.hpp>
#include <sycl/detail/type_traits.hpp>
Expand All @@ -23,12 +24,12 @@
#include <memory>
#include <mutex>

#define __SYCL_CHECK_UR_CODE_NO_EXC(expr) \
#define __SYCL_CHECK_UR_CODE_NO_EXC(expr, backend) \
{ \
auto code = expr; \
if (code != UR_RESULT_SUCCESS) { \
std::cerr << __SYCL_UR_ERROR_REPORT << sycl::detail::codeToString(code) \
<< std::endl; \
std::cerr << __SYCL_UR_ERROR_REPORT(backend) \
<< sycl::detail::codeToString(code) << std::endl; \
} \
}

Expand Down Expand Up @@ -74,7 +75,8 @@ class Adapter {
throw sycl::detail::set_ur_error(
sycl::exception(
sycl::make_error_code(errc),
__SYCL_UR_ERROR_REPORT + sycl::detail::codeToString(ur_result) +
__SYCL_UR_ERROR_REPORT(MBackend) +
sycl::detail::codeToString(ur_result) +
(message ? "\n" + std::string(message) + "(adapter error )" +
std::to_string(adapter_error) + "\n"
: std::string{})),
Expand All @@ -83,7 +85,7 @@ class Adapter {
if (ur_result != UR_RESULT_SUCCESS) {
throw sycl::detail::set_ur_error(
sycl::exception(sycl::make_error_code(errc),
__SYCL_UR_ERROR_REPORT +
__SYCL_UR_ERROR_REPORT(MBackend) +
sycl::detail::codeToString(ur_result)),
ur_result);
}
Expand Down Expand Up @@ -143,6 +145,9 @@ class Adapter {
checkUrResult<errc>(Err);
}

/// Returns the backend reported by the adapter.
backend getBackend() const { return MBackend; }

/// Tells if this adapter can serve specified backend.
/// For example, Unified Runtime adapter will be able to serve
/// multiple backends as determined by the platforms reported by the adapter.
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ device_impl::~device_impl() {
const AdapterPtr &Adapter = getAdapter();
ur_result_t Err =
Adapter->call_nocheck<UrApiKind::urDeviceRelease>(MDevice);
__SYCL_CHECK_UR_CODE_NO_EXC(Err);
__SYCL_CHECK_UR_CODE_NO_EXC(Err, Adapter->getBackend());
} catch (std::exception &e) {
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~device_impl", e);
}
Expand Down
7 changes: 4 additions & 3 deletions sycl/source/detail/error_handling/error_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "error_handling.hpp"
#include "sycl/detail/common.hpp"

#include <detail/adapter.hpp>
#include <sycl/backend_types.hpp>
Expand Down Expand Up @@ -69,8 +70,7 @@ void handleOutOfResources(const device_impl &DeviceImpl,
// Fallback
constexpr ur_result_t Error = UR_RESULT_ERROR_OUT_OF_RESOURCES;
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),
"UR backend failed. UR backend returns:" +
codeToString(Error));
__SYCL_UR_ERROR_REPORT(Backend) + codeToString(Error));
}

void handleInvalidWorkGroupSize(const device_impl &DeviceImpl,
Expand Down Expand Up @@ -459,7 +459,8 @@ void handleErrorOrWarning(ur_result_t Error, const device_impl &DeviceImpl,
default:
throw detail::set_ur_error(
exception(make_error_code(errc::runtime),
"UR error: " + sycl::detail::codeToString(Error)),
__SYCL_UR_ERROR_REPORT(DeviceImpl.getBackend()) +
sycl::detail::codeToString(Error)),
Error);
}
}
Expand Down
4 changes: 2 additions & 2 deletions sycl/source/detail/kernel_program_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class KernelProgramCache {
ur_result_t Err =
AdapterSharedPtr->call_nocheck<UrApiKind::urProgramRelease>(
Val);
__SYCL_CHECK_UR_CODE_NO_EXC(Err);
__SYCL_CHECK_UR_CODE_NO_EXC(Err, AdapterSharedPtr->getBackend());
}
}
} catch (std::exception &e) {
Expand Down Expand Up @@ -214,7 +214,7 @@ class KernelProgramCache {
ur_result_t Err =
AdapterSharedPtr->call_nocheck<UrApiKind::urKernelRelease>(
Val.first);
__SYCL_CHECK_UR_CODE_NO_EXC(Err);
__SYCL_CHECK_UR_CODE_NO_EXC(Err, AdapterSharedPtr->getBackend());
}
}
} catch (std::exception &e) {
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 @@ -269,7 +269,7 @@ class queue_impl : public std::enable_shared_from_this<queue_impl> {
// ->call<>() instead of ->call_nocheck<>() above.
if (status != UR_RESULT_SUCCESS &&
status != UR_RESULT_ERROR_UNINITIALIZED) {
__SYCL_CHECK_UR_CODE_NO_EXC(status);
__SYCL_CHECK_UR_CODE_NO_EXC(status, getAdapter()->getBackend());
}
} catch (std::exception &e) {
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~queue_impl", e);
Expand Down
10 changes: 6 additions & 4 deletions sycl/source/detail/scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,12 @@ void Scheduler::enqueueCommandForCG(EventImplPtr NewEvent,
NewCmd, Lock, Res, ToCleanUp, NewCmd, Blocking);
if (!Enqueued && EnqueueResultT::SyclEnqueueFailed == Res.MResult) {
throw sycl::detail::set_ur_error(
sycl::exception(sycl::make_error_code(errc::runtime),
std::string("Enqueue process failed.\n") +
__SYCL_UR_ERROR_REPORT +
sycl::detail::codeToString(Res.MErrCode)),
sycl::exception(
sycl::make_error_code(errc::runtime),
std::string("Enqueue process failed.\n") +
__SYCL_UR_ERROR_REPORT(
NewCmd->getWorkerContext()->getBackend()) +
sycl::detail::codeToString(Res.MErrCode)),
Res.MErrCode);
}
} catch (...) {
Expand Down
8 changes: 7 additions & 1 deletion sycl/source/detail/ur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ std::vector<AdapterPtr> &initializeUr(ur_loader_config_handle_t LoaderConfig) {

static void initializeAdapters(std::vector<AdapterPtr> &Adapters,
ur_loader_config_handle_t LoaderConfig) {
#define CHECK_UR_SUCCESS(Call) __SYCL_CHECK_UR_CODE_NO_EXC(Call)
#define CHECK_UR_SUCCESS(Call) \
{ \
if (ur_result_t error = Call) { \
std::cerr << "UR adapter initialization failed: " \
<< sycl::detail::codeToString(error) << std::endl; \
} \
}

UrFuncInfo<UrApiKind::urLoaderConfigCreate> loaderConfigCreateInfo;
auto loaderConfigCreate =
Expand Down
2 changes: 1 addition & 1 deletion sycl/unittests/xpti_trace/QueueApiFailures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class QueueApiFailures : public ::testing::Test {
const std::string TestKernelLocationMessage = BuildCodeLocationMessage(
TestKI::getFileName(), TestKI::getFunctionName(), TestKI::getLineNumber(),
TestKI::getColumnNumber());
const std::string URLevelFailMessage = "Native API failed";
const std::string URLevelFailMessage = " backend failed with error: ";
const std::string SYCLLevelFailMessage = "Enqueue process failed";
};

Expand Down