Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion onnxruntime/core/session/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "core/session/allocator_adapters.h"
#include "core/session/inference_session.h"
#include "core/session/onnxruntime_env_config_keys.h"
#include "core/session/onnxruntime_ep_device_ep_metadata_keys.h"
#include "core/session/plugin_ep/ep_factory_internal.h"
#include "core/session/plugin_ep/ep_library_internal.h"
#include "core/session/plugin_ep/ep_library_plugin.h"
Expand Down Expand Up @@ -896,8 +897,15 @@
factory.GetSupportedDevices(&factory, sorted_devices.data(), sorted_devices.size(),
ep_devices.data(), ep_devices.size(), &num_ep_devices)));

const auto* library_path = instance.library->LibraryPath();
for (size_t i = 0; i < num_ep_devices; ++i) {
if (ep_devices[i] != nullptr) { // should never happen but just in case...
if (ep_devices[i] != nullptr) { // should never happen but just in case...
if (library_path != nullptr) {
// Add library path to EP metadata if available.
// This is used by GenAI for custom library loading so we want to consistently set it.
ep_devices[i]->ep_metadata.Add(kOrtEpDevice_EpMetadataKey_LibraryPath, library_path->string());

Check warning on line 906 in onnxruntime/core/session/environment.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <string> for string [build/include_what_you_use] [4] Raw Output: onnxruntime/core/session/environment.cc:906: Add #include <string> for string [build/include_what_you_use] [4]
}

instance.execution_devices.emplace_back(ep_devices[i]); // take ownership
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ OrtStatus* ProviderBridgeEpFactory::GetSupportedDevices(EpFactoryInternal& ep_fa
auto* ep_device = ep_devices[i];
if (ep_device) {
ep_device->ep_factory = &ep_factory;

// Add library path to EP metadata if available
if (library_path_.has_value()) {
ep_device->ep_metadata.Add(kOrtEpDevice_EpMetadataKey_LibraryPath, library_path_->string());
}
}
}

Expand Down
1 change: 1 addition & 0 deletions onnxruntime/core/session/plugin_ep/ep_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class EpLibrary {
EpLibrary() = default;

virtual const char* RegistrationName() const = 0;
virtual const std::filesystem::path* LibraryPath() const { return nullptr; }
virtual Status Load() { return Status::OK(); }
virtual const std::vector<OrtEpFactory*>& GetFactories() = 0; // valid after Load()
virtual Status Unload() { return Status::OK(); }
Expand Down
4 changes: 4 additions & 0 deletions onnxruntime/core/session/plugin_ep/ep_library_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class EpLibraryPlugin : public EpLibrary {
return registration_name_.c_str();
}

const std::filesystem::path* LibraryPath() const override {
return &library_path_;
}

Status Load() override;

const std::vector<OrtEpFactory*>& GetFactories() override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class EpLibraryProviderBridge : public EpLibrary {
public:
EpLibraryProviderBridge(std::unique_ptr<ProviderLibrary> provider_library,
std::unique_ptr<EpLibrary> ep_library_plugin,
std::optional<std::filesystem::path> library_path = std::nullopt)
std::filesystem::path library_path)
: provider_library_{std::move(provider_library)},
ep_library_plugin_{std::move(ep_library_plugin)},
library_path_{std::move(library_path)} {
Expand All @@ -32,6 +32,10 @@ class EpLibraryProviderBridge : public EpLibrary {
return ep_library_plugin_->RegistrationName();
}

const std::filesystem::path* LibraryPath() const override {
return &library_path_;
}

const std::vector<OrtEpFactory*>& GetFactories() override {
return factory_ptrs_;
}
Expand All @@ -56,7 +60,7 @@ class EpLibraryProviderBridge : public EpLibrary {
std::unique_ptr<EpLibrary> ep_library_plugin_;

// Library path for EP metadata
std::optional<std::filesystem::path> library_path_;
std::filesystem::path library_path_;

std::vector<std::unique_ptr<EpFactoryInternal>> factories_;
std::vector<OrtEpFactory*> factory_ptrs_; // for convenience
Expand Down
9 changes: 9 additions & 0 deletions onnxruntime/test/autoep/test_registration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ TEST(OrtEpLibrary, LoadUnloadPluginLibraryCxxApi) {
auto options = test_ep_device->EpOptions();
ASSERT_STREQ(options.GetValue("run_really_fast"), "true");

// Verify the library path is present in the EP metadata
const char* metadata_library_path = metadata.GetValue(kOrtEpDevice_EpMetadataKey_LibraryPath);
ASSERT_NE(metadata_library_path, nullptr) << "Expected library_path to be present in EP metadata.";

// Verify the library path matches the registered path
std::filesystem::path metadata_path{metadata_library_path};
ASSERT_EQ(std::filesystem::canonical(metadata_path), std::filesystem::canonical(library_path))
<< "Expected library_path in EP metadata to match the registered library path.";

// the CPU device info will vary by machine so check for the lowest common denominator values
Ort::ConstHardwareDevice device = test_ep_device->Device();
ASSERT_EQ(device.Type(), OrtHardwareDeviceType_CPU);
Expand Down
Loading