-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add some device discovery support for non-Windows platforms #25228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 20 commits
f5b4d8a
f58ea4d
d7b598d
f34b674
6101b99
a82a10c
64e0a82
3bba325
0594d5a
757d27a
3481e99
34141a1
849b365
cc25212
04b0758
f03f229
c089033
55c3a8c
231d347
9e686ca
b474e4f
c53921d
48c6bb4
6aa11ab
537ab69
f926cdc
5b8764e
d0f9653
920c821
a56c2ff
8ef49c2
5b721ec
c31e336
9ae765a
53dbbf9
d9a7a5a
46d60a3
8dfeb2f
1ddd31a
e1e1014
3ad0927
6adf61f
100228f
b8b5db0
1afaa3e
cdca7a9
35b3796
30370bc
c3138a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #include "core/platform/device_discovery.h" | ||
|
|
||
| #include "core/common/cpuid_info.h" | ||
|
|
||
| namespace onnxruntime { | ||
|
|
||
| namespace { | ||
|
|
||
| OrtHardwareDevice GetCpuDevice() { | ||
| const auto& cpuid_info = CPUIDInfo::GetCPUIDInfo(); | ||
|
|
||
| OrtHardwareDevice cpu_device{}; | ||
| cpu_device.vendor = cpuid_info.GetCPUVendor(); | ||
| cpu_device.vendor_id = cpuid_info.GetCPUVendorId(); | ||
| cpu_device.device_id = 0; | ||
| cpu_device.type = OrtHardwareDeviceType_CPU; | ||
|
|
||
| return cpu_device; | ||
| } | ||
edgchen1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| } // namespace | ||
|
|
||
| std::unordered_set<OrtHardwareDevice> DeviceDiscovery::DiscoverDevicesForPlatform() { | ||
| std::unordered_set<OrtHardwareDevice> devices; | ||
|
Check warning on line 27 in onnxruntime/core/platform/apple/device_discovery.cc
|
||
|
|
||
| // get CPU devices | ||
| devices.insert(GetCpuDevice()); | ||
|
|
||
| // TODO | ||
|
Check warning on line 32 in onnxruntime/core/platform/apple/device_discovery.cc
|
||
|
|
||
| // get GPU devices | ||
|
|
||
| // get NPU devices | ||
edgchen1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return devices; | ||
| } | ||
| } // namespace onnxruntime | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| // This file contains platform-agnostic device discovery implementation. | ||
|
|
||
| #include "core/platform/device_discovery.h" | ||
|
|
||
| #include <sstream> | ||
|
|
||
| #include "core/common/logging/logging.h" | ||
|
|
||
| namespace onnxruntime { | ||
|
|
||
| const std::unordered_set<OrtHardwareDevice>& DeviceDiscovery::GetDevices() { | ||
| // assumption: devices don't change. we assume the machine must be shutdown to change cpu/gpu/npu devices. | ||
| // technically someone could disable/enable a device in a running OS. we choose not to add complexity to support | ||
| // that scenario. | ||
| static std::unordered_set<OrtHardwareDevice> devices = []() { | ||
|
Check warning on line 18 in onnxruntime/core/platform/device_discovery_common.cc
|
||
| auto discovered_devices = DiscoverDevicesForPlatform(); | ||
|
|
||
| // log discovered devices | ||
| for (const auto& ortdevice : discovered_devices) { | ||
| std::ostringstream oss; | ||
| oss << "Discovered OrtHardwareDevice {vendor_id:0x" << std::hex << ortdevice.vendor_id | ||
| << ", device_id:0x" << ortdevice.device_id | ||
| << ", vendor:" << ortdevice.vendor | ||
| << ", type:" << std::dec << static_cast<int>(ortdevice.type) | ||
| << ", metadata: ["; | ||
| for (auto& [key, value] : ortdevice.metadata.Entries()) { | ||
| oss << key << "=" << value << ", "; | ||
| } | ||
| oss << "]}"; | ||
| LOGS_DEFAULT(INFO) << oss.str(); | ||
| } | ||
|
|
||
| return discovered_devices; | ||
| }(); | ||
|
|
||
| return devices; | ||
| } | ||
|
|
||
| } // namespace onnxruntime | ||
Uh oh!
There was an error while loading. Please reload this page.