Implementation:Microsoft Onnxruntime OrtHardwareDevice
| 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