Implementation:Microsoft Onnxruntime OrtHardwareDevice: Difference between revisions
Auto-imported from implementations/Microsoft_Onnxruntime_OrtHardwareDevice.md |
Sync from local file |
||
| Line 99: | Line 99: | ||
== Related Pages == | == Related Pages == | ||
* [[Microsoft_Onnxruntime_OrtEpDevice|OrtEpDevice.java]] - EP device tuple containing OrtHardwareDevice | * [[Implementation:Microsoft_Onnxruntime_OrtEpDevice|OrtEpDevice.java]] - EP device tuple containing OrtHardwareDevice | ||
* [[Microsoft_Onnxruntime_OrtEnvironment|OrtEnvironment.java]] - Provides getEpDevices() for device discovery | * [[Implementation:Microsoft_Onnxruntime_OrtEnvironment|OrtEnvironment.java]] - Provides getEpDevices() for device discovery | ||
[[Category:Implementations]] | [[Category:Implementations]] | ||
[[Category:Implementations]] | [[Category:Implementations]] | ||
Latest revision as of 10:46, 27 September 2026
| Knowledge Sources | Description |
|---|---|
| Source File | java/src/main/java/ai/onnxruntime/OrtHardwareDevice.java |
| Repository | Microsoft/onnxruntime |
Domains
- Machine Learning Runtime
- Hardware Device Enumeration
Overview
OrtHardwareDevice is a final class representing hardware device information for a specific device in the ONNX Runtime system. It contains the device type (CPU, GPU, or NPU), vendor identification, device ID, and metadata. It also contains the OrtHardwareDeviceType inner enum. Instances are accessed through OrtEpDevice.getDevice().
Description
The class wraps a native handle and eagerly extracts:
- type: An
OrtHardwareDeviceTypeenum (CPU, GPU, or NPU). - vendorId: An integer vendor identifier.
- vendor: A string vendor name.
- deviceId: An integer device identifier.
- metadata: An unmodifiable
Map<String, String>of device metadata.
The OrtHardwareDeviceType enum defines CPU (0), GPU (1), and NPU (2) with mapFromInt for native conversion (defaults to CPU for unknown values).
Code Reference
Source Location
// File: java/src/main/java/ai/onnxruntime/OrtHardwareDevice.java
// Package: ai.onnxruntime
Signature
public final class OrtHardwareDevice {
public OrtHardwareDeviceType getType();
public int getVendorId();
public int getDeviceId();
public String getVendor();
public Map<String, String> getMetadata();
public enum OrtHardwareDeviceType {
CPU(0), GPU(1), NPU(2);
public int getValue();
public static OrtHardwareDeviceType mapFromInt(int deviceType);
}
}
Import
import ai.onnxruntime.OrtHardwareDevice;
import ai.onnxruntime.OrtHardwareDevice.OrtHardwareDeviceType;
I/O Contract
Inputs
| Name | Type | Description |
|---|---|---|
| nativeHandle | long | Pointer to the native hardware device struct (internal) |
Outputs
| Name | Type | Description |
|---|---|---|
| getType() | OrtHardwareDeviceType | CPU, GPU, or NPU |
| getVendorId() | int | Numeric vendor identifier |
| getVendor() | String | Vendor name string |
| getDeviceId() | int | Numeric device identifier |
| getMetadata() | Map<String, String> | Device metadata key-value pairs |
Usage Examples
import ai.onnxruntime.*;
import java.util.*;
OrtEnvironment env = OrtEnvironment.getEnvironment();
List<OrtEpDevice> epDevices = env.getEpDevices();
for (OrtEpDevice epDev : epDevices) {
OrtHardwareDevice device = epDev.getDevice();
System.out.println("Device type: " + device.getType());
System.out.println("Vendor: " + device.getVendor() + " (ID: " + device.getVendorId() + ")");
System.out.println("Device ID: " + device.getDeviceId());
System.out.println("Metadata: " + device.getMetadata());
}
Related Pages
- OrtEpDevice.java - EP device tuple containing OrtHardwareDevice
- OrtEnvironment.java - Provides getEpDevices() for device discovery