Od 27 marca 2025 r. zalecamy używanie android-latest-release
zamiast aosp-main
do kompilowania i wspołtworzenia AOSP. Więcej informacji znajdziesz w artykule o zmianach w AOSP.
Wykrywanie i przypisywanie urządzeń
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
W Androidzie 10 interfejs Neural Networks API (NNAPI) udostępnia funkcje, które umożliwiają bibliotekom i aplikacjom korzystającym z ramowego oprogramowania uczenia maszynowego uzyskiwanie informacji o dostępnych urządzeniach oraz określanie, na których urządzeniach ma być wykonywany model. Podanie informacji o dostępnych urządzeniach umożliwia aplikacjom pobieranie dokładnej wersji sterowników znalezionych na urządzeniu, aby uniknąć znanych niezgodności. Dzięki temu aplikacje mogą optymalizować działanie pod kątem produktu, na którym są wdrażane.
W przypadku implementacji NN HAL 1.2 wymagana jest obsługa wykrywania i przypisywania urządzeń.
Implementacja
Aby obsługiwać funkcje wykrywania i przypisywania urządzeń w NNAPI, wprowadź getType
i getVersionString
w IDevice.hal
, aby umożliwić frameworkowi uzyskanie typu urządzenia i wersji sterownika.
W przypadku każdego urządzenia określ typ jako jedną z tych kategorii:DeviceType
types.hal
.
OTHER
: urządzenie, które nie pasuje do żadnej z pozostałych kategorii, w tym do heterogenicznego interfejsu, który jest pojedynczym interfejsem IDevice
, zarządzającym wieloma urządzeniami, prawdopodobnie różnych typów. Sterownik z heterogenicznym interfejsem powinien też udostępniać osobne interfejsy IDevice
odpowiadające poszczególnym urządzeniom, aby aplikacja mogła je wybierać.
CPU
: procesor jedno- lub wielordzeniowy.
GPU
: procesor graficzny, który może uruchamiać modele NNAPI i przyspieszać interfejsy API do grafiki, takie jak OpenGL ES i Vulkan.
ACCELERATOR
: dedykowana jednostka przetwarzania neuronowego (NPU).
Zaimplementuj funkcję getVersionString
w IDevice.hal
, aby pobrać ciąg znaków wersji implementacji urządzenia.
Ta metoda musi zwracać ciąg tekstowy zrozumiały dla człowieka. Format ciągu jest specyficzny dla danego dostawcy. Ciąg znaków wersji musi być inny w przypadku każdej nowej wersji sterownika.
Nazwa interfejsu IDevice
musi być zgodna z formatem {VENDOR}-{DEVICE_NAME}
.
Treść strony i umieszczone na niej fragmenty kodu podlegają licencjom opisanym w Licencji na treści. Java i OpenJDK są znakami towarowymi lub zastrzeżonymi znakami towarowymi należącymi do firmy Oracle lub jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-27 UTC.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 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."]]