Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Khám phá và chỉ định thiết bị
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Trong Android 10, Neural Networks API (NNAPI) giới thiệu các hàm cho phép các ứng dụng và thư viện khung máy học có được thông tin về các thiết bị có sẵn và chỉ định thiết bị nào sẽ thực thi mô hình. Việc cung cấp thông tin về các thiết bị có sẵn cho phép các ứng dụng biết được phiên bản chính xác của các trình điều khiển có trên thiết bị để tránh các trường hợp không tương thích đã biết. Nhờ được phép chỉ định những thiết bị sẽ thực thi những phần khác nhau của một mô hình, các ứng dụng có thể được tối ưu hoá cho sản phẩm mà ứng dụng được triển khai.
Bạn cần hỗ trợ tính năng khám phá và chỉ định thiết bị để triển khai NN HAL 1.2.
Triển khai
Để hỗ trợ các tính năng khám phá và chỉ định thiết bị trong NNAPI, hãy triển khai getType
và getVersionString
trong IDevice.hal
để cho phép khung này nhận loại thiết bị và phiên bản trình điều khiển.
Đối với mỗi thiết bị, hãy chỉ định loại thiết bị là một trong các danh mục sau đây như được chỉ định trong DeviceType
trong types.hal
.
OTHER
: Một thiết bị không thuộc danh mục nào khác, bao gồm cả giao diện không đồng nhất, là một giao diện IDevice
duy nhất quản lý nhiều thiết bị, có thể thuộc nhiều loại. Trình điều khiển có giao diện không đồng nhất cũng phải hiển thị các giao diện IDevice
riêng biệt tương ứng với từng thiết bị để cho phép ứng dụng chọn trong số các thiết bị đó.
CPU
: CPU đơn nhân hoặc đa nhân.
GPU
: GPU có thể chạy các mô hình NNAPI và tăng tốc các API đồ hoạ như OpenGL ES và Vulkan.
ACCELERATOR
: Một đơn vị xử lý thần kinh (NPU) chuyên dụng.
Triển khai getVersionString
trong IDevice.hal
để lấy chuỗi phiên bản của quá trình triển khai thiết bị.
Phương thức này phải trả về một chuỗi mà con người có thể đọc được. Định dạng của chuỗi là tuỳ theo nhà cung cấp. Chuỗi phiên bản phải khác nhau cho mỗi phiên bản mới của trình điều khiển.
Tên của giao diện IDevice
phải tuân theo định dạng {VENDOR}-{DEVICE_NAME}
.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],null,["# Device discovery and assignment\n\n| **Deprecated:** Starting in Android 15, the\n| [NNAPI (NDK API)](https://developer.android.com/ndk/guides/neuralnetworks) is deprecated. The Neural Networks HAL interface\n| continues to be supported.\n|\n| For more information, see the\n| [NNAPI Migration Guide](https://developer.android.com/ndk/guides/neuralnetworks/migration-guide).\n\nIn Android 10, the\n[Neural Networks API (NNAPI)](/docs/core/interaction/neural-networks)\nintroduces functions that allow\nmachine learning framework\nlibraries and apps to get information about the devices available and\nspecify which devices to execute a model on. Providing information about the\navailable devices allows apps to get the exact version of the drivers\nfound on the device to avoid known incompatibilities. By giving apps the\nability to specify which devices are to execute different sections of a model,\napps can be optimized for the product on which they are deployed.\n\nSupport for device discovery and assignment is required for NN HAL 1.2\nimplementations.\n\nImplementation\n--------------\n\nTo support the device discovery and assignment features in NNAPI, implement\n[`getType`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/neuralnetworks/1.2/IDevice.hal#76)\nand\n[`getVersionString`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/neuralnetworks/1.2/IDevice.hal#56)\nin `IDevice.hal` to allow the framework to get the device type and driver\nversion.\n\nFor each device, specify the type as one of the following categories as\nspecified in\n[`DeviceType`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/neuralnetworks/1.2/types.hal#4737)\nin\n[`types.hal`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/neuralnetworks/1.2/types.hal).\n\n- **`OTHER`:** A device that doesn't fall into any of the other categories, including a heterogeneous interface, which is a single `IDevice` interface that manages multiple devices, possibly of different types. A driver with a heterogeneous interface should also expose separate `IDevice` interfaces that correspond to individual devices to allow an application to choose from those devices.\n- **`CPU`:** A single core or multicore CPU.\n- **`GPU`:** A GPU that can run NNAPI models and accelerate graphics APIs such as OpenGL ES and Vulkan.\n- **`ACCELERATOR`:** A dedicated neural processing unit (NPU).\n\nImplement\n[`getVersionString`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/neuralnetworks/1.2/IDevice.hal#56)\nin `IDevice.hal` for getting the version string of the device implementation.\nThis method must return a string that is human readable. The format of the\nstring is vendor specific. The version string must be different for each new\nversion of a driver.\n\nThe name of the `IDevice` interface must follow the `{VENDOR}-{DEVICE_NAME}`\nformat."]]