Integration guide

This document describes how to integrate the Arm NN Android NNAPI driver into an Android source tree.

Prerequisites

  1. Android source tree for Android P (we have tested against Android P version 9.0.0_r3) , in the directory <ANDROID_ROOT>
  2. Android source tree for Android Q (we have tested against Android Q version 10.0.0_r39), in the directory <ANDROID_ROOT>
  3. Mali OpenCL driver integrated into the Android source tree

Note: Arm NN Android NNAPI driver also supports pre-release version of Android R.

Procedure

  1. Place this source directory at <ANDROID_ROOT>/vendor/arm/android-nn-driver
  2. Run setup.sh
  3. Update the Android build environment to add the ArmNN driver. This ensures that the driver service is built and copied to the system/vendor/bin/hw directory in the Android image. To update the build environment, add to the contents of the variable PRODUCT_PACKAGES within the device-specific makefile that is located in the <ANDROID_ROOT>/device/<manufacturer>/<product> directory. This file is normally called device.mk:

For Android P or Q, using NN API version (1.0), the following should be added to device.mk:

For Android P or Q, a new version of the NN API is available (1.1), thus the following should be added to device.mk instead:

For Android Q, a new version of the NN API is available (1.2), thus the following should be added to device.mk instead:

For android.hardware.neuralnetworks@1.3 HAL, thus the following should be added to device.mk instead:

Android.mk contains the module definition of all versions (1.0, 1.1, 1.2 and 1.3) of the ArmNN driver.

Similarly, the Neon, CL or reference backend can be enabled/disabled by setting ARMNN_COMPUTE_CL_ENABLE, ARMNN_COMPUTE_NEON_ENABLE or ARMNN_REF_ENABLE in device.mk:

For Android P and Android Q the vendor manifest.xml requires the Neural Network HAL information. For Android P use HAL version 1.1 as below. For Android Q substitute 1.2 where necessary. For pre-release support of HAL version 1.3, substitute 1.3 where necessary.

<hal format="hidl">
    <name>android.hardware.neuralnetworks</name>
    <transport>hwbinder</transport>
    <version>1.1</version>
    <interface>
        <name>IDevice</name>
        <instance>armnn</instance>
    </interface>
    <fqname>@1.1::IDevice/armnn</fqname>
</hal>
  1. Build Android as normal, i.e. run make in <ANDROID_ROOT>
  2. To confirm that the ArmNN driver has been built, check for driver service executable at

Android P

For example, if the ArmNN driver has been built with the NN API 1.0, check for the following file:

Android Q and later has a different path:

Testing

  1. Run the ArmNN driver service executable in the background. Use the corresponding version of the driver for the Android version you are running. i.e android.hardware.neuralnetworks@1.1-service-armnn for Android P, android.hardware.neuralnetworks@1.2-service-armnn for Android Q and android.hardware.neuralnetworks@1.3-service-armnn for Android R
  1. Run some code that exercises the Android Neural Networks API, for example Android's NeuralNetworksTest unit tests (note this is an optional component that must be built).
  1. To confirm that the ArmNN driver is being used to service the Android Neural Networks API requests, check for messages in logcat with the ArmnnDriver tag.

Using the GPU tuner

The GPU tuner is a feature of the Compute Library that finds optimum values for GPU acceleration tuning parameters. There are three levels of tuning: exhaustive, normal and rapid. Exhaustive means that all lws values are tested. Normal means that a reduced number of lws values are tested, but that generally is sufficient to have a performance close enough to the exhaustive approach. Rapid means that only 3 lws values should be tested for each kernel. The recommended way of using it with ArmNN is to generate the tuning data during development of the Android image for a device, and use it in read-only mode during normal operation:

  1. Run the ArmNN driver service executable in tuning mode. The path to the tuning data must be writable by the service. The following examples assume that the 1.0 version of the driver is being used:
  1. Run a representative set of Android NNAPI testing loads. In this mode of operation, each NNAPI workload will be slow the first time it is executed, as the tuning parameters are being selected. Subsequent executions will use the tuning data which has been generated.
  2. Stop the service.
  3. Deploy the tuned parameters file to a location readable by the ArmNN driver service (for example, to a location within /vendor/etc).
  4. During normal operation, pass the location of the tuning data to the driver service (this would normally be done by passing arguments via Android init in the service .rc definition):