Add runtime detection of usable execution providers#27697
Add runtime detection of usable execution providers#27697sagarbhure-msft wants to merge 1 commit intomicrosoft:mainfrom
Conversation
|
@microsoft-github-policy-service agree |
|
Friendly nudge — would love eyes on this when someone gets a chance. cc @microsoft/onnxruntime-api cc: @yuslepukhin |
There was a problem hiding this comment.
Pull request overview
Adds runtime-aware “usable execution provider” detection to ONNX Runtime so consumers can query which EPs are actually loadable on the current machine (vs. merely compiled in), and exposes this via Python bindings alongside unit tests.
Changes:
- Introduces C++ APIs
IsExecutionProviderUsable()andGetUsableExecutionProviderNames()and wires them to runtime provider library checks. - Adds
get_usable_providers()andis_provider_usable()to the Python module and exports them fromonnxruntime/__init__.py. - Adds unit tests covering basic usability expectations and ordering properties.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| onnxruntime/core/providers/get_execution_providers.h | Declares new runtime usability query APIs. |
| onnxruntime/core/providers/get_execution_providers.cc | Implements usable-vs-available logic (with minimal build fallback). |
| onnxruntime/core/session/provider_bridge_ort.h | Declares IsProviderLibraryLoadable helper for runtime checks. |
| onnxruntime/core/session/provider_bridge_ort.cc | Implements provider library loadability checks via provider bridge infrastructure. |
| onnxruntime/python/onnxruntime_pybind_module.cc | Exposes new usability APIs to Python via pybind11. |
| onnxruntime/init.py | Re-exports new Python APIs at top-level. |
| onnxruntime/test/providers/get_execution_providers_test.cc | Adds tests for usability behavior and ordering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
452b646 to
bef8eb3
Compare
Redesigned based on PR review feedback. Uses std::filesystem::exists() to check provider library presence — no DLL loading, no memory footprint increase, no error logs, no hardware initialization. Extended existing kProvidersInPriorityOrder with library_base_name field as single source of truth (no duplicate EP lists). Fixes microsoft#27177
bef8eb3 to
109b00f
Compare
|
Addressed all review feedback - redesigned to use filesystem checks, no library loading. Thanks @yuslepukhin and Key changes:
|
Overview
Adds runtime-aware APIs to detect usable execution providers.
Unlike
get_available_providers()(compile-time), these APIs verify that required runtime dependencies (CUDA, cuDNN, shared libs, etc.) are actually present.This PR adds two new APIs that check whether provider shared libraries actually exist on disk at runtime, without loading them.
New APIs
Python:
C++:
Key Changes
duplicate EP lists
no memory footprint increase
Motivation
get_available_providers()can report providers as available even when runtime dependencies are missing.Current workaround (bad):
New APIs remove the need for exception-based checks.
Tested on Real Hardware
Machine: AMD Ryzen AI MAX+ 395 / Radeon 8060S, Windows
CPU-only build (onnxruntime 1.24.3)
DirectML build (onnxruntime-directml 1.24.3)
Both providers correctly reported as usable, verified with real inference
Who this affects
Fixes #27177