2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、AOSP の変更をご覧ください。
デバイスの検出と割り当て
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Android 10 では、ニューラル ネットワーク API(NNAPI)に、機械学習フレームワーク ライブラリとアプリが使用可能なデバイスに関する情報を取得し、モデルを実行するデバイスを指定できるようにする機能が導入されました。アプリは、使用可能なデバイスに関する情報を得ることにより、デバイスで見つかったドライバの正確なバージョンから、既知の非互換性の問題を回避できるようになります。実行するデバイスをモデルのセクションごとに指定できるようになるため、デプロイする製品に合わせてアプリを最適化できます。
NN HAL 1.2 の実装には、デバイスの検出と割り当てのサポートが必要です。
実装
NNAPI でデバイスの検出と割り当ての機能をサポートするには、IDevice.hal
の getType
と getVersionString
を実装して、フレームワークがデバイスのタイプとドライバのバージョンを取得できるようにします。
types.hal
の DeviceType
で指定されているとおり、デバイスごとに、次のいずれかのカテゴリとしてタイプを指定します。
OTHER
: 他のいずれのカテゴリにも属さないデバイス。(場合によってはタイプが異なる)複数のデバイスを管理する単一の IDevice
インターフェースである異種インターフェースを含みます。異種インターフェースのドライバは、個々のデバイスに対応する個別の IDevice
インターフェースを公開し、アプリがこれらのデバイスから選択できるようにする必要もあります。
CPU
: シングルコアまたはマルチコア CPU。
GPU
: NNAPI モデルを実行し、OpenGL ES や Vulkan などのグラフィック API を高速化できる GPU。
ACCELERATOR
: 専用ニューラル プロセッシング ユニット(NPU)。
IDevice.hal
で getVersionString
を実装して、デバイス実装のバージョン文字列を取得します。このメソッドは、人間が読める文字列を返す必要があります。文字列の形式はベンダー固有です。バージョン文字列は、ドライバの新しいバージョンごとに異なる必要があります。
IDevice
インターフェースの名前は、{VENDOR}-{DEVICE_NAME}
形式に従う必要があります。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-03-26 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-03-26 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."]]