Skip to content

Commit 39b3025

Browse files
authoredMar 21, 2025··
[SYCL][UR] Log sycl-ls error messages related to adapter loading (#17490)
Changes: * change the log level to "error" for all errors related to adapter dependencies during UR adapter loading * enable the printing of UR adapter errors in sycl-ls from platform::get_platforms() using environment variables With this PR, there will be no changes for the user in the default scenario where some adapters exist and some are missing (a missing adapter is not considered an error). In cases where a dependency is missing, the following example message will be displayed: ``` <LOADER>[ERROR]: failed to load adapter 'libur_adapter_level_zero.so.0' with error: libumf.so.0: cannot open shared object file: No such file or directory ``` Here is the message for missing symbols (a case where a dependency is not compatible with the rest of the libraries): ``` <LOADER>[ERROR]: failed to load adapter 'libur_adapter_level_zero.so.0' with error: /home/rrudnick/llvm/build/lib/libumf.so.0: version `UMF_0.10' not found (required by /home/rrudnick/llvm/build/lib/libur_adapter_level_zero.so.0) ```
1 parent 12803cd commit 39b3025

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed
 

‎sycl/tools/sycl-ls/sycl-ls.cpp

+19-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
#ifdef _WIN32
2929
#include <system_error>
3030
#include <windows.h>
31+
32+
#define setenv(name, var, ignore) _putenv_s(name, var)
33+
#define unsetenv(name) _putenv_s(name, "")
34+
#else
35+
3136
#endif
3237

3338
using namespace sycl;
@@ -261,11 +266,7 @@ static void printWarningIfFiltersUsed(bool &SuppressNumberPrinting) {
261266
// ONEAPI_DEVICE_SELECTOR, and SYCL_DEVICE_ALLOWLIST.
262267
static void unsetFilterEnvVars() {
263268
for (const auto &it : FilterEnvVars) {
264-
#ifdef _WIN32
265-
_putenv_s(it.c_str(), "");
266-
#else
267269
unsetenv(it.c_str());
268-
#endif
269270
}
270271
}
271272

@@ -363,8 +364,22 @@ int main(int argc, char **argv) {
363364
if (DiscardFilters && FilterEnvVars.size())
364365
unsetFilterEnvVars();
365366

367+
// Store the original UR_LOG_LOADER environment variable and enable printing
368+
// of any errors related to adapter loading.
369+
const char *orig_ur_log_loader_var = std::getenv("UR_LOG_LOADER");
370+
std::string orig_ur_log_loader_var_str;
371+
if (orig_ur_log_loader_var != NULL)
372+
orig_ur_log_loader_var_str.assign(orig_ur_log_loader_var);
373+
374+
setenv("UR_LOG_LOADER", "level:error;output:stderr", 1);
375+
366376
const auto &Platforms = platform::get_platforms();
367377

378+
if (orig_ur_log_loader_var == NULL)
379+
unsetenv("UR_LOG_LOADER");
380+
else
381+
setenv("UR_LOG_LOADER", orig_ur_log_loader_var_str.c_str(), 1);
382+
368383
// Keep track of the number of devices per backend
369384
std::map<backend, size_t> DeviceNums;
370385

‎unified-runtime/source/common/linux/ur_lib_loader.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,20 @@ LibLoader::loadAdapterLibrary(const char *name) {
5050
#endif
5151
HMODULE handle = dlopen(name, mode);
5252
if (!handle) {
53-
char *err = dlerror();
54-
logger::info("failed to load adapter '{}' with error: {}", name,
55-
err ? err : "unknown error");
53+
const char *err = dlerror();
54+
55+
// Check if the error string does not contain the adapter name or if it
56+
// contains a "required by" (missing symbol) message.
57+
if (err &&
58+
(strstr(err, name) == NULL || strstr(err, "required by") != NULL)) {
59+
// If the adapter cannot be loaded due to missing dependencies or any
60+
// other related error, it is considered as an error.
61+
logger::error("failed to load adapter '{}' with error: {}", name, err);
62+
} else {
63+
// Simply having the adapter library missing isn't an error.
64+
logger::info("failed to load adapter '{}' with error: {}", name,
65+
err ? err : "unknown error");
66+
}
5667
} else {
5768
#if defined(ADD_FULL_PATH_LOG)
5869
struct link_map *dlinfo_map;

0 commit comments

Comments
 (0)
Please sign in to comment.