-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Linux device discovery for TRT-RTX Ep #26210
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
base: main
Are you sure you want to change the base?
Changes from all commits
7904e6b
33de4ed
8752206
b2734d9
7d1c75f
b4a38fc
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 | ||
|
@@ -591,6 +592,46 @@ class PosixEnv : public Env { | |
char* val = getenv(var_name.c_str()); | ||
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"); | ||
// We will find OrtGetApiBase if onnxruntime is loaded as a shared library | ||
if (dladdr(symbol_from_this_library, &dl_info) && dl_info.dli_fname) { | ||
return PathString(dl_info.dli_fname) + "/"; | ||
} else { | ||
// else use path of current executable to mirror Windows behavior | ||
#if __linux__ | ||
return PathString(std::filesystem::read_symlink(std::filesystem::path("/proc/self/exe")).parent_path()) + "/"; | ||
#else | ||
// TODO: MacOS could use _NSGetExecutablePath, but this needs to be tested! | ||
return PathString(); | ||
#endif | ||
} | ||
} | ||
|
||
|
||
// 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"); | ||
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. needs to be an exported symbol. onnxruntim_core.a does not have exported symbols by itself (we could add one though), only with onnxruntime.so |
||
// We will find OrtGetApiBase if onnxruntime is loaded as a shared library | ||
if (dladdr(symbol_from_this_library, &dl_info) && dl_info.dli_fname) { | ||
return PathString(dl_info.dli_fname) + "/"; | ||
} else { | ||
// else use path of current executable to mirror Windows behavior | ||
#if __linux__ | ||
return PathString(std::filesystem::read_symlink(std::filesystem::path("/proc/self/exe")).parent_path()) + "/"; | ||
#else | ||
// TODO: MacOS could use _NSGetExecutablePath, but this needs to be tested! | ||
return PathString(); | ||
#endif | ||
} | ||
} | ||
|
||
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. @edgchen1 This resolves the failing test under Linux. I could alternatively put I'm not sure whether the Windows behavior to set runtime path to current exe's dir is always desired (but it would be needed to behave the same in tests like on Windows) |
||
private: | ||
Telemetry telemetry_provider_; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
VERS_1.0 { | ||
global: | ||
GetProvider; | ||
CreateEpFactories; | ||
ReleaseEpFactory; | ||
|
||
# Hide everything else. | ||
local: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,7 +216,6 @@ INSTANTIATE_TEST_SUITE_P(NvExecutionProviderTest, TypeTests, | |
), | ||
[](const testing::TestParamInfo<TypeTests::ParamType>& info) { return getTypeAsName(info.param); }); | ||
|
||
#ifdef _WIN32 | ||
static bool SessionHasEp(Ort::Session& session, const char* ep_name) { | ||
// Access the underlying InferenceSession. | ||
const OrtSession* ort_session = session; | ||
|
@@ -233,7 +232,6 @@ static bool SessionHasEp(Ort::Session& session, const char* ep_name) { | |
} | ||
|
||
// Tests autoEP feature to automatically select an EP that supports the GPU. | ||
// Currently only works on Windows. | ||
TEST(NvExecutionProviderTest, AutoEp_PreferGpu) { | ||
PathString model_name = ORT_TSTR("nv_execution_provider_auto_ep.onnx"); | ||
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 test is currently still failing: NvTensorRtRtxEpFactory::CreateEp is called but not implemented https://github.com/theHamsta/onnxruntime/blob/bc7f4bbc92ed0609e18e1c4c80c3c8d560ce1729/onnxruntime/core/providers/nv_tensorrt_rtx/nv_provider_factory.cc#L698. The other test passes 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. Where would would the internal factories on Windows come from NvEp like other EPs does not implement CreateEp. I guess IExecutionProvider.CreateProviders is the modern version of it? |
||
std::string graph_name = "test"; | ||
|
@@ -243,7 +241,11 @@ TEST(NvExecutionProviderTest, AutoEp_PreferGpu) { | |
CreateBaseModel(model_name, graph_name, dims); | ||
|
||
{ | ||
#if _WIN32 | ||
ort_env->RegisterExecutionProviderLibrary(kNvTensorRTRTXExecutionProvider, ORT_TSTR("onnxruntime_providers_nv_tensorrt_rtx.dll")); | ||
#else | ||
ort_env->RegisterExecutionProviderLibrary(kNvTensorRTRTXExecutionProvider, ORT_TSTR("libonnxruntime_providers_nv_tensorrt_rtx.so")); | ||
#endif | ||
|
||
Ort::SessionOptions so; | ||
so.SetEpSelectionPolicy(OrtExecutionProviderDevicePolicy_PREFER_GPU); | ||
|
@@ -398,7 +400,5 @@ TEST(NvExecutionProviderTest, DataTransfer) { | |
device_tensor = Ort::Value(); | ||
} | ||
|
||
#endif | ||
|
||
} // namespace test | ||
} // namespace onnxruntime |
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.
is it possible to infer whether the GPU is discrete from the bus_id? I'm trying to figure out how to determine that - any pointers would be appreciated.
Uh oh!
There was an error while loading. Please reload this page.
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.
Hi! I don't know whether this is reliable, but it seems that the parent bus of a iGPU seems to have a parent bus with id of pattern
picXXXX:00
. dGPU seems to have names likecard1
or higher while iGPU would be namedcard0
. So it's rather the topology of the bus than the bus id of the GPU itselfdGPU
iGPUs would often have the parent path and be named card0
I don't have a iGPU so my node
or
wouldn't have a any drm nodes
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.
good to know, thanks for sharing that observation