@@ -119,7 +119,13 @@ std::unordered_map<uint64_t, DeviceInfo> GetDeviceInfoSetupApi(const std::unorde
119119
120120 uint32_t vendor_id = get_id (buffer, L" VEN_" );
121121 uint32_t device_id = get_id (buffer, L" DEV_" );
122- // won't always have a vendor id from an ACPI entry. need at least a device id to identify the hardware
122+
123+ // Processor ID should come from CPUID mapping.
124+ if (vendor_id == 0 && guid == GUID_DEVCLASS_PROCESSOR ) {
125+ vendor_id = CPUIDInfo::GetCPUIDInfo ().GetCPUVendorId ();
126+ }
127+
128+ // Won't always have a vendor id from an ACPI entry. ACPI is not defined for this purpose.
123129 if (vendor_id == 0 && device_id == 0 ) {
124130 continue ;
125131 }
@@ -138,8 +144,8 @@ std::unordered_map<uint64_t, DeviceInfo> GetDeviceInfoSetupApi(const std::unorde
138144 entry = &device_info[key];
139145 entry->vendor_id = vendor_id;
140146 entry->device_id = device_id;
141- // put the first hardware id string in the metadata. ignore the other lines.
142- entry->metadata .emplace (L" SPDRP_HARDWAREID" , std::wstring (buffer, wcslen (buffer)));
147+ // put the first hardware id string in the metadata. ignore the other lines. not sure if this is of value.
148+ // entry->metadata.emplace(L"SPDRP_HARDWAREID", std::wstring(buffer, wcslen(buffer)));
143149 } else {
144150 // need valid ids
145151 continue ;
@@ -156,22 +162,22 @@ std::unordered_map<uint64_t, DeviceInfo> GetDeviceInfoSetupApi(const std::unorde
156162 (PBYTE )buffer, sizeof (buffer), &size)) {
157163 std::wstring desc{buffer};
158164
159- // Should we require the NPU to be found by DXCore or do we want to allow this vague matching?
160- // Probably depends on whether we always attempt to run DXCore or not .
161- const auto possible_npu = [](const std::wstring& desc) {
162- return (desc.find (L" NPU" ) != std::wstring::npos ||
163- desc.find (L" Neural" ) != std::wstring::npos ||
164- desc.find (L" AI Engine" ) != std::wstring::npos ||
165- desc.find (L" VPU" ) != std::wstring::npos);
166- };
165+ // For now, require dxcore to identify an NPU.
166+ // If we want to try and infer it from the description this _may_ work but is untested .
167+ // const auto possible_npu = [](const std::wstring& desc) {
168+ // return (desc.find(L"NPU") != std::wstring::npos ||
169+ // desc.find(L"Neural") != std::wstring::npos ||
170+ // desc.find(L"AI Engine") != std::wstring::npos ||
171+ // desc.find(L"VPU") != std::wstring::npos);
172+ // };
167173
168174 // use description if no friendly name
169175 if (entry->description .empty ()) {
170176 entry->description = desc;
171177 }
172178
173179 uint64_t npu_key = GetDeviceKey (*entry);
174- bool is_npu = npus.count (npu_key) > 0 || possible_npu (desc);
180+ bool is_npu = npus.count (npu_key) > 0 ; // rely on dxcore to determine if something is an NPU
175181
176182 if (guid == GUID_DEVCLASS_DISPLAY ) {
177183 entry->type = OrtHardwareDeviceType_GPU;
@@ -194,22 +200,17 @@ std::unordered_map<uint64_t, DeviceInfo> GetDeviceInfoSetupApi(const std::unorde
194200 continue ;
195201 }
196202
197- if (SetupDiGetDeviceRegistryPropertyW (devInfo, &devData, SPDRP_MFG , nullptr ,
198- (PBYTE )buffer, sizeof (buffer), &size)) {
199- entry->vendor = std::wstring (buffer, wcslen (buffer));
203+ if (entry->type == OrtHardwareDeviceType_CPU) {
204+ // get 12 byte string from CPUID. easier for a user to match this if they are explicitly picking a device.
205+ std::string_view cpuid_vendor = CPUIDInfo::GetCPUIDInfo ().GetCPUVendor ();
206+ entry->vendor = std::wstring (cpuid_vendor.begin (), cpuid_vendor.end ());
200207 }
201208
202- // Add the UI number if GPU. Helpful if user has integrated and discrete GPUs
203- if (entry->type == OrtHardwareDeviceType_GPU) {
204- DWORD ui_number = 0 ;
205- if (SetupDiGetDeviceRegistryPropertyW (devInfo, &devData, SPDRP_UI_NUMBER , nullptr ,
206- (PBYTE )&ui_number, sizeof (ui_number), &size)) {
207- // use value read.
208- } else {
209- // infer it as 0 if not set.
209+ if (entry->vendor .empty ()) {
210+ if (SetupDiGetDeviceRegistryPropertyW (devInfo, &devData, SPDRP_MFG , nullptr ,
211+ (PBYTE )buffer, sizeof (buffer), &size)) {
212+ entry->vendor = std::wstring (buffer, wcslen (buffer));
210213 }
211-
212- entry->metadata .emplace (L" SPDRP_UI_NUMBER" , std::to_wstring (ui_number));
213214 }
214215 }
215216
@@ -252,9 +253,7 @@ std::unordered_map<uint64_t, DeviceInfo> GetDeviceInfoD3D12() {
252253 info.description = std::wstring (desc.Description );
253254
254255 info.metadata [L" DxgiAdapterNumber" ] = std::to_wstring (i);
255- info.metadata [L" VideoMemory" ] = std::to_wstring (desc.DedicatedVideoMemory / (1024 * 1024 )) + L" MB" ;
256- info.metadata [L" SystemMemory" ] = std::to_wstring (desc.DedicatedSystemMemory / (1024 * 1024 )) + L" MB" ;
257- info.metadata [L" SharedSystemMemory" ] = std::to_wstring (desc.DedicatedSystemMemory / (1024 * 1024 )) + L" MB" ;
256+ info.metadata [L" DxgiVideoMemory" ] = std::to_wstring (desc.DedicatedVideoMemory / (1024 * 1024 )) + L" MB" ;
258257 }
259258
260259 // iterate by high-performance GPU preference to add that info
@@ -272,7 +271,7 @@ std::unordered_map<uint64_t, DeviceInfo> GetDeviceInfoD3D12() {
272271 auto it = device_info.find (key);
273272 if (it != device_info.end ()) {
274273 DeviceInfo& info = it->second ;
275- info.metadata [L" HighPerformanceIndex " ] = std::to_wstring (i);
274+ info.metadata [L" DxgiHighPerformanceIndex " ] = std::to_wstring (i);
276275 }
277276 }
278277
@@ -405,32 +404,48 @@ std::unordered_set<OrtHardwareDevice> DeviceDiscovery::DiscoverDevicesForPlatfor
405404 }
406405 }
407406
408- std::wstring_convert<std::codecvt_utf8<wchar_t > > converter; // wstring to string
409- const auto device_to_ortdevice = [&converter](
407+ // our log output to std::wclog breaks with UTF8 chars that are not supported by the current code page.
408+ // e.g. (TM) symbol. that stops ALL logging working on at least arm64.
409+ // safest way to avoid that is to keep it to single byte chars.
410+ // process the OrtHardwareDevice values this way so it can be safely logged.
411+ // only the 'description' metadata is likely to be affected and that is mainly for diagnostic purposes.
412+ const auto to_safe_string = [](const std::wstring& wstr) -> std::string {
413+ std::string str (wstr.size (), ' ' );
414+ std::transform (wstr.begin (), wstr.end (), str.begin (), [](wchar_t wchar) {
415+ if (wchar >= 0 && wchar <= 127 ) {
416+ return static_cast <char >(wchar);
417+ }
418+ return ' ' ;
419+ });
420+ return str;
421+ };
422+
423+ const auto device_to_ortdevice = [&to_safe_string](
410424 DeviceInfo& device,
411425 std::unordered_map<std::wstring, std::wstring>* extra_metadata = nullptr ) {
412- OrtHardwareDevice ortdevice{device.type , device.vendor_id , device.device_id , converter. to_bytes (device.vendor )};
426+ OrtHardwareDevice ortdevice{device.type , device.vendor_id , device.device_id , to_safe_string (device.vendor )};
413427
414428 if (!device.description .empty ()) {
415- ortdevice.metadata .Add (" Description" , converter. to_bytes (device.description ));
429+ ortdevice.metadata .Add (" Description" , to_safe_string (device.description ));
416430 }
417431
418432 for (auto & [key, value] : device.metadata ) {
419- ortdevice.metadata .Add (converter. to_bytes (key), converter. to_bytes (value));
433+ ortdevice.metadata .Add (to_safe_string (key), to_safe_string (value));
420434 }
421435
422436 if (extra_metadata) {
423437 // add any extra metadata from the dxcore info
424438 for (auto & [key, value] : *extra_metadata) {
425439 if (device.metadata .find (key) == device.metadata .end ()) {
426- ortdevice.metadata .Add (converter. to_bytes (key), converter. to_bytes (value));
440+ ortdevice.metadata .Add (to_safe_string (key), to_safe_string (value));
427441 }
428442 }
429443 }
430444
431445 std::ostringstream oss;
432446 oss << " Adding OrtHardwareDevice {vendor_id:0x" << std::hex << ortdevice.vendor_id
433447 << " , device_id:0x" << ortdevice.device_id
448+ << " , vendor:" << ortdevice.vendor
434449 << " , type:" << std::dec << static_cast <int >(ortdevice.type )
435450 << " , metadata: [" ;
436451 for (auto & [key, value] : ortdevice.metadata .entries ) {
0 commit comments