fix: Add Linux NPU discovery through sysfs accel devices - #28703
Conversation
|
Gentle ping. This PR has been open for about two weeks and the CI looks green from my side. cc: @chilo-ms — would you be the right person to review or help route this change? |
There was a problem hiding this comment.
Pull request overview
This PR extends ONNX Runtime’s Linux DeviceDiscovery::DiscoverDevicesForPlatform() to enumerate NPU devices by scanning the sysfs accel subsystem (/sys/class/accel) and emitting OrtHardwareDeviceType_NPU entries so plugin EP factories can match/claim NPUs on Linux.
Changes:
- Add sysfs scanning for
accelNentries under/sys/class/acceland translate them intoOrtHardwareDeviceType_NPUdevices. - Read PCI
vendor_id/device_idand optionally attachpci_bus_id, plus addaccel_idxmetadata. - Wire NPU enumeration into
DeviceDiscovery::DiscoverDevicesForPlatform()and introducekSysfsAccelPath.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Could you help add test for the changes? |
96eaea8 to
b9a8823
Compare
Extend Linux device discovery to enumerate NPU devices exposed through /sys/class/accel and add unit tests using a fake sysfs accel tree.
b9a8823 to
f542008
Compare
Thanks for the review! I updated the PR to add unit tests for the NPU sysfs discovery path using a fake sysfs accel tree, following the same style as the existing PCI device discovery tests. I also parameterized the accel sysfs base path so the tests can pass a temporary directory while production discovery still uses I verified the targeted tests locally: 12 tests from 2 test suites passed. |
Description
This PR adds Linux NPU discovery through sysfs accel devices
Currently,
DeviceDiscovery::DiscoverDevicesForPlatform()on Linux discovers CPU and GPU devices, but NPU discovery is still missing. As a result, plugin execution providers that filter devices byOrtHardwareDeviceType_NPUdo not receive any NPU hardware devices on Linux, even when the NPU is present and exposed by the kernel.This change scans
/sys/class/accelforaccelNdevices and createsOrtHardwareDeviceentries with:type = OrtHardwareDeviceType_NPUvendor_iddevice_idaccel_idxmetadatapci_bus_idmetadata when availableThis enables Linux systems with NPUs exposed through the accel subsystem, such as AMD Ryzen AI / XDNA devices, to be reported through ORT device discovery and made available to plugin EP factories.
Changes
/sys/class/accel.accel_idxandpci_bus_id.DeviceDiscovery::DiscoverDevicesForPlatform().kSysfsAccelPathconstant for the Linux accel sysfs path.Motivation
Linux plugin EPs that target NPUs rely on ORT passing
OrtHardwareDeviceType_NPUdevices intoGetSupportedDevices(). Without Linux NPU discovery, those EPs cannot claim NPU devices and provider selection policies such asPREFER_NPUsilently fall back to CPU.Fixes #28660.