Skip to content

Commit 1f3ae1f

Browse files
authored
Use GUID_DEVCLASS_COMPUTEACCELERATOR for NPU discovery (microsoft#24660)
### Description Updated device discovery to use `GUID_DEVCLASS_COMPUTEACCELERATOR` instead of `GUID_DEVCLASS_SYSTEM` when querying SetupAPI for potential NPU devices. This provides a more specific and accurate class for identifying compute accelerators like NPUs. This change also saves us an average of 5 milliseconds by not looping through unnecessary system devices. ### Motivation and Context When looking for NPUs, the previous code used `GUID_DEVCLASS_SYSTEM` as the class to query for potential devices and didn't return the Qualcomm NPU.
1 parent dc09448 commit 1f3ae1f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

onnxruntime/core/platform/windows/device_discovery.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ std::unordered_map<uint64_t, DeviceInfo> GetDeviceInfoSetupApi(const std::unorde
7575

7676
const GUID local_DXCORE_ADAPTER_ATTRIBUTE_D3D12_GENERIC_ML = {0xb71b0d41, 0x1088, 0x422f, 0xa2, 0x7c, 0x2, 0x50, 0xb7, 0xd3, 0xa9, 0x88};
7777
const GUID local_DXCORE_HARDWARE_TYPE_ATTRIBUTE_NPU = {0xd46140c4, 0xadd7, 0x451b, 0x9e, 0x56, 0x6, 0xfe, 0x8c, 0x3b, 0x58, 0xed};
78+
const GUID local_GUID_DEVCLASS_COMPUTEACCELERATOR = {0xf01a9d53, 0x3ff6, 0x48d2, 0x9f, 0x97, 0xc8, 0xa7, 0x00, 0x4b, 0xe1, 0x0c};
7879

7980
std::array<GUID, 3> guids = {
8081
GUID_DEVCLASS_DISPLAY,
8182
GUID_DEVCLASS_PROCESSOR,
82-
GUID_DEVCLASS_SYSTEM,
83+
local_GUID_DEVCLASS_COMPUTEACCELERATOR,
8384
};
8485

8586
for (auto guid : guids) {
@@ -183,9 +184,9 @@ std::unordered_map<uint64_t, DeviceInfo> GetDeviceInfoSetupApi(const std::unorde
183184
entry->type = OrtHardwareDeviceType_GPU;
184185
} else if (guid == GUID_DEVCLASS_PROCESSOR) {
185186
entry->type = is_npu ? OrtHardwareDeviceType_NPU : OrtHardwareDeviceType_CPU;
186-
} else if (guid == GUID_DEVCLASS_SYSTEM) {
187+
} else if (guid == local_GUID_DEVCLASS_COMPUTEACCELERATOR) {
187188
if (!is_npu) {
188-
// we're only iterating system devices to look for NPUs so drop anything else
189+
// we're only iterating compute accelerator devices to look for NPUs so drop anything else
189190
device_info.erase(key);
190191
continue;
191192
}

0 commit comments

Comments
 (0)