Skip to content
Closed
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
5 changes: 5 additions & 0 deletions include/onnxruntime/core/session/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ class Environment {
const DataTransferManager& GetDataTransferManager() const {
return data_transfer_mgr_;
}

// Get the filesystem path of the library registered for the given EP registration name.
// Returns NOT_FOUND/FAIL if the EP is not registered or does not expose a library path.
Status GetExecutionProviderLibraryPath(const std::string& registration_name,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding C++ and C# versions of this method too.

std::filesystem::path& out) const;
#endif // !defined(ORT_MINIMAL_BUILD)

// return a shared allocator from a plugin EP or custom allocator added with RegisterAllocator
Expand Down
25 changes: 25 additions & 0 deletions onnxruntime/core/session/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,31 @@
}
}

Status Environment::GetExecutionProviderLibraryPath(const std::string& registration_name,

Check warning on line 800 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:800: Add #include <string> for string [build/include_what_you_use] [4]
std::filesystem::path& out) const {
std::lock_guard<std::mutex> lock{mutex_};

auto it = ep_libraries_.find(registration_name);
if (it == ep_libraries_.end()) {
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Execution provider library: ", registration_name, " was not registered.");
}

auto& ep_info = it->second;
if (!ep_info || !ep_info->library) {
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Execution provider library registered under '", registration_name,
"' has no EpLibrary instance.");
}

const auto& lib_path = ep_info->library->GetLibraryPath();
if (lib_path.empty()) {
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Execution provider library registered under '", registration_name,
"' doesn't expose a library path.");
}

out = lib_path;
return Status::OK();
}

#endif // !defined(ORT_MINIMAL_BUILD)

} // namespace onnxruntime
9 changes: 9 additions & 0 deletions onnxruntime/core/session/plugin_ep/ep_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <string>
#include <filesystem>

Check warning on line 7 in onnxruntime/core/session/plugin_ep/ep_library.h

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 <filesystem> is an unapproved C++17 header. [build/c++17] [5] Raw Output: onnxruntime/core/session/plugin_ep/ep_library.h:7: <filesystem> is an unapproved C++17 header. [build/c++17] [5]
#include "core/common/status.h"
#include "core/framework/provider_options.h"
#include "core/framework/session_options.h"
Expand All @@ -22,6 +23,14 @@
virtual const char* RegistrationName() const = 0;
virtual Status Load() { return Status::OK(); }
virtual const std::vector<OrtEpFactory*>& GetFactories() = 0; // valid after Load()

// Return the filesystem path for the underlying library if available. Default implementation returns an
// empty path so derived classes that represent a plugin should override this.
virtual const std::filesystem::path& GetLibraryPath() const {
static const std::filesystem::path empty{};
return empty;
}

virtual Status Unload() { return Status::OK(); }
virtual ~EpLibrary() = default;

Expand Down
3 changes: 3 additions & 0 deletions onnxruntime/core/session/plugin_ep/ep_library_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class EpLibraryPlugin : public EpLibrary {
return factories_;
}

// Return the actual library path for plugin-based EpLibrary instances.
const std::filesystem::path& GetLibraryPath() const override { return library_path_; }

Status Unload() override;

ORT_DISALLOW_COPY_AND_ASSIGNMENT(EpLibraryPlugin);
Expand Down
Loading