Skip to content

Language bindings for Hardware Device and EP Compatibility APIs#28128

Merged
adrianlizarraga merged 7 commits intomicrosoft:mainfrom
xhan65:user/xiha/language_projection
May 1, 2026
Merged

Language bindings for Hardware Device and EP Compatibility APIs#28128
adrianlizarraga merged 7 commits intomicrosoft:mainfrom
xhan65:user/xiha/language_projection

Conversation

@xhan65
Copy link
Copy Markdown
Contributor

@xhan65 xhan65 commented Apr 18, 2026

Description

This change includes c++, c# and python language projections for the GetHardwareDeviceEpIncompatibilityDetails and related APIs added #26922

Motivation and Context

  • GetNumHardwareDevices / GetHardwareDevices — enumerate hardware devices (CPU, GPU, NPU) available on the system
  • GetHardwareDeviceEpIncompatibilityDetails — check known incompatibility issues between a device and an execution
    provider
  • DeviceEpIncompatibilityDetails_GetReasonsBitmask / GetNotes / GetErrorCode / Release — access and manage
    incompatibility detail results
  • OrtDeviceEpIncompatibilityReason enum — standard incompatibility reason flags

Testing

Added python, c++ and c# tests and verified that they passed.

@xhan65 xhan65 changed the title Merged Language bindings for Hardware Device and EP Compatibility APIs Language bindings for Hardware Device and EP Compatibility APIs Apr 20, 2026
@xhan65 xhan65 marked this pull request as ready for review April 20, 2026 18:02
Copy link
Copy Markdown
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

Adds C++, C# and Python language projections for the new Hardware Device + EP compatibility APIs (device enumeration + querying EP/device incompatibility details), along with unit tests validating the new bindings.

Changes:

  • Added Python pybind11 globals for get_hardware_devices, get_hardware_device_ep_incompatibility_details, and exposed OrtDeviceEpIncompatibilityReason.
  • Extended C++ C++-API wrappers (Ort::Env) to enumerate hardware devices and retrieve DeviceEpIncompatibilityDetails.
  • Added C# projections + native delegate bindings for the new APIs and corresponding tests.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
onnxruntime/test/python/onnxruntime_test_python_ep_compatibility.py Adds Python tests for device enumeration, incompatibility details, and enum values.
onnxruntime/test/framework/hardware_device_compatibility_test.cc Adds C++ API unit tests for the new Ort::Env hardware-device methods.
onnxruntime/python/onnxruntime_pybind_state.cc Adds Python bindings for hardware device enumeration/incompatibility queries and exposes the new reason enum.
include/onnxruntime/core/session/onnxruntime_cxx_inline.h Implements inline C++ API wrappers for the new Env/device APIs and details accessors.
include/onnxruntime/core/session/onnxruntime_cxx_api.h Declares new C++ wrapper types and Ort::Env methods for hardware device compatibility APIs.
csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/EpCompatibilityTests.cs Adds C# tests for device enumeration and incompatibility details.
csharp/src/Microsoft.ML.OnnxRuntime/OrtHardwareDevice.shared.cs Exposes OrtHardwareDevice.Handle internally for interop calls.
csharp/src/Microsoft.ML.OnnxRuntime/OrtEnv.shared.cs Adds C# projections for new APIs and a disposable wrapper for incompatibility details + flags enum.
csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.shared.cs Adds native delegate bindings/function pointers for the new C API calls.

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

Comment thread onnxruntime/python/onnxruntime_pybind_state.cc Outdated
Comment thread onnxruntime/python/onnxruntime_pybind_state.cc Outdated
Comment thread csharp/src/Microsoft.ML.OnnxRuntime/OrtEnv.shared.cs Outdated
@xhan65 xhan65 force-pushed the user/xiha/language_projection branch from 3e63595 to aa844ec Compare April 23, 2026 17:40
Comment thread onnxruntime/python/onnxruntime_pybind_state.cc Outdated
Comment thread onnxruntime/python/onnxruntime_pybind_state.cc Outdated
Comment thread onnxruntime/python/onnxruntime_pybind_state.cc Outdated
Comment thread onnxruntime/python/onnxruntime_pybind_state.cc Outdated
Replace C API calls with direct internal calls to GetEnv() for
get_hardware_devices and get_hardware_device_ep_incompatibility_details.
Use OrtPybindThrowIfError for proper Python exception types.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
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

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.


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

Comment thread onnxruntime/python/onnxruntime_pybind_state.cc
Comment thread onnxruntime/test/python/onnxruntime_test_python_ep_compatibility.py Outdated
Comment thread onnxruntime/test/framework/hardware_device_compatibility_test.cc Outdated
Comment thread csharp/src/Microsoft.ML.OnnxRuntime/OrtEnv.shared.cs
Comment thread csharp/src/Microsoft.ML.OnnxRuntime/OrtEnv.shared.cs
- Use bitmask comparison for UNKNOWN enum value in Python test to avoid
  platform/compiler sign brittleness
- Replace strlen(notes) == 0 with *notes == '\0' to avoid implicit
  cstring dependency in C++ tests
- Use checked((int)numDevices) in C# OrtEnv to prevent silent truncation
  on 64-bit

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
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

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.


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

Comment thread include/onnxruntime/core/session/onnxruntime_cxx_api.h Outdated
@adrianlizarraga
Copy link
Copy Markdown
Contributor

Hi @xhan65, you may need to sync with the latest main branch to get some CI to pass.

…ojection

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
@xhan65
Copy link
Copy Markdown
Contributor Author

xhan65 commented Apr 30, 2026

Hi @xhan65, you may need to sync with the latest main branch to get some CI to pass.

Hmmm I synced to main but this Linux_TRT_Minimal_CUDA_Test_CI test still keeps failing... Is it a known issue? I don't think my change would cause it to fail.

@adrianlizarraga
Copy link
Copy Markdown
Contributor

Hi @xhan65, you may need to sync with the latest main branch to get some CI to pass.

Hmmm I synced to main but this Linux_TRT_Minimal_CUDA_Test_CI test still keeps failing... Is it a known issue? I don't think my change would cause it to fail.

Hi, I don't think it is a problem with your PR. We're investigating internally.

@adrianlizarraga adrianlizarraga merged commit 5ca4e83 into microsoft:main May 1, 2026
91 of 92 checks passed
tianleiwu pushed a commit that referenced this pull request May 3, 2026
### Description
This change includes c++, c# and python language projections for the
GetHardwareDeviceEpIncompatibilityDetails and related APIs added #26922

### Motivation and Context
- GetNumHardwareDevices / GetHardwareDevices — enumerate hardware
devices (CPU, GPU, NPU) available on the system
- GetHardwareDeviceEpIncompatibilityDetails — check known
incompatibility issues between a device and an execution
provider
- DeviceEpIncompatibilityDetails_GetReasonsBitmask / GetNotes /
GetErrorCode / Release — access and manage
incompatibility detail results
- OrtDeviceEpIncompatibilityReason enum — standard incompatibility
reason flags

### Testing
Added python, c++ and c# tests and verified that they passed.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

3 participants