Skip to content

Conversation

@theHamsta
Copy link

@theHamsta theHamsta commented Oct 28, 2025

Description

During #26210 we discovered that implementing PosixEnv::GetRuntimePath is a requirement to make autoep test work on Linux.

This PR implements PosixEnv::GetRuntimePath in a way that is close to Windows on Linux and (partially) on MacOS. The newly added method is tested by enabling autoep tests on Linux and MacOS.

Motivation and Context

  • enable automatic device discovery on Linux (without AppendExecutionProvider{_V2})
  • enable device discovery with Cuda EP on Linux (without AppendExecutionProvider{_V2})

@edgchen1

We try to follow the implementation of WindowsEnv which resolves the
runtime directory as the directory of the current DLL (onnxruntime) or
executable for static linkage.
The same symbols are already exposed for Windows.
This enables the CUDA EP to be selected in AutoEP tests.
@theHamsta theHamsta force-pushed the posixenv-to-enable-autoep-tests branch from 769dd8d to 30b8639 Compare October 28, 2025 12:38
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())) + "/";
Copy link
Author

Choose a reason for hiding this comment

The 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 CreateEp which CUDA EP does not implement.

global:
GetProvider;
CreateEpFactories;
ReleaseEpFactory;
Copy link
Author

Choose a reason for hiding this comment

The 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.

#else
// TODO: MacOS could use _NSGetExecutablePath, but this needs to be tested!
runtime_path = PathString();
#endif
Copy link
Author

@theHamsta theHamsta Oct 28, 2025

Choose a reason for hiding this comment

The 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 libonnxruntime.dynlib

@theHamsta theHamsta changed the title Posixenv to enable autoep tests Implement PosixEnv::GetRuntimePath to enable AutoEP tests on Linux/MacOS Oct 28, 2025

// 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 {
Copy link
Contributor

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.

@edgchen1
Copy link
Contributor

FYI, I have a PR to enable onnxruntime_autoep_test on other platforms. Also implemented PosixEnv::GetRuntimePath() there.

#26344

@theHamsta
Copy link
Author

FYI, I have a PR to enable onnxruntime_autoep_test on other platforms. Also implemented PosixEnv::GetRuntimePath() there.

#26344

Thanks! Wasn't aware of this. Will close this one then!

@theHamsta theHamsta closed this Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants