-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Implement PosixEnv::GetRuntimePath to enable AutoEP tests on Linux/MacOS #26424
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ limitations under the License. | |
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <sys/mman.h> | ||
| #include <filesystem> | ||
| #if !defined(_AIX) | ||
| #include <sys/syscall.h> | ||
| #endif | ||
|
|
@@ -592,6 +593,31 @@ class PosixEnv : public Env { | |
| return val == NULL ? std::string() : std::string(val); | ||
| } | ||
|
|
||
| // Return the path of the executable/shared library for the current running code. This is to make it | ||
| // possible to load other shared libraries installed next to our core runtime code. | ||
| PathString GetRuntimePath() const override { | ||
| Dl_info dl_info{}; | ||
| // Must be one of the symbols exported in libonnxruntime.{so,dynlib}. | ||
| void* symbol_from_this_library = dlsym(RTLD_DEFAULT, "OrtGetApiBase"); | ||
| PathString runtime_path; | ||
| // We will find OrtGetApiBase if onnxruntime is loaded as a shared library | ||
| if (dladdr(symbol_from_this_library, &dl_info) && dl_info.dli_fname) { | ||
| // Converting to absolute path since running a program with and without gdb attached can make a difference whether | ||
| // dli_fname will be absolute or relative. Converting to absolute for consistent result | ||
| runtime_path = PathString(std::filesystem::absolute(std::filesystem::path(dl_info.dli_fname).parent_path().string())) + "/"; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw that returning an absolute vs an relative path makes a difference on whether ORT will attempt to call |
||
| } else { | ||
| // else use path of current executable to mirror Windows behavior | ||
| #if __linux__ | ||
| runtime_path = PathString(std::filesystem::absolute(std::filesystem::read_symlink(std::filesystem::path("/proc/self/exe")).parent_path())) + "/"; | ||
| #else | ||
| // TODO: MacOS could use _NSGetExecutablePath, but this needs to be tested! | ||
| runtime_path = PathString(); | ||
| #endif | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have a Mac to test. Can this be deferred to another PR? It is not required for the tests as the tests use |
||
| } | ||
| LOGS_DEFAULT(VERBOSE) << "Determined PosixEnv runtime path as \"" << runtime_path << "\""; | ||
| return runtime_path; | ||
| } | ||
|
|
||
| private: | ||
| Telemetry telemetry_provider_; | ||
| #ifdef ORT_USE_CPUINFO | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
| VERS_1.0 { | ||
| global: | ||
| GetProvider; | ||
| CreateEpFactories; | ||
| ReleaseEpFactory; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this enables the autoep test cases. The exports are already present on Windows. |
||
| _binary_*; | ||
|
|
||
| # Hide everything else. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may directly use std::filesystem::path. The class PathString was created before we migrated the code to C++17.