ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
การค้นหาและการกําหนดอุปกรณ์
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ใน Android 10 Neural Networks API (NNAPI) ได้เปิดตัวฟังก์ชันที่ช่วยให้ผู้ใช้ในเฟรมเวิร์กแมชชีนเลิร์นนิงและไลบรารีของแอปรับข้อมูลเกี่ยวกับอุปกรณ์ที่ใช้ได้ รวมถึงระบุอุปกรณ์ที่จะใช้เรียกใช้โมเดล การให้ข้อมูลเกี่ยวกับอุปกรณ์ที่ใช้ได้ช่วยให้แอปรับเวอร์ชันที่แน่นอนของไดรเวอร์ที่พบในอุปกรณ์เพื่อหลีกเลี่ยงการทำงานร่วมกันที่ไม่เข้ากันได้ที่ทราบ การให้แอประบุได้ว่าอุปกรณ์ใดควรเรียกใช้ส่วนต่างๆ ของโมเดล จะช่วยให้แอปได้รับการเพิ่มประสิทธิภาพสำหรับผลิตภัณฑ์ที่ติดตั้งใช้งาน
ต้องมีการรองรับการค้นพบและการกําหนดอุปกรณ์สําหรับการติดตั้งใช้งาน NN HAL 1.2
การใช้งาน
หากต้องการรองรับฟีเจอร์การค้นพบและการกําหนดอุปกรณ์ใน NNAPI ให้ติดตั้งใช้งาน getType
และ getVersionString
ใน IDevice.hal
เพื่อให้เฟรมเวิร์กรับประเภทอุปกรณ์และเวอร์ชันไดรเวอร์
สําหรับอุปกรณ์แต่ละเครื่อง ให้ระบุประเภทเป็นหมวดหมู่ใดหมวดหมู่หนึ่งต่อไปนี้ตามที่ระบุไว้ใน
DeviceType
ใน
types.hal
OTHER
: อุปกรณ์ที่ไม่จัดอยู่ในหมวดหมู่อื่นๆ ซึ่งรวมถึงอินเทอร์เฟซที่หลากหลาย ซึ่งเป็นIDevice
อินเทอร์เฟซเดียวที่จัดการอุปกรณ์หลายเครื่อง ซึ่งอาจเป็นอุปกรณ์ประเภทต่างๆ ไดร์เวอร์ที่มีอินเทอร์เฟซที่หลากหลายควรแสดงIDevice
อินเทอร์เฟซแยกต่างหากซึ่งสอดคล้องกับอุปกรณ์แต่ละเครื่องเพื่อให้แอปพลิเคชันเลือกจากอุปกรณ์เหล่านั้นได้
CPU
: CPU แบบ 1 หรือหลายแกน
GPU
: GPU ที่รันโมเดล NNAPI และเร่ง API กราฟิกได้ เช่น OpenGL ES และ Vulkan
ACCELERATOR
: หน่วยประมวลผลระบบประสาท (NPU) โดยเฉพาะ
ติดตั้งใช้งาน
getVersionString
ใน IDevice.hal
เพื่อรับสตริงเวอร์ชันของการติดตั้งใช้งานอุปกรณ์
เมธอดนี้ต้องแสดงผลสตริงที่มนุษย์อ่านได้ รูปแบบของสตริงจะเจาะจงผู้ให้บริการ สตริงเวอร์ชันต้องแตกต่างกันสำหรับไดรเวอร์เวอร์ชันใหม่แต่ละเวอร์ชัน
ชื่ออินเทอร์เฟซ IDevice
ต้องเป็นไปตามรูปแบบ {VENDOR}-{DEVICE_NAME}
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 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-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."]]