diff options
-rw-r--r-- | BuildGuideAndroidNDK.md | 364 | ||||
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rwxr-xr-x | scripts/build_android_ndk_guide.sh | 459 | ||||
-rw-r--r-- | src/backends/backendsCommon/test/CMakeLists.txt | 7 |
4 files changed, 693 insertions, 139 deletions
diff --git a/BuildGuideAndroidNDK.md b/BuildGuideAndroidNDK.md index c61a4fe5ee..7c6f224693 100644 --- a/BuildGuideAndroidNDK.md +++ b/BuildGuideAndroidNDK.md @@ -1,132 +1,151 @@ # How to use the Android NDK to build Arm NN - [Introduction](#introduction) +- [Initial Setup](#initial-setup) - [Download the Android NDK and make a standalone toolchain](#download-the-android-ndk-and-make-a-standalone-toolchain) - [Install Cmake](#install-cmake) -- [Build Google's Protobuf library](#build-google-s-protobuf-library) - [Build Flatbuffers](#build-flatbuffers) - [Download Arm NN](#download-arm-nn) +- [Get And Build TFLite](#get-and-build-tflite) - [Build Arm Compute Library](#build-arm-compute-library) - [Build Arm NN](#build-arm-nn) - [Build Standalone Sample Dynamic Backend](#build-standalone-sample-dynamic-backend) -- [Run the Arm NN unit tests on an Android device](#run-the-armnn-unit-tests-on-an-android-device) +- [Run the Arm NN unit tests on an Android device](#run-the-arm-nn-unit-tests-on-an-android-device) ## Introduction -These are step by step instructions for using the Android NDK to build Arm NN. -They have been tested on a clean install of Ubuntu 18.04 and 20.04, and should also work with other OS versions. -The instructions show how to build the Arm NN core library. -Building protobuf is optional. We have given steps should the user wish to build it (i.e. as an Onnx dependency). -All downloaded or generated files will be saved inside the `$HOME/armnn-devenv` directory. +These are step-by-step instructions for using the Android NDK to build Arm NN. +They have been tested on a clean installation of Ubuntu 18.04 and 20.04, and should also work with other OS versions. +The instructions show how to build the Arm NN core library and its dependencies. +For ease of use there is a shell script version of this guide located in the scripts directory called [build_android_ndk_guide.sh](scripts/build_android_ndk_guide.sh). +Run the script with a -h flag to see the command line parameters. -## Download the Android NDK and make a standalone toolchain - -* Download the Android NDK from [the official website](https://developer.android.com/ndk/downloads/index.html): - ```bash - mkdir -p $HOME/armnn-devenv/ - cd $HOME/armnn-devenv/ - # For Mac OS, change the NDK download link accordingly. - wget https://dl.google.com/android/repository/android-ndk-r25-linux.zip - unzip android-ndk-r25.zip - export NDK=$HOME/armnn-devenv/android-ndk-r25 - export NDK_TOOLCHAIN_ROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64 - export PATH=$NDK_TOOLCHAIN_ROOT/bin/:$PATH +## Initial Setup - # You may want to append the above export variables commands to your `~/.bashrc` (or `~/.bash_profile` in Mac OS). - ``` +First, we need to specify the Android version and the directories you want to build armnn in and to install some applications required to build Arm NN and its dependencies. -* With the android ndk-25, you don't need to use the make_standalone_toolchain script to create a toolchain for a specific version of android. Android's current preference is for you to just specify the architecture and operating system while setting the compiler and just use the ndk directory. +```bash +export ANDROID_API=30 +export WORKING_DIR=$HOME/armnn-devenv +export NDK_DIR=$WORKING_DIR/android-ndk-r25 +export NDK_TOOLCHAIN_ROOT=$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64 +export PATH=$NDK_TOOLCHAIN_ROOT/bin/:$PATH +``` +You may want to append the above export variables commands to your `~/.bashrc` (or `~/.bash_profile` in macOS). -## Install Cmake -Cmake 3.19rc3 is required to build Arm NN. +The ANDROID_API variable should be set to the Android API version number you are using. For example, "30" for Android R. The WORKING_DIR can be any directory you have write permissions to. +### Required Applications +Git is required to obtain Arm NN. If this has not been already installed then install it using: ```bash -cd $HOME/armnn-devenv -sudo apt-get install libssl-dev -wget https://github.com/Kitware/CMake/releases/download/v3.19.0-rc3/cmake-3.19.0-rc3.tar.gz -tar -zxvf cmake-3.19.0-rc3.tar.gz -cd cmake-3.19.0-rc3 -./bootstrap --prefix=$HOME/armnn-devenv/cmake/install -make all install -cd.. +sudo apt install git ``` -## Build Google's Protobuf library (Optional) - -* Clone protobuf: - (Requires Git if not previously installed: `sudo apt install git`) +Arm Compute Library requires SCons. If this has not been already installed then install it using: ```bash -mkdir $HOME/armnn-devenv/google -cd $HOME/armnn-devenv/google -git clone https://github.com/google/protobuf.git -cd protobuf -git checkout -b v3.12.0 v3.12.0 +sudo apt install scons ``` -* Build a native (x86) version of the protobuf libraries and compiler (protoc): - (Requires cUrl, autoconf, llibtool, and other build dependencies if not previously installed: `sudo apt install curl autoconf libtool build-essential g++`) +CMake is required to build Arm NN and its dependencies. If this has not been already installed then install it using: ```bash -./autogen.sh -mkdir x86_64_build -cd x86_64_build -../configure --prefix=$HOME/armnn-devenv/google/x86_64_pb_install -make install -j16 -cd .. +sudo apt install cmake ``` -* Build the arm64 version of the protobuf libraries: +## Download the Android NDK and make a standalone toolchain + +Download the Android NDK from [the official website](https://developer.android.com/ndk/downloads/index.html): ```bash -mkdir arm64_build -cd arm64_build -CC=aarch64-linux-android<Android_API>-clang \ -CXX=aarch64-linux-android<Android_API>-clang++ \ -CFLAGS="-fPIE -fPIC" \ - LDFLAGS="-llog -lz -lc++_static" \ - ../configure --host=aarch64-linux-android \ - --prefix=$HOME/armnn-devenv/google/arm64_pb_install \ - --enable-cross-compile \ - --with-protoc=$HOME/armnn-devenv/google/x86_64_pb_install/bin/protoc -make install -j16 -cd .. +mkdir -p $WORKING_DIR +cd $WORKING_DIR +# For Mac OS, change the NDK download link accordingly. +wget https://dl.google.com/android/repository/android-ndk-r25-linux.zip +unzip android-ndk-r25-linux.zip ``` +With Android NDK-25, you no longer need to use the make_standalone_toolchain script to create a toolchain for a specific version of Android. Android's current preference is for you to just specify the architecture and operating system while setting the compiler and just use the ndk directory. + +## Install Cmake +Cmake 3.19rc3 or later is required to build Arm NN. If you are using Ubuntu 20.04 the command given in [Initial Setup](#initial-setup) should install a usable version. If you're using Ubuntu 18.04 you may need to compile cmake yourself. -Note: The ANDROID_API variable should be set to the Android API version number you are using. E.g. "30" for Android R. +```bash +cd $WORKING_DIR +sudo apt-get install libssl-dev +wget https://github.com/Kitware/CMake/releases/download/v3.19.0-rc3/cmake-3.19.0-rc3.tar.gz +tar -zxvf cmake-3.19.0-rc3.tar.gz +cd cmake-3.19.0-rc3 +./bootstrap --prefix=$WORKING_DIR/cmake/install +make all install +cd.. +``` ## Build Flatbuffers -* Download Flatbuffers +Download Flatbuffers: ```bash -cd $HOME/armnn-devenv +cd $WORKING_DIR wget https://github.com/google/flatbuffers/archive/v2.0.6.tar.gz tar xf v2.0.6.tar.gz ``` -* Build Flatbuffers +Build Flatbuffers for x86: ```bash -cd flatbuffers-2.0.6 +cd $WORKING_DIR/flatbuffers-2.0.6 + rm -f CMakeCache.txt -rm -rf build -mkdir build -cd build + +rm -rf build-x86 +mkdir build-x86 +cd build-x86 + +rm -rf $WORKING_DIR/flatbuffers-x86 +mkdir $WORKING_DIR/flatbuffers-x86 + CXXFLAGS="-fPIC" $CMAKE .. \ - -DFLATBUFFERS_BUILD_FLATC=1 \ - -DCMAKE_INSTALL_PREFIX:PATH=$WORKING_DIR/flatbuffers + -DFLATBUFFERS_BUILD_FLATC=1 \ + -DCMAKE_INSTALL_PREFIX:PATH=$WORKING_DIR/flatbuffers-x86 -make all install +make all install -j16 ``` Note: -fPIC is added to allow users to use the libraries in shared objects. +Build Flatbuffers for Android: +```bash +cd $WORKING_DIR/flatbuffers-2.0.6 + +rm -f CMakeCache.txt + +rm -rf build-android +mkdir build-android +cd build-android + +rm -rf $WORKING_DIR/flatbuffers-android +mkdir $WORKING_DIR/flatbuffers-android + +CC=/usr/bin/aarch64-linux-gnu-gcc CXX=/usr/bin/aarch64-linux-gnu-g++ \ +CXXFLAGS="-fPIC" \ +cmake .. \ + -DCMAKE_ANDROID_NDK=$NDK_DIR \ + -DCMAKE_SYSTEM_NAME=Android \ + -DCMAKE_SYSTEM_VERSION=27 \ + -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \ + -DCMAKE_CXX_FLAGS=--std=c++14 \ + -DFLATBUFFERS_BUILD_FLATC=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + -DFLATBUFFERS_BUILD_TESTS=OFF \ + -DCMAKE_INSTALL_PREFIX=$WORKING_DIR/flatbuffers-android + +make all install -j16 +``` + ## Download Arm NN -* Clone Arm NN: - (Requires Git if not previously installed: `sudo apt install git`) +Clone Arm NN: ```bash -cd $HOME/armnn-devenv +cd $WORKING_DIR git clone https://github.com/ARM-software/armnn.git ``` -* Checkout Arm NN branch: +Checkout the Arm NN branch: ```bash cd armnn git checkout <branch_name> @@ -135,69 +154,133 @@ git pull For example, if you want to check out the 23.02 release branch: ```bash +cd armnn git checkout branches/armnn_23_02 git pull ``` +## Get And Build TFLite +This optional step is only required if you intend to build the TFLite delegate or parser for Arm NN. + +First clone tensorflow: +```bash +cd $WORKING_DIR +git clone https://github.com/tensorflow/tensorflow.git +cd tensorflow +git fetch && git checkout "tags/v2.10.0" +``` +Arm NN provides a script that downloads the version of Tensorflow that Arm NN was tested with: +```bash +git fetch && git checkout $(../armnn/scripts/get_tensorflow.sh -p) +``` +Next build Tensorflow Lite: +```bash +cd $WORKING_DIR +mkdir -p tflite-out/android +cd tflite-out/android + +CMARGS="-DCMAKE_TOOLCHAIN_FILE=$NDK_DIR/build/cmake/android.toolchain.cmake \ + -DANDROID_ABI=arm64-v8a \ + -DANDROID_PLATFORM=$ANDROID_API" + +cmake $CMARGS $WORKING_DIR/tensorflow/tensorflow/lite + +cd $WORKING_DIR +cmake --build tflite-out/android -j 16 +``` +Now generate the Tensorflow Lite Schema for the TFLite parser: +```bash +cd $WORKING_DIR +mkdir -p $WORKING_DIR/tflite-out/tensorflow/tensorflow/lite/schema + +SCHEMA_LOCATION=$WORKING_DIR/tensorflow/tensorflow/lite/schema/schema.fbs +cp $SCHEMA_LOCATION $WORKING_DIR/tflite-out/tensorflow/tensorflow/lite/schema + +cd $WORKING_DIR/tflite-out/tensorflow/tensorflow/lite/schema +$WORKING_DIR/flatbuffers-x86/bin/flatc -c --gen-object-api --reflect-types --reflect-names schema.fbs +``` + ## Build Arm Compute Library -* Clone Arm Compute Library: +Clone Arm Compute Library: ```bash -cd $HOME/armnn-devenv +cd $WORKING_DIR git clone https://github.com/ARM-software/ComputeLibrary.git ``` -* Checkout Arm Compute Library release tag: +Checkout Arm Compute Library release tag: ```bash cd ComputeLibrary git checkout <tag_name> ``` -For example, if you want to checkout the 23.02 release tag: +For example, if you want to check out the 23.02 release tag: ```bash +cd ComputeLibrary git checkout v23.02 ``` -Arm NN and Arm Compute Library are developed closely together. If you would like to use a particular release of Arm NN you will need the same release tag of ACL too. - +Arm NN and Arm Compute Library are developed closely together. To use a particular version of Arm NN you will need a compatible version of ACL. Arm NN provides a script that downloads the version of Arm Compute Library that Arm NN was tested with: ```bash git checkout $(../armnn/scripts/get_compute_library.sh -p) ``` -* the Arm Compute Library: - (Requires SCons if not previously installed: `sudo apt install scons`) +Build the Arm Compute Library: ```bash -scons arch=arm64-v8a neon=1 opencl=1 embed_kernels=1 extra_cxx_flags="-fPIC" \ - benchmark_tests=0 validation_tests=0 os=android -j16 +scons arch=arm64-v8a os=android toolchain_prefix=llvm- compiler_prefix=aarch64-linux-android$ANDROID_API- \ + neon=1 opencl=1 embed_kernels=1 extra_cxx_flags="-fPIC" \ + benchmark_tests=0 validation_tests=0 -j16 ``` ## Build Arm NN -* Build Arm NN: - (Requires CMake if not previously installed: `sudo apt install cmake`) +Build Arm NN: + ```bash -mkdir $HOME/armnn-devenv/armnn/build -cd $HOME/armnn-devenv/armnn/build -CXX=aarch64-linux-android<Android_API>-clang++ \ -CC=aarch64-linux-android<Android_API>-clang \ +mkdir $WORKING_DIR/armnn/build +cd $WORKING_DIR/armnn/build +CXX=aarch64-linux-android$ANDROID_API-clang++ \ +CC=aarch64-linux-android$ANDROID_API-clang \ CXX_FLAGS="-fPIE -fPIC" \ cmake .. \ - -DCMAKE_ANDROID_NDK=$NDK \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_ANDROID_NDK=$NDK_DIR \ + -DNDK_VERSION=r25 \ -DCMAKE_SYSTEM_NAME=Android \ - -DCMAKE_SYSTEM_VERSION=<Android_API> \ + -DCMAKE_SYSTEM_VERSION=$ANDROID_API \ -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \ - -DCMAKE_EXE_LINKER_FLAGS="-pie -llog -lz" \ - -DARMCOMPUTE_ROOT=$HOME/armnn-devenv/ComputeLibrary/ \ - -DARMCOMPUTE_BUILD_DIR=$HOME/armnn-devenv/ComputeLibrary/build \ + -DCMAKE_SYSROOT=$WORKING_DIR/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/sysroot \ + -DARMCOMPUTE_ROOT=$WORKING_DIR/ComputeLibrary \ + -DARMCOMPUTE_BUILD_DIR=$WORKING_DIR/ComputeLibrary/build \ -DARMCOMPUTENEON=1 -DARMCOMPUTECL=1 -DARMNNREF=1 \ - -DPROTOBUF_ROOT=$HOME/armnn-devenv/google/arm64_pb_install/ - -DFLATBUFFERS_ROOT=$HOME/armnn-devenv/flatbuffers \ - -DFLATC_DIR=$HOME/armnn-devenv/flatbuffers-2.0.6/build \ + -DFLATBUFFERS_INCLUDE_PATH=$WORKING_DIR/flatbuffers-x86/include \ + -DFLATBUFFERS_ROOT=$WORKING_DIR/flatbuffers-android \ + -DFLATC_DIR=$WORKING_DIR/flatbuffers-x86 \ + -DBUILD_UNIT_TESTS=1 \ + -fexception +``` + +To include the Arm NN TFLite delegate add these arguments to the above list: + +```bash + -DBUILD_ARMNN_TFLITE_DELEGATE=1 \ + -DTENSORFLOW_ROOT=$WORKING_DIR/tensorflow \ + -DTFLITE_LIB_ROOT=$WORKING_DIR/tflite-out/android \ + -DTFLITE_ROOT_DIR=$WORKING_DIR/tensorflow/tensorflow/lite \ +``` + +To include the Arm NN TFLite Parser add these arguments to the above list: + +```bash + -DBUILD_TF_LITE_PARSER=1 \ + -DTF_LITE_GENERATED_PATH=$WORKING_DIR/tflite-out/tensorflow/tensorflow/lite/schema \ + -DTENSORFLOW_ROOT=$WORKING_DIR/tensorflow \ + -DTFLITE_LIB_ROOT=$WORKING_DIR/tflite-out/android \ ``` -To include standalone sample dynamic backend tests, add the argument to enable the tests and the dynamic backend path to the CMake command: +To include standalone sample dynamic backend tests, add these arguments to enable the tests and the dynamic backend path to the CMake command: ```bash --DSAMPLE_DYNAMIC_BACKEND=1 \ --DDYNAMIC_BACKEND_PATHS=$SAMPLE_DYNAMIC_BACKEND_PATH + -DSAMPLE_DYNAMIC_BACKEND=1 \ + -DDYNAMIC_BACKEND_PATHS=$SAMPLE_DYNAMIC_BACKEND_PATH # Where $SAMPLE_DYNAMIC_BACKEND_PATH is the path where libArm_SampleDynamic_backend.so library file is pushed ``` @@ -207,7 +290,7 @@ make -j16 ``` ## Build Standalone Sample Dynamic Backend -* The sample dynamic backend is located in armnn/src/dynamic/sample +This step is optional. The sample dynamic backend is located in armnn/src/dynamic/sample ```bash mkdir build cd build @@ -216,21 +299,21 @@ cd build * Use CMake to configure the build environment, update the following script and run it from the armnn/src/dynamic/sample/build directory to set up the Arm NN build: ```bash #!/bin/bash -CXX=aarch64-linux-android<Android_API>-clang++ \ -CC=aarch64-linux-android<Android_API>-clang \ +CXX=aarch64-linux-android$ANDROID_API-clang++ \ +CC=aarch64-linux-android$ANDROID_API-clang \ CXX_FLAGS="-fPIE -fPIC" \ cmake \ --DCMAKE_C_COMPILER_WORKS=TRUE \ --DCMAKE_CXX_COMPILER_WORKS=TRUE \ --DCMAKE_ANDROID_NDK=$NDK \ --DCMAKE_SYSTEM_NAME=Android \ --DCMAKE_SYSTEM_VERSION=$ANDROID_API \ --DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \ --DCMAKE_SYSROOT=$HOME/armnn-devenv/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/sysroot \ --DCMAKE_CXX_FLAGS=--std=c++14 \ --DCMAKE_EXE_LINKER_FLAGS="-pie -llog" \ --DCMAKE_MODULE_LINKER_FLAGS="-llog" \ --DARMNN_PATH=$HOME/armnn-devenv/armnn/build/libarmnn.so .. + -DCMAKE_C_COMPILER_WORKS=TRUE \ + -DCMAKE_CXX_COMPILER_WORKS=TRUE \ + -DCMAKE_ANDROID_NDK=$NDK_DIR \ + -DCMAKE_SYSTEM_NAME=Android \ + -DCMAKE_SYSTEM_VERSION=$ANDROID_API \ + -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \ + -DCMAKE_SYSROOT=$WORKING_DIR/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/sysroot \ + -DCMAKE_CXX_FLAGS=--std=c++14 \ + -DCMAKE_EXE_LINKER_FLAGS="-pie -llog" \ + -DCMAKE_MODULE_LINKER_FLAGS="-llog" \ + -DARMNN_PATH=$WORKING_DIR/armnn/build/libarmnn.so .. ``` * Run the build @@ -247,56 +330,63 @@ make adb 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.0 -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' +adb push $NDK_DIR/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so /data/local/tmp/ ``` * Push the files needed for the unit tests (they are a mix of files, directories and symbolic links): ```bash adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/testSharedObject -adb push -p $HOME/armnn-devenv/armnn/build/src/backends/backendsCommon/test/testSharedObject/* /data/local/tmp/src/backends/backendsCommon/test/testSharedObject/ +adb push -p $WORKING_DIR/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/testDynamicBackend -adb push -p $HOME/armnn-devenv/armnn/build/src/backends/backendsCommon/test/testDynamicBackend/* /data/local/tmp/src/backends/backendsCommon/test/testDynamicBackend/ +adb push -p $WORKING_DIR/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/backendsTestPath1 -adb push -p $HOME/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath1/* /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath1/ +adb push -p $WORKING_DIR/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/backendsTestPath2 -adb 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 push -p $WORKING_DIR/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.1 adb shell ln -s Arm_CpuAcc_backend.so.1 /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so.1.2 adb shell ln -s Arm_CpuAcc_backend.so.1.2 /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so.1.2.3 -adb 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 push -p $WORKING_DIR/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/backendsTestPath5 -adb push -p $HOME/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath5/* /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath5/ +adb push -p $WORKING_DIR/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/backendsTestPath6 -adb push -p $HOME/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath6/* /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath6/ +adb push -p $WORKING_DIR/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/backendsTestPath9 -adb push -p $HOME/armnn-devenv/armnn/build/src/backends/backendsCommon/test/backendsTestPath9/* /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath9/ +adb push -p $WORKING_DIR/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/reference -adb push -p $HOME/armnn-devenv/armnn/build/src/backends/dynamic/reference/Arm_CpuRef_backend.so /data/local/tmp/src/backends/dynamic/reference/ +adb push -p $WORKING_DIR/armnn/build/src/backends/dynamic/reference/Arm_CpuRef_backend.so /data/local/tmp/src/backends/dynamic/reference/ +``` -# If the standalone sample dynamic tests are enabled, also push libArm_SampleDynamic_backend.so library file to the folder specified as $SAMPLE_DYNAMIC_BACKEND_PATH when Arm NN is built. -# This is the example when $SAMPLE_DYNAMIC_BACKEND_PATH is specified as /data/local/tmp/dynamic/sample/: +If the standalone sample dynamic tests are enabled, also push libArm_SampleDynamic_backend.so library file to the folder specified as $SAMPLE_DYNAMIC_BACKEND_PATH when Arm NN is built. +This is the example when $SAMPLE_DYNAMIC_BACKEND_PATH is specified as /data/local/tmp/dynamic/sample/: +```bash 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/ +adb push -p $WORKING_DIR/armnn/src/dynamic/sample/build/libArm_SampleDynamic_backend.so /data/local/tmp/dynamic/sample/ ``` - -* Run Arm NN unit tests: +If the delegate was built, push the delegate unit tests too. +```bash +adb push $WORKING_DIR/armnn/build/delegate/DelegateUnitTests /data/local/tmp/ +adb push $WORKING_DIR/armnn/build/delegate/libarmnnDelegate.so /data/local/tmp/ +``` +Run Arm NN unit tests: ```bash adb shell 'LD_LIBRARY_PATH=/data/local/tmp:/vendor/lib64:/vendor/lib64/egl /data/local/tmp/UnitTests' ``` -If libarmnnUtils.a is present in `$HOME/armnn-devenv/armnn/build/` and the unit tests run without failure then the build was successful. +If the delegate was built run Arm Delegate NN unit tests: +```bash +adb shell 'LD_LIBRARY_PATH=/data/local/tmp:/vendor/lib64:/vendor/lib64/egl /data/local/tmp/DelegateUnitTests' +``` +If libarmnnUtils.a is present in `$WORKING_DIR/armnn/build/` and the unit tests run without failure then the build was successful. diff --git a/CMakeLists.txt b/CMakeLists.txt index 37dba7c1ac..edb1485126 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -593,7 +593,6 @@ if(BUILD_UNIT_TESTS) src/armnn/test/optimizations/FoldPadTests.cpp src/armnn/test/optimizations/Fp32NetworkToFp16ConverterTests.cpp src/armnn/test/optimizations/FuseActivationTests.cpp - src/armnn/test/optimizations/FuseBatchNormTests.cpp src/armnn/test/optimizations/InsertDebugLayerTests.cpp src/armnn/test/optimizations/MovePermuteUpTests.cpp src/armnn/test/optimizations/MoveTransposeUpTests.cpp @@ -655,6 +654,7 @@ if(BUILD_UNIT_TESTS) if(ARMNNREF) list(APPEND unittest_sources + src/armnn/test/optimizations/FuseBatchNormTests.cpp src/armnn/test/DebugCallbackTest.cpp src/armnn/test/RuntimeTests.cpp src/armnn/test/RuntimeTests.hpp diff --git a/scripts/build_android_ndk_guide.sh b/scripts/build_android_ndk_guide.sh new file mode 100755 index 0000000000..4d9689e6a0 --- /dev/null +++ b/scripts/build_android_ndk_guide.sh @@ -0,0 +1,459 @@ +#!/bin/bash +# +# Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +# +# SPDX-License-Identifier: MIT +# + +function Usage() { + echo "This script builds Arm NN for Android using the Android NDK. The script builds" + echo "the Arm NN core library and its dependencies." + echo "" + echo "Usage: $CMD [options]" + echo "Options:" + echo " -l Use this copy of Arm NN and ComputeLibrary instead of cloning new copies" + echo " <1 or 0> defaults to 1" + echo " -a Override Arm NN branch (defaults to latest release branches/armnn_23_02)" + echo " -b Override ACL branch (defaults to latest release v23.02)" + echo " -A Android API level defaults to 30" + echo " -n Neon (CpuAcc backend) enabled <1 or 0> defaults to 1" + echo " -g CL (GpuAcc backend) enabled <1 or 0> defaults to 1" + echo " -r Reference (CpuRef backend) enabled <1 or 0> defaults to 1" + echo " -u Build unit tests <1 or 0> defaults to 1" + echo " -d TfLite Delegate enabled <1 or 0> defaults to 1" + echo " -p TfLite Parser enabled <1 or 0> defaults to 1" + echo " -s Dynamic Sample enabled <1 or 0> defaults to 0" + echo " -i Installation directory defaults to ~/armnn-devenv" + echo " -t Push to board and run tests <1 or 0> defaults to 0" + + exit 1 +} + +function AssertZeroExitCode { + EXITCODE=$? + if [[ $EXITCODE -ne 0 ]]; then + echo -e "Previous command exited with code $EXITCODE" + exit 1 + fi +} + +THIS_FILE=$(readlink -f "$0") +BASE_DIR=$(dirname "$THIS_FILE") + +# Set variables and working directory +CREATE_LINKS=1 +ARMNN_BRANCH=branches/armnn_23_02 +ACL_BRANCH=v23.02 +ACL_NEON=1 +ACL_CL=1 +REFERENCE=1 +BUILD_TESTS=1 +DELEGATE=1 +TFLITE_PARSER=1 +DYNAMIC_SAMPLE=0 +CMAKE=$(which cmake) +WORKING_DIR=$HOME/armnn-devenv + +ANDROID_API=30 +PUSH_TO_BOARD=0 + +# Parse the command line arguments to get build type +while getopts "hl:a:c:A:n:g:r:u:d:p:s:i:t:" opt; do + ((OPTION_COUNTER+=1)) + case "$opt" in + h|\?) Usage;; + l) CREATE_LINKS=$OPTARG;; + a) ARMNN_BRANCH=$OPTARG;; + c) ACL_BRANCH=$OPTARG;; + A) ANDROID_API=$OPTARG;; + n) ACL_NEON=$OPTARG;; + g) ACL_CL=$OPTARG;; + r) REFERENCE=$OPTARG;; + u) BUILD_TESTS=$OPTARG;; + d) DELEGATE=$OPTARG;; + p) TFLITE_PARSER=$OPTARG;; + s) DYNAMIC_SAMPLE=$OPTARG;; + i) WORKING_DIR=$OPTARG;; + t) PUSH_TO_BOARD=$OPTARG;; + esac +done +shift $((OPTIND - 1)) + +export NDK_DIR=$WORKING_DIR/android-ndk-r25 +export NDK_TOOLCHAIN_ROOT=$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64 +export PATH=$NDK_TOOLCHAIN_ROOT/bin/:$PATH + +pushd $WORKING_DIR + +function GetAndroidNDK { + cd $WORKING_DIR + if [[ ! -d android-ndk-r25 ]]; then + echo "+++ Getting Android NDK" + wget https://dl.google.com/android/repository/android-ndk-r25-linux.zip + unzip android-ndk-r25-linux.zip + fi +} + +function GetAndBuildCmake319 { + echo "+++ Building Cmake 3.19rc3" + cd $WORKING_DIR + sudo apt-get install libssl-dev + wget https://github.com/Kitware/CMake/releases/download/v3.19.0-rc3/cmake-3.19.0-rc3.tar.gz + tar -zxf cmake-3.19.0-rc3.tar.gz + pushd cmake-3.19.0-rc3 + ./bootstrap --prefix=$WORKING_DIR/cmake/install + make all install + popd +} + +function GetAndBuildFlatbuffers { + cd $WORKING_DIR + + if [[ ! -d flatbuffers-2.0.6 ]]; then + echo "+++ Getting Flatbuffers" + wget https://github.com/google/flatbuffers/archive/v2.0.6.tar.gz + tar xf v2.0.6.tar.gz + fi + #Build FlatBuffers + echo "+++ Building x86 Flatbuffers library" + cd $WORKING_DIR/flatbuffers-2.0.6 + + rm -f CMakeCache.txt + + rm -rf build-x86 + mkdir build-x86 + cd build-x86 + + rm -rf $WORKING_DIR/flatbuffers-x86 + mkdir $WORKING_DIR/flatbuffers-x86 + + CXXFLAGS="-fPIC" $CMAKE .. \ + -DFLATBUFFERS_BUILD_FLATC=1 \ + -DCMAKE_INSTALL_PREFIX:PATH=$WORKING_DIR/flatbuffers-x86 + + make all install -j16 + + echo "+++ Building Android Flatbuffers library" + cd $WORKING_DIR/flatbuffers-2.0.6 + + rm -f CMakeCache.txt + + rm -rf build-android + mkdir build-android + cd build-android + + rm -rf $WORKING_DIR/flatbuffers-android + mkdir $WORKING_DIR/flatbuffers-android + + CC=/usr/bin/aarch64-linux-gnu-gcc CXX=/usr/bin/aarch64-linux-gnu-g++ \ + CXXFLAGS="-fPIC" $CMAKE .. \ + -DCMAKE_ANDROID_NDK=$NDK_DIR \ + -DCMAKE_SYSTEM_NAME=Android \ + -DCMAKE_SYSTEM_VERSION=$ANDROID_API \ + -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \ + -DCMAKE_CXX_FLAGS=--std=c++14 \ + -DFLATBUFFERS_BUILD_FLATC=OFF \ + -DCMAKE_BUILD_TYPE=Release \ + -DFLATBUFFERS_BUILD_TESTS=OFF \ + -DCMAKE_INSTALL_PREFIX=$WORKING_DIR/flatbuffers-android + + make all install -j16 +} + +function GetArmNN { + cd $WORKING_DIR + + if [[ ! -d armnn ]]; then + if [[ $CREATE_LINKS = 1 && -d $BASE_DIR/../../armnn ]]; then + echo "+++ Linking Arm NN" + ln -s $BASE_DIR/../../armnn $WORKING_DIR/armnn + else + echo "+++ Cloning Arm NN" + git clone https://review.mlplatform.org/ml/armnn.git armnn + cd armnn + + git checkout $ARMNN_BRANCH + git log -1 + fi + fi +} + +function GetAndBuildComputeLibrary { + cd $WORKING_DIR + + if [[ ! -d ComputeLibrary ]]; then + if [[ $CREATE_LINKS = 1 ]]; then + if [[ -d $BASE_DIR/../../ComputeLibrary ]]; then + echo "+++ Linking ComputeLibrary" + ln -s $BASE_DIR/../../ComputeLibrary $WORKING_DIR/ComputeLibrary + else + echo "+++ Cloning ComputeLibrary" + git clone https://review.mlplatform.org/ml/ComputeLibrary.git ComputeLibrary + cd ComputeLibrary + git checkout $($BASE_DIR/../../armnn/scripts/get_compute_library.sh -p) + git log -1 + fi + else + echo "+++ Cloning ComputeLibrary" + + git clone https://review.mlplatform.org/ml/ComputeLibrary.git ComputeLibrary + cd ComputeLibrary + git checkout $ACL_BRANCH + git log -1 + fi + fi + cd $WORKING_DIR/ComputeLibrary + + echo "+++ Building Compute Library" + scons toolchain_prefix=llvm- compiler_prefix=aarch64-linux-android$ANDROID_API- arch=arm64-v8a neon=$ACL_NEON opencl=$ACL_CL embed_kernels=$ACL_CL extra_cxx_flags="-fPIC" \ + benchmark_tests=0 validation_tests=0 os=android -j16 +} + +function GetAndBuildTFLite { + TENSORFLOW_REVISION="tags/v2.10.0" # Release 2.10.0 tag + TFLITE_ROOT_DIR=${WORKING_DIR}/tensorflow/tensorflow/lite + + cd $WORKING_DIR + + if [[ ! -d tensorflow ]]; then + if [[ -d $BASE_DIR/../../armnn ]]; then + TENSORFLOW_REVISION=$($BASE_DIR/../../armnn/scripts/get_tensorflow.sh -p) + fi + echo "+++ Cloning TensorFlow" + git clone https://github.com/tensorflow/tensorflow.git + AssertZeroExitCode "Cloning TensorFlow failed" + + cd tensorflow + + echo "Checking out ${TENSORFLOW_REVISION}" + git fetch && git checkout $TENSORFLOW_REVISION + + cd $WORKING_DIR + fi + + CMARGS="-DTFLITE_ENABLE_XNNPACK=OFF" + + # Two different naming conventions; one for build and the other for CC_OPT_FLAGS + ANDROID_ARM_ARCH="arm64-v8a" + + mkdir -p tflite-out/android + cd tflite-out/android + + echo "*** Configure and Cross-Compile TfLite for ${TARGET_MACHINE} with architecture ${ANDROID_ARM_ARCH}" + echo "*** Outputting files to ${TFLITE_OUTPUT_DIR}/${TARGET_MACHINE}" + + CMARGS="$CMARGS -DCMAKE_TOOLCHAIN_FILE=$NDK_DIR/build/cmake/android.toolchain.cmake \ + -DANDROID_ABI=$ANDROID_ARM_ARCH \ + -DANDROID_PLATFORM=$ANDROID_API" \ + + $CMAKE $CMARGS $TFLITE_ROOT_DIR + AssertZeroExitCode "Failed to configure Tensorflow Lite from source" + + cd $WORKING_DIR + + $CMAKE --build tflite-out/android -j 16 + AssertZeroExitCode "Failed to build Tensorflow Lite from source" + + mkdir -p $WORKING_DIR/tflite-out/tensorflow/tensorflow/lite/schema + + SCHEMA_LOCATION=$WORKING_DIR/tensorflow/tensorflow/lite/schema/schema.fbs + + cp $SCHEMA_LOCATION $WORKING_DIR/tflite-out/tensorflow/tensorflow/lite/schema + + cd $WORKING_DIR/tflite-out/tensorflow/tensorflow/lite/schema + $WORKING_DIR/flatbuffers-x86/bin/flatc -c --gen-object-api --reflect-types --reflect-names schema.fbs + AssertZeroExitCode "Failed to generate C++ schema from $SCHEMA_LOCATION" +} + +function BuildArmNN { + echo "+++ Building Arm NN" + + rm -rf $WORKING_DIR/armnn/build + + mkdir $WORKING_DIR/armnn/build + cd $WORKING_DIR/armnn/build + + CMARGS="-DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_ANDROID_NDK=$NDK_DIR \ + -DNDK_VERSION=r25 \ + -DCMAKE_SYSTEM_NAME=Android \ + -DCMAKE_SYSTEM_VERSION=$ANDROID_API \ + -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \ + -DCMAKE_SYSROOT=$WORKING_DIR/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/sysroot \ + -DARMCOMPUTE_ROOT=$WORKING_DIR/ComputeLibrary \ + -DARMCOMPUTE_BUILD_DIR=$WORKING_DIR/ComputeLibrary/build \ + -DARMCOMPUTENEON=$ACL_NEON -DARMCOMPUTECL=$ACL_CL -DARMNNREF=$REFERENCE \ + -DFLATBUFFERS_INCLUDE_PATH=$WORKING_DIR/flatbuffers-x86/include \ + -DFLATBUFFERS_ROOT=$WORKING_DIR/flatbuffers-android \ + -DFLATC_DIR=$WORKING_DIR/flatbuffers-x86 \ + -DBUILD_UNIT_TESTS=$BUILD_TESTS \ + -fexceptions" + + if [[ $TFLITE_PARSER == 1 ]]; then + CMARGS="$CMARGS \ + -DBUILD_TF_LITE_PARSER=1 \ + -DTF_LITE_GENERATED_PATH=$WORKING_DIR/tflite-out/tensorflow/tensorflow/lite/schema \ + -DTENSORFLOW_ROOT=$WORKING_DIR/tensorflow \ + -DTFLITE_LIB_ROOT=$WORKING_DIR/tflite-out/android" + fi + + if [[ $DELEGATE == 1 ]]; then + CMARGS="$CMARGS \ + -DBUILD_ARMNN_TFLITE_DELEGATE=1 \ + -DTENSORFLOW_ROOT=$WORKING_DIR/tensorflow \ + -DTFLITE_LIB_ROOT=$WORKING_DIR/tflite-out/android \ + -DTFLITE_ROOT_DIR=$WORKING_DIR/tensorflow/tensorflow/lite" + fi + + if [[ $DYNAMIC_SAMPLE == 1 ]]; then + DYNAMIC_SAMPLE_PATH="/data/local/tmp/dynamic/sample" + CMARGS="$CMARGS \ + -DDYNAMIC_BACKEND_PATHS=$DYNAMIC_SAMPLE_PATH \ + -DSAMPLE_DYNAMIC_BACKEND=1" + fi + echo "args" + echo $CMARGS + CXX=aarch64-linux-android$ANDROID_API-clang++ \ + CC=aarch64-linux-android$ANDROID_API-clang \ + CXX_FLAGS="-fPIE -fPIC" \ + $CMAKE $CMARGS .. + make -j16 +} + +function BuildStandaloneDynamicBackend { + echo "+++ Building Standalone Dynamic Sample Backend" + cd $WORKING_DIR/armnn/src/dynamic/sample + BUILD_DIR=build + rm -rf $BUILD_DIR + mkdir -p $BUILD_DIR + cd $BUILD_DIR + CXX=aarch64-linux-android$ANDROID_API-clang++ \ + CC=aarch64-linux-android$ANDROID_API-clang \ + CXX_FLAGS="-fPIE -fPIC" \ + $CMAKE \ + -DCMAKE_C_COMPILER_WORKS=TRUE \ + -DCMAKE_CXX_COMPILER_WORKS=TRUE \ + -DCMAKE_ANDROID_NDK=$NDK_DIR \ + -DCMAKE_SYSTEM_NAME=Android \ + -DCMAKE_SYSTEM_VERSION=$ANDROID_API \ + -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \ + -DCMAKE_SYSROOT=$WORKING_DIR/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/sysroot \ + -DCMAKE_CXX_FLAGS=--std=c++14 \ + -DCMAKE_EXE_LINKER_FLAGS="-pie -llog" \ + -DCMAKE_MODULE_LINKER_FLAGS="-llog" \ + -DARMNN_PATH=$WORKING_DIR/armnn/build/libarmnn.so .. + make +} + +# push sources to board +function PushBuildSourcesToBoard { + echo "+++ Removing files and symbolic links from previous runs" + adb start-server + adb shell rm -rf /data/local/tmp/* + echo "+++ Pushing sources to board" + adb root + adb remount + sleep 10s + adb version + adb push libarmnn.so /data/local/tmp/ + adb push libtimelineDecoder.so /data/local/tmp/ + adb push libtimelineDecoderJson.so /data/local/tmp/ + adb push GatordMock /data/local/tmp/ + adb push libarmnnBasePipeServer.so /data/local/tmp/ + adb push libarmnnTestUtils.so /data/local/tmp/ + adb push UnitTests /data/local/tmp/ + if [[ $DELEGATE == 1 ]]; then + adb push ${WORKING_DIR}/armnn/build/delegate/DelegateUnitTests /data/local/tmp/ + adb push ${WORKING_DIR}/armnn/build/delegate/libarmnnDelegate.so /data/local/tmp/ + fi + adb push $NDK_DIR/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so /data/local/tmp/ + echo "+++ Pushing test files to board" + adb shell mkdir -p /data/local/tmp/src/backends/backendsCommon/test/testSharedObject + adb push -p ${WORKING_DIR}/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/testDynamicBackend + adb push -p ${WORKING_DIR}/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/backendsTestPath1 + adb push -p ${WORKING_DIR}/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/backendsTestPath2 + adb push -p ${WORKING_DIR}/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.1' + adb shell 'ln -s Arm_CpuAcc_backend.so.1 /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so.1.2' + adb shell 'ln -s Arm_CpuAcc_backend.so.1.2 /data/local/tmp/src/backends/backendsCommon/test/backendsTestPath2/Arm_CpuAcc_backend.so.1.2.3' + adb push -p ${WORKING_DIR}/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/backendsTestPath5 + adb push -p ${WORKING_DIR}/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/backendsTestPath6 + adb push -p ${WORKING_DIR}/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/backendsTestPath9 + adb push -p ${WORKING_DIR}/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/reference + adb push -p ${WORKING_DIR}/armnn/build/src/backends/dynamic/reference/Arm_CpuRef_backend.so /data/local/tmp/src/backends/dynamic/reference/ + if [[ $DYNAMIC_SAMPLE == 1 ]]; then + adb shell mkdir -p /data/local/tmp/dynamic/sample/ + adb push -p ${WORKING_DIR}/armnn/src/dynamic/sample/build/libArm_SampleDynamic_backend.so /data/local/tmp/dynamic/sample/ + fi + echo "+++ Running UnitTests" + adb shell LD_LIBRARY_PATH=/data/local/tmp:/vendor/lib64:/vendor/lib64/egl /data/local/tmp/UnitTests ; printf $? + if [[ $DELEGATE == 1 ]]; then + adb shell LD_LIBRARY_PATH=/data/local/tmp:/vendor/lib64:/vendor/lib64/egl /data/local/tmp/DelegateUnitTests ; printf $? + fi +} + +# Cleanup any previous runs, setup clean directories +echo "+++ Creating $WORKING_DIR directory" +mkdir -p $WORKING_DIR +AssertZeroExitCode "Creating $WORKING_DIR directory failed" + +GetAndroidNDK +if [[ $? != 0 ]] ; then + echo "Downloading Android NDK failed" + exit 1 +fi +GetAndBuildFlatbuffers +if [[ $? != 0 ]] ; then + echo "Building Flatbuffers failed" + exit 1 +fi +if [[ $(lsb_release -rs) == "18.04" ]]; then + # We know this is necessary for 18.04 builds. + GetAndBuildCmake319 + CMAKE=$WORKING_DIR/cmake/install/bin/cmake +fi +GetArmNN +if [[ $? != 0 ]] ; then + echo "Cloning Arm NN failed" + exit 1 +fi +# Build TFLite if the Delegate or Parser is required +if [[ $DELEGATE == 1 || $TFLITE_PARSER ]]; then + GetAndBuildTFLite +fi +if [[ $? != 0 ]] ; then + echo "Building tflite failed" + exit 1 +fi +GetAndBuildComputeLibrary +if [[ $? != 0 ]] ; then + echo "Building ComputeLibrary failed" + exit 1 +fi +BuildArmNN +if [[ $? != 0 ]] ; then + echo "Building Arm NN failed" + exit 1 +fi +if [[ $DYNAMIC_SAMPLE == 1 ]]; then + BuildStandaloneDynamicBackend +fi +if [[ $PUSH_TO_BOARD == 1 ]]; then + PushBuildSourcesToBoard +fi +if [[ "$R_new" -eq 0 ]]; then + echo "Success!" +else + echo "Failed to run UnitTests" + exit 1 +fi diff --git a/src/backends/backendsCommon/test/CMakeLists.txt b/src/backends/backendsCommon/test/CMakeLists.txt index 77335d550a..26b0b433bd 100644 --- a/src/backends/backendsCommon/test/CMakeLists.txt +++ b/src/backends/backendsCommon/test/CMakeLists.txt @@ -16,7 +16,6 @@ list(APPEND armnnBackendsCommonUnitTests_sources ConcatEndToEndTestImpl.hpp Convolution2dEndToEndTestImpl.hpp Convolution3dEndToEndTestImpl.hpp - CustomMemoryOptimizerStrategyTests.cpp DefaultAsyncExecuteTest.cpp DepthToSpaceEndToEndTestImpl.hpp DepthwiseConvolution2dEndToEndTests.hpp @@ -198,6 +197,12 @@ list(APPEND armnnBackendsCommonUnitTests_sources layerTests/UnidirectionalSequenceLstmTestImpl.hpp ) +if(ARMCOMPUTENEON OR ARMNNREF) + list(APPEND armnnBackendsCommonUnitTests_sources + CustomMemoryOptimizerStrategyTests.cpp + ) +endif() + if (ARMNNREF) list(APPEND armnnBackendsCommonUnitTests_sources mockBackend/MockImportBackend.cpp |