diff --git a/sycl/tools/sycl-ls/sycl-ls.cpp b/sycl/tools/sycl-ls/sycl-ls.cpp index 3652a1e75e9c0..e92e86bc675ec 100644 --- a/sycl/tools/sycl-ls/sycl-ls.cpp +++ b/sycl/tools/sycl-ls/sycl-ls.cpp @@ -28,6 +28,11 @@ #ifdef _WIN32 #include #include + +#define setenv(name, var, ignore) _putenv_s(name, var) +#define unsetenv(name) _putenv_s(name, "") +#else + #endif using namespace sycl; @@ -261,11 +266,7 @@ static void printWarningIfFiltersUsed(bool &SuppressNumberPrinting) { // ONEAPI_DEVICE_SELECTOR, and SYCL_DEVICE_ALLOWLIST. static void unsetFilterEnvVars() { for (const auto &it : FilterEnvVars) { -#ifdef _WIN32 - _putenv_s(it.c_str(), ""); -#else unsetenv(it.c_str()); -#endif } } @@ -363,8 +364,22 @@ int main(int argc, char **argv) { if (DiscardFilters && FilterEnvVars.size()) unsetFilterEnvVars(); + // Store the original UR_LOG_LOADER environment variable and enable printing + // of any errors related to adapter loading. + const char *orig_ur_log_loader_var = std::getenv("UR_LOG_LOADER"); + std::string orig_ur_log_loader_var_str; + if (orig_ur_log_loader_var != NULL) + orig_ur_log_loader_var_str.assign(orig_ur_log_loader_var); + + setenv("UR_LOG_LOADER", "level:error;output:stderr", 1); + const auto &Platforms = platform::get_platforms(); + if (orig_ur_log_loader_var == NULL) + unsetenv("UR_LOG_LOADER"); + else + setenv("UR_LOG_LOADER", orig_ur_log_loader_var_str.c_str(), 1); + // Keep track of the number of devices per backend std::map DeviceNums; diff --git a/unified-runtime/source/common/linux/ur_lib_loader.cpp b/unified-runtime/source/common/linux/ur_lib_loader.cpp index 80281544487c9..65e67bba048ef 100644 --- a/unified-runtime/source/common/linux/ur_lib_loader.cpp +++ b/unified-runtime/source/common/linux/ur_lib_loader.cpp @@ -50,9 +50,20 @@ LibLoader::loadAdapterLibrary(const char *name) { #endif HMODULE handle = dlopen(name, mode); if (!handle) { - char *err = dlerror(); - logger::info("failed to load adapter '{}' with error: {}", name, - err ? err : "unknown error"); + const char *err = dlerror(); + + // Check if the error string does not contain the adapter name or if it + // contains a "required by" (missing symbol) message. + if (err && + (strstr(err, name) == NULL || strstr(err, "required by") != NULL)) { + // If the adapter cannot be loaded due to missing dependencies or any + // other related error, it is considered as an error. + logger::error("failed to load adapter '{}' with error: {}", name, err); + } else { + // Simply having the adapter library missing isn't an error. + logger::info("failed to load adapter '{}' with error: {}", name, + err ? err : "unknown error"); + } } else { #if defined(ADD_FULL_PATH_LOG) struct link_map *dlinfo_map;