Skip to content

fix: Add Linux NPU discovery through sysfs accel devices - #28703

Merged
chilo-ms merged 1 commit into
microsoft:mainfrom
the0cp:linux-npu-device-discovery
Jun 11, 2026
Merged

fix: Add Linux NPU discovery through sysfs accel devices#28703
chilo-ms merged 1 commit into
microsoft:mainfrom
the0cp:linux-npu-device-discovery

Conversation

@the0cp

@the0cp the0cp commented May 28, 2026

Copy link
Copy Markdown
Contributor

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 by OrtHardwareDeviceType_NPU do not receive any NPU hardware devices on Linux, even when the NPU is present and exposed by the kernel.

This change scans /sys/class/accel for accelN devices and creates OrtHardwareDevice entries with:

  • type = OrtHardwareDeviceType_NPU
  • PCI vendor_id
  • PCI device_id
  • accel_idx metadata
  • pci_bus_id metadata when available

This 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

  • Add Linux sysfs discovery for NPU devices under /sys/class/accel.
  • Read NPU PCI vendor and device IDs from the underlying sysfs device path.
  • Add NPU metadata including accel_idx and pci_bus_id.
  • Include discovered NPU devices in DeviceDiscovery::DiscoverDevicesForPlatform().
  • Add a kSysfsAccelPath constant for the Linux accel sysfs path.

Motivation

Linux plugin EPs that target NPUs rely on ORT passing OrtHardwareDeviceType_NPU devices into GetSupportedDevices(). Without Linux NPU discovery, those EPs cannot claim NPU devices and provider selection policies such as PREFER_NPU silently fall back to CPU.

Fixes #28660.

@the0cp the0cp changed the title Add Linux NPU discovery through sysfs accel devices fix: Add Linux NPU discovery through sysfs accel devices Jun 1, 2026
@the0cp

the0cp commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

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?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 accelN entries under /sys/class/accel and translate them into OrtHardwareDeviceType_NPU devices.
  • Read PCI vendor_id/device_id and optionally attach pci_bus_id, plus add accel_idx metadata.
  • Wire NPU enumeration into DeviceDiscovery::DiscoverDevicesForPlatform() and introduce kSysfsAccelPath.

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

Comment thread onnxruntime/core/platform/linux/device_discovery.cc Outdated
@chilo-ms

chilo-ms commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Could you help add test for the changes?
We might need to create a fake device for the test as there is no real NPU device in the pipeline environment.
Also just wondering have you tested the change in a system that has a NPU device?

@the0cp
the0cp force-pushed the linux-npu-device-discovery branch from 96eaea8 to b9a8823 Compare June 10, 2026 02:41
Extend Linux device discovery to enumerate NPU devices exposed through
/sys/class/accel and add unit tests using a fake sysfs accel tree.
@the0cp
the0cp force-pushed the linux-npu-device-discovery branch from b9a8823 to f542008 Compare June 10, 2026 02:47
@the0cp

the0cp commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Could you help add test for the changes? We might need to create a fake device for the test as there is no real NPU device in the pipeline environment. Also just wondering have you tested the change in a system that has a NPU device?

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 /sys/class/accel.
I do not have access to a physical NPU system locally, so I have not tested this on real NPU hardware. My validation is based on the simulated sysfs layout matching the issue’s reported Linux exposure of the NPU.

I verified the targeted tests locally:

./build/Linux/Debug/onnxruntime_test_all --gtest_filter="*NpuDeviceDiscoveryTest*:*PciDeviceDiscoveryTest*"

12 tests from 2 test suites passed.

@chilo-ms
chilo-ms merged commit 5c7ba13 into microsoft:main Jun 11, 2026
85 checks passed
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.

[Bug] Linux DeviceDiscovery::DiscoverDevicesForPlatform does not enumerate NPU devices — plugin EPs targeting NPU are unusable on Linux

3 participants