diff options
-rw-r--r-- | BuildGuideAndroidNDK.md | 200 | ||||
-rw-r--r-- | README.md | 16 |
2 files changed, 214 insertions, 2 deletions
diff --git a/BuildGuideAndroidNDK.md b/BuildGuideAndroidNDK.md new file mode 100644 index 000000000..5d6f52363 --- /dev/null +++ b/BuildGuideAndroidNDK.md @@ -0,0 +1,200 @@ +# How to use the Android NDK to build ArmNN + +* [Introduction](#introduction) +* [Download the Android NDK and make a standalone toolchain](#downloadNDK) +* [Build the Boost C++ libraries](#buildBoost) +* [Build the Compute Library](#buildCL) +* [Build Google's Protobuf library](#buildProtobuf) +* [Download TensorFlow](#downloadTF) +* [Build ArmNN](#buildArmNN) +* [Run ArmNN UnitTests on an Android device](#runArmNNUnitTests) + + +#### <a name="introduction">Introduction</a> +These are step by step instructions for using the Android NDK to build ArmNN. +They have been tested on a clean install of Ubuntu 18.04, and should also work with other OS versions. +The instructions show how to build the ArmNN core library and the optional TensorFlow parser. +All downloaded or generated files will be saved inside the `~/armnn-devenv` directory. + +#### <a name="downloadNDK">Download the Android NDK and make a standalone toolchain</a> + +* Download the Android NDK from [the official website](https://developer.android.com/ndk/downloads/index.html): + + ```bash + mkdir -p ~/armnn-devenv/toolchains + cd ~/armnn-devenv/toolchains + # For Mac OS, change the NDK download link accordingly. + wget https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip + unzip android-ndk-r16b-linux-x86_64.zip + export NDK=~/armnn-devenv/toolchains/android-ndk-r16b + ``` + + You may want to append `export NDK=~/armnn-devenv/toolchains/android-ndk-r16b` to your `~/.bashrc` (or `~/.bash_profile` in Mac OS). + +* Make a standalone toolchain: + + (Requires python if not previously installed: `sudo apt install python`) + + ```bash + # Create an arm64 API 26 libc++ toolchain. + $NDK/build/tools/make_standalone_toolchain.py \ + --arch arm64 \ + --api 26 \ + --stl=libc++ \ + --install-dir=$HOME/armnn-devenv/toolchains/aarch64-android-r16b + export PATH=$HOME/armnn-devenv/toolchains/aarch64-android-r16b/bin:$PATH + ``` + + You may want to append `export PATH=$HOME/armnn-devenv/toolchains/aarch64-android-r16b/bin:$PATH` to your `~/.bashrc` (or `~/.bash_profile` in Mac OS). + +#### <a name="buildBoost">Build the Boost C++ libraries</a> + +* Download Boost version 1.64: + + ```bash + mkdir ~/armnn-devenv/boost + cd ~/armnn-devenv/boost + wget https://dl.bintray.com/boostorg/release/1.64.0/source/boost_1_64_0.tar.bz2 + tar xvf boost_1_64_0.tar.bz2 + ``` + +* Build: + + (Requires gcc if not previously installed: `sudo apt install gcc`) + ```bash + echo "using gcc : arm : aarch64-linux-android-clang++ ;" > $HOME/armnn-devenv/boost/user-config.jam + cd ~/armnn-devenv/boost/boost_1_64_0 + ./bootstrap.sh --prefix=$HOME/armnn-devenv/boost/install + ./b2 install --user-config=$HOME/armnn-devenv/boost/user-config.jam \ + toolset=gcc-arm link=static cxxflags=-fPIC --with-filesystem \ + --with-test --with-log --with-program_options -j16 + ``` + +#### <a name="buildCL">Build the Compute Library</a> +* Clone the Compute Library: + + (Requires Git if not previously installed: `sudo apt install git`) + + ``` bash + cd ~/armnn-devenv + git clone https://github.com/ARM-software/ComputeLibrary.git + ``` + +* Build: + + (Requires SCons if not previously installed: `sudo apt install scons`) + ```bash + cd ComputeLibrary + scons arch=arm64-v8a neon=1 opencl=1 embed_kernels=1 extra_cxx_flags="-fPIC" \ + benchmark_tests=0 validation_tests=0 os=android -j16 + ``` + +#### <a name="buildProtobuf">Build Google's Protobuf library</a> + +* Clone protobuf: + ```bash + mkdir ~/armnn-devenv/google + cd ~/armnn-devenv/google + git clone https://github.com/google/protobuf.git + cd protobuf + git checkout -b v3.5.2 v3.5.2 + ``` + +* 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++`) + + ```bash + ./autogen.sh + mkdir x86_build + cd x86_build + ../configure --prefix=$HOME/armnn-devenv/google/x86_pb_install + make install -j16 + cd .. + ``` + +* Build the arm64 version of the protobuf libraries: + + ```bash + mkdir arm64_build + cd arm64_build + CC=aarch64-linux-android-clang \ + CXX=aarch64-linux-android-clang++ \ + CFLAGS="-fPIE -fPIC" LDFLAGS="-pie -llog" \ + ../configure --host=aarch64-linux-android \ + --prefix=$HOME/armnn-devenv/google/arm64_pb_install \ + --with-protoc=$HOME/armnn-devenv/google/x86_pb_install/bin/protoc + make install -j16 + cd .. + ``` + +#### <a name="downloadTF">Download TensorFlow</a> +* Clone TensorFlow source code: + + ```bash + cd ~/armnn-devenv/google/ + git clone https://github.com/tensorflow/tensorflow.git + ``` + +#### <a name="buildArmNN">Build ArmNN</a> + +* Clone ArmNN source code: + + ```bash + cd ~/armnn-devenv/ + git clone https://github.com/ARM-software/armnn.git + ``` + +* Generate TensorFlow protobuf definitions: + + ```bash + cd ~/armnn-devenv/google/tensorflow + ~/armnn-devenv/armnn/scripts/generate_tensorflow_protobuf.sh \ + $HOME/armnn-devenv/google/tf_pb $HOME/armnn-devenv/google/x86_pb_install + ``` + + * Build ArmNN: + + (Requires CMake if not previously installed: `sudo apt install cmake`) + + ```bash + mkdir ~/armnn-devenv/armnn/build + cd ~/armnn-devenv/armnn/build + CXX=aarch64-linux-android-clang++ \ + CC=aarch64-linux-android-clang \ + CXX_FLAGS="-fPIE -fPIC" \ + cmake .. \ + -DCMAKE_SYSTEM_NAME=Linux \ + -DCMAKE_EXE_LINKER_FLAGS=-pie \ + -DARMCOMPUTE_ROOT=$HOME/armnn-devenv/ComputeLibrary/ \ + -DARMCOMPUTE_BUILD_DIR=$HOME/armnn-devenv/ComputeLibrary/build \ + -DBOOST_ROOT=$HOME/armnn-devenv/boost/install/ \ + -DARMCOMPUTENEON=1 -DARMCOMPUTECL=1 \ + -DTF_GENERATED_SOURCES=$HOME/armnn-devenv/google/tf_pb/ -DBUILD_TF_PARSER=1 \ + -DPROTOBUF_ROOT=$HOME/armnn-devenv/google/arm64_pb_install/ + make -j16 + ``` + +#### <a name="runArmNNUnitTests">Run the ArmNN unit tests on an Android device</a> + + +* Push the build results to an Android device and make symbolic links for shared libraries: + + ```bash + adb push libarmnnTfParser.so libarmnn.so UnitTests \ + $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.15.0.1 + adb shell 'ln -s libprotobuf.so.15.0.1 /data/local/tmp/libprotobuf.so.15' + adb shell 'ln -s libprotobuf.so.15.0.1 /data/local/tmp/libprotobuf.so' + ``` + +* Run ArmNN unit tests: + + ```bash + adb shell 'LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/UnitTests' + ``` + + If libarmnnUtils.a is present in `~/armnn-devenv/armnn/build/` and the unit tests run without failure then the build was successful. + @@ -1,5 +1,17 @@ # Arm NN -For more information about Arm NN, see: https://developer.arm.com/products/processors/machine-learning/arm-nn +For more information about Arm NN, see: <https://developer.arm.com/products/processors/machine-learning/arm-nn> -There is a getting started guide here: https://developer.arm.com/technologies/machine-learning-on-arm/developer-material/how-to-guides/configuring-the-arm-nn-sdk-build-environment +There is a getting started guide here using TensorFlow: <https://developer.arm.com/technologies/machine-learning-on-arm/developer-material/how-to-guides/configuring-the-arm-nn-sdk-build-environment-for-tensorflow> + +There is a getting started guide here using Caffe: <https://developer.arm.com/technologies/machine-learning-on-arm/developer-material/how-to-guides/configuring-the-arm-nn-sdk-build-environment-for-caffe> + +### Build Instructions + +Arm tests the build system of Arm NN with the following build environments: + +* Android NDK: [How to use Android NDK to build ArmNN](BuildGuideAndroidNDK.md) +* Cross compilation from x86_64 Ubuntu to arm64 Linux +* Native compilation under arm64 Debian 9 + +Arm NN is written using portable C++14 and the build system uses [CMake](https://cmake.org/) so it is possible to build for a wide variety of target platforms, from a wide variety of host environments. |