Skip to content

Conversation

@adrianlizarraga
Copy link
Contributor

@adrianlizarraga adrianlizarraga commented Jan 5, 2026

Description

  • Adds a new C API RegisterExecutionProviderLibraryWithOptions that allows applications to pass configuration options to execution provider (EP) factories during EP library registration. The options are passed to each factory's SetEnvironmentOptions function immediately after factory creation.
  • Adds corresponding bindings for C# and Python.

Motivation and Context

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new API RegisterExecutionProviderLibraryWithOptions that allows applications to pass configuration options to execution provider (EP) factories during EP library registration. The options are passed to each factory's SetEnvironmentOptions function immediately after factory creation.

Key Changes:

  • Adds new C API function RegisterExecutionProviderLibraryWithOptions that accepts optional key-value pair options
  • Updates existing RegisterExecutionProviderLibrary to call the new implementation with nullptr for options
  • Adds HasKey method to OrtKeyValuePairs to check for existing keys before adding defaults

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
include/onnxruntime/core/session/onnxruntime_c_api.h Adds new C API function declaration with documentation
include/onnxruntime/core/session/onnxruntime_cxx_api.h Adds C++ wrapper method declaration
include/onnxruntime/core/session/onnxruntime_cxx_inline.h Implements C++ wrapper method
include/onnxruntime/core/session/onnxruntime_ep_c_api.h Updates documentation for SetEnvironmentOptions to clarify it's called during registration
include/onnxruntime/core/session/environment.h Updates internal method signatures to accept options parameter
onnxruntime/core/session/onnxruntime_c_api.cc Implements new C API function and refactors existing one
onnxruntime/core/session/ort_apis.h Adds function pointer declaration
onnxruntime/core/session/environment.cc Updates internal implementation to pass options through to EP factories
onnxruntime/core/session/abi_key_value_pairs.h Adds HasKey helper method
onnxruntime/python/onnxruntime_pybind_state.cc Adds Python binding overload accepting options dictionary
onnxruntime/test/python/autoep_helper.py Adds test utility for registering with options
onnxruntime/test/python/onnxruntime_test_python_autoep.py Adds Python test case
csharp/src/Microsoft.ML.OnnxRuntime/OrtEnv.shared.cs Adds C# API overload and removes outdated comment
csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.shared.cs Adds P/Invoke declarations
csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/OrtAutoEpTests.cs Adds C# test case and fixes trailing whitespace
onnxruntime/test/autoep/test_registration.cc Adds comprehensive C++ test cases
onnxruntime/test/autoep/library/example_plugin_ep_kernel_registry/ep_factory.h Adds SetEnvironmentOptions method declaration
onnxruntime/test/autoep/library/example_plugin_ep_kernel_registry/ep_factory.cc Implements SetEnvironmentOptions to store config for testing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@adrianlizarraga adrianlizarraga marked this pull request as ready for review January 5, 2026 18:18
@jnagi-intel
Copy link
Contributor

@adrianlizarraga Does this mean that .virtual suffix will not be necessary to enumerate virtual devices ?

},
R"pbdoc(Register an execution provider library with ONNX Runtime.)pbdoc");
m.def(
"register_execution_provider_library",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note this overloads the original python function name.

* \param[in] env The OrtEnv instance to register the library in.
* \param[in] registration_name The name to register the execution provider library under.
* \param[in] path The path to the execution provider library.
* \param[in] options Map of options to pass to each OrtEpFactory via OrtEpFactory::SetEnvironmentOptions.
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe mention that this parameter is optional.

ORT_API2_STATUS(KernelInfo_GetConfigEntries, _In_ const OrtKernelInfo* info, _Outptr_ OrtKeyValuePairs** out);

/** \brief Register an execution provider library with ORT. The provided options are passed to
* OrtEpFactory::SetEnvironmentOptions after factory creation.
Copy link
Contributor

Choose a reason for hiding this comment

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

it's good to document how the options are passed through. maybe also mention when it would be useful to specify such options.

Env& RegisterExecutionProviderLibrary(const char* registration_name, const std::basic_string<ORTCHAR_T>& path);

///< Wraps OrtApi::RegisterExecutionProviderLibraryWithOptions
Env& RegisterExecutionProviderLibraryWithOptions(const char* registration_name, const std::basic_string<ORTCHAR_T>& path,
Copy link
Contributor

Choose a reason for hiding this comment

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

one thing that bothered me before is how Env::RegisterExecutionProviderLibrary() took both a char* and a std::basic_string parameter.

would it be possible to make them consistent? I guess an argument could be made for making it consistently inconsistent too though...

"""
ep_lib_path = "example_plugin_ep_kernel_registry.dll"
try:
ep_lib_path = get_name("example_plugin_ep_kernel_registry.dll")
Copy link
Contributor

Choose a reason for hiding this comment

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

do these tests only run on Windows, or should they use a platform-specific library path?

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.

4 participants