Skip to content

Commit b5207cf

Browse files
committed
Don't log an error when there are no CUDA backend symbols to promote
load_library re-opens the library that holds the backend with RTLD_NOLOAD | RTLD_GLOBAL to make its symbols global. When the backend is linked into the executable, as in a statically linked runner, dlopen finds no library and sets no error, so every first load logged "Failed to promote symbols: (null)". The executable's symbols are already global then. Log an error only when dlopen reports one, and log the case where it finds no library at Info level.
1 parent 6a7dd63 commit b5207cf

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎backends/cuda/runtime/platform/platform.cpp‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,24 @@ executorch::runtime::Result<void*> load_library(
8686
Dl_info info;
8787
// Get info about a symbol we know exists in this backend library
8888
if (dladdr((void*)&load_library, &info) && info.dli_fname) {
89-
// Re-open with RTLD_GLOBAL | RTLD_NOLOAD to promote symbols
89+
// Re-open with RTLD_GLOBAL | RTLD_NOLOAD to promote symbols. Clear any
90+
// earlier error first, so dlerror() below reports only this call's.
91+
dlerror();
9092
void* handle =
9193
dlopen(info.dli_fname, RTLD_NOW | RTLD_GLOBAL | RTLD_NOLOAD);
9294
if (!handle) {
93-
ET_LOG(Error, "Failed to promote symbols: %s", dlerror());
95+
const char* error = dlerror();
96+
if (error != nullptr) {
97+
ET_LOG(Error, "Failed to promote symbols: %s", error);
98+
} else {
99+
// dlopen found no library to re-open and set no error. That is the
100+
// case when this backend is linked into the executable, whose
101+
// symbols are global already.
102+
ET_LOG(
103+
Info,
104+
"Not promoting symbols: %s is not loaded as a shared library",
105+
info.dli_fname);
106+
}
94107
} else {
95108
// Close the handle after successful promotion
96109
dlclose(handle);

0 commit comments

Comments
 (0)