Skip to content
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

[SYCL][UR] Log sycl-ls error messages related to adapter loading #17490

Merged
merged 1 commit into from
Mar 21, 2025
Merged
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
23 changes: 19 additions & 4 deletions sycl/tools/sycl-ls/sycl-ls.cpp
Original file line number Diff line number Diff line change
@@ -28,6 +28,11 @@
#ifdef _WIN32
#include <system_error>
#include <windows.h>

#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<backend, size_t> DeviceNums;

17 changes: 14 additions & 3 deletions unified-runtime/source/common/linux/ur_lib_loader.cpp
Original file line number Diff line number Diff line change
@@ -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;