Running ArmNN UnitTests and ONNX mnist model using adb on an Android device
I hope you have successfully built your Arm NN environment. If not, then refer to this and build it first.
Now, after you have successfully setup your Arm NN environment, the next step is to run the UnitTests.
I am using ADB(Android Debug Bridge) to run this file.
Connect your PC or MAC with an Android device using a USB cable. In your device settings, ensure developer options and USB debugging are enabled. The following command will let you know if you’re connected successfully with the device.
adb devices
Now, we need to push(copy) certain files or directories to our device. To do so, the command is -
adb push <path_to_the_local_object> <path_to_the_remote_destination>
To initiate an ADB shell, use
adb shell 'Command_to_execute'
Now, to run the UnitTests executable, you need to push the build results into our device and create symbolic links for shared libraries. The commands for them are listed below -
cd $HOME/armnn-devenv/armnn/buildadb push libarmnn.so /data/local/tmp/adb push libtimelineDecoder.so /data/local/tmp/adb push UnitTests /data/local/tmp/adb push $NDK/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so /data/local/tmp/adb push $HOME/armnn-devenv/google/arm64_pb_install/lib/libprotobuf.so /data/local/tmp/libprotobuf.so.23.0.0adb push libarmnnTfLiteParser.so /data/local/tmp/adb push libarmnnOnnxParser.so /data/local/tmp/adb push libtimelineDecoderJson.so /data/local/tmp/adb push libarmnnBasePipeServer.so /data/local/tmp/adb shell 'ln -s libprotobuf.so.23.0.0 /data/local/tmp/libprotobuf.so.23'adb shell 'ln -s libprotobuf.so.23.0.0 /data/local/tmp/libprotobuf.so'
Additionally, push the necessary files and directories needed for the unit tests using the following commands-
adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/testSharedObjectadb push -p $HOME/armnn-devenv/armnn/build/src/backends/backendsCommon/test/testSharedObject/* /data/local/tmp/src/backends/backendsCommon/test/testSharedObject/
adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/testDynamicBackendadb push -p $HOME/armnn-devenv/armnn/build/src/backends/backendsCommon/test/testDynamicBackend/* /data/local/tmp/src/backends/backendsCommon/test/testDynamicBackend/
adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath1adb push -p $HOME/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath1/* /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath1/adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2adb push -p $HOME/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/adb shell ln -s Arm_CpuAcc_backend.so /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so.1adb shell ln -s Arm_CpuAcc_backend.so.1 /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so.1.2adb shell ln -s Arm_CpuAcc_backend.so.1.2 /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so.1.2.3adb push -p $HOME/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath2/Arm_GpuAcc_backend.so /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/adb shell ln -s nothing /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/Arm_no_backend.so
adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath3
adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath5adb push -p $HOME/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath5/* /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath5/
adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath6adb push -p $HOME/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath6/* /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath6/
adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath7
adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath9adb push -p $HOME/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath9/* /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath9/
adb shell mkdir -p /data/local/tmp/src/backends/dynamic/referenceadb push -p $HOME/armnn-devenv/armnn/build/src/backends/dynamic/reference/Arm_CpuRef_backend.so /data/local/tmp/src/backends/dynamic/reference/
adb shell mkdir -p /data/local/tmp/dynamic/sample/adb push -p $HOME/armnn-devenv/armnn/src/dynamic/sample/build/libArm_SampleDynamic_backend.so /data/local/tmp/dynamic/sample/
Now, running Arm NN unit tests -
adb shell ‘LD_LIBRARY_PATH=/data/local/tmp:/vendor/lib64:/vendor/lib64/egl /data/local/tmp/UnitTests -t Compute_ArmComputeNeon’
NOTE: If your Android’s processor has no OpenCL support, then you need to use ‘-t Compute_ArmComputeNeon’ switch in the above command, otherwise it will not work.
Now, let’s move on to running an ONNX model.
If you’ve build the ArmNN properly, an executable file named OnnxMnist-Armnn will be present in $HOME/armnn-devenv/armnn/build/tests/. Also, you need a dataset and mnist_onnx.onnx file.
Push all these files in a folder in your android device using the following commands-
cd $HOME/armnn-devenv/armnn/buildadb shell mkdir -p /data/local/tmp/mnistadb push -p tests/OnnxMnist-Armnn /data/local/tmp/mnist
In the below given commands, replace path_to_t10k-images.idx3-ubyte, path_to_t10k-labels.idx1-ubyte and path_to_mnist_onnx.onnx with paths to t10k-images.idx3-ubyte, t10k-labels.idx1-ubyte and mnist_onnx.onnx files.
EXAMPLE- If your t10k-images.idx3-ubyte is present in $HOME/Downloads directory, then path_to_t10k-images.idx3-ubyte will be replaced by $HOME/Downloads/t10k-images.idx3-ubyte
adb push -p path_to_t10k-images.idx3-ubyte /data/local/tmp/mnistadb push -p path_to_t10k-labels.idx1-ubyte /data/local/tmp/mnistadb push -p path_to_mnist_onnx.onnx /data/local/tmp/mnist
Now, let’s run the model using the below command-
adb shell ‘LD_LIBRARY_PATH=/data/local/tmp:/vendor/lib64:/vendor/lib64/egl /data/local/tmp/mnist/OnnxMnist-Armnn --data-dir /data/local/tmp/mnist --model-dir /data/local/tmp/mnist/ -t Compute_ArmComputeNeon’
Hope, you were able to run your model successfully.
Happy Learning.