aboutsummaryrefslogtreecommitdiff
path: root/shim/BuildGuideShimSupportLibrary.md
diff options
context:
space:
mode:
Diffstat (limited to 'shim/BuildGuideShimSupportLibrary.md')
-rw-r--r--shim/BuildGuideShimSupportLibrary.md70
1 files changed, 41 insertions, 29 deletions
diff --git a/shim/BuildGuideShimSupportLibrary.md b/shim/BuildGuideShimSupportLibrary.md
index 550a05f70f..dc69f8f77c 100644
--- a/shim/BuildGuideShimSupportLibrary.md
+++ b/shim/BuildGuideShimSupportLibrary.md
@@ -15,11 +15,13 @@ This work is currently in an experimental phase.
## Prerequisites
-The following are required to build the support library
+The following are required to build the Arm NN support library
* Android NDK r20b
* Detailed setup can be found in [BuildGuideAndroidNDK.md](../BuildGuideAndroidNDK.md)
* Flatbuffer version 1.12.0
* Detailed setup can be found in [BuildGuideCrossCompilation.md](../BuildGuideCrossCompilation.md)
+
+The following is required to build the Arm NN shim
* AOSP Source (Android Open Source Project)
* Download the source from the [official website](https://source.android.com/setup/build/downloading)
* This guide will use release tag `android12-s1-release`
@@ -27,21 +29,29 @@ The following are required to build the support library
Set environment variables
```bash
-export AOSP_ROOT=<path/to/aosp/root>
-export NDK=<path/to/>/android-ndk-r20b
+export WORKING_DIR=<path to where the Arm NN source code, clframework and aosp repos will be cloned>
+export AOSP_ROOT=<path to the root of Android tree where the shim will be built>
+export AOSP_MODULES_ROOT=<path to where AOSP modules will be cloned i.e. $WORKING_DIR/aosp>
+export ARMNN_BUILD_DIR=<path to the Arm NN build directory i.e. $WORKING_DIR/build>
+export NDK=<path to>android-ndk-r20b
export NDK_TOOLCHAIN_ROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64
export PATH=$NDK_TOOLCHAIN_ROOT/bin/:$PATH
-export FLATBUFFERS_ANDROID_BUILD=<path/to/flatbuffers/target/android/build>
-export FLATBUFFERS_X86_BUILD=<path/to/flatbuffers/host/build-x86_64>
+export FLATBUFFERS_ANDROID_BUILD=<path to flatbuffers target android build>
+export FLATBUFFERS_X86_BUILD=<path to flatbuffers host build-x86_64>
```
## Download Arm NN
-* Clone Arm NN into the AOSP tree:
+If the user only wishes to build the Support Library with the NDK, the Arm NN repo can be cloned into any folder.
+If the user also wishes to build the Arm NN Shim, for this the Arm NN repo will need to reside within
+the Android tree in order for armnn/shim/Android.bp to be picked up by the Soong (Android) build system.
+For example $AOSP_ROOT/vendor/arm/armnn
+
+
+* Clone Arm NN:
(Requires Git if not previously installed: `sudo apt install git`)
```bash
-mkdir -p $AOSP_ROOT/vendor/arm/
-cd $AOSP_ROOT/vendor/arm/
+cd $WORKING_DIR
git clone https://github.com/ARM-software/armnn.git
```
@@ -49,12 +59,12 @@ git clone https://github.com/ARM-software/armnn.git
Arm NN provides a script that downloads the version of Arm Compute Library that Arm NN was tested with:
```bash
-./armnn/scripts/get_compute_library.sh
+${WORKING_DIR}/armnn/scripts/get_compute_library.sh
```
-* Build the Arm Compute Library:
+* Build the Arm Compute Library:
(Requires SCons if not previously installed: `sudo apt install scons`)
```bash
-cd $AOSP_ROOT/vendor/arm/clframework
+cd ${WORKING_DIR}/clframework
scons arch=arm64-v8a \
toolchain_prefix=aarch64-linux-android- \
@@ -69,21 +79,20 @@ validation_tests=0 benchmark_tests=0 benchmark_examples=0 os=android -j16
## Build Arm NN and Serializer
-* Build Arm NN:
+* Build Arm NN:
(Requires CMake if not previously installed: `sudo apt install cmake`)
```bash
-mkdir -p $AOSP_ROOT/vendor/arm/armnn/build
-cd $AOSP_ROOT/vendor/arm/armnn/build
+cd $ARMNN_BUILD_DIR
CXX=aarch64-linux-android29-clang++ \
CC=aarch64-linux-android29-clang \
-CXX_FLAGS="-fPIE -fPIC" cmake .. \
+CXX_FLAGS="-fPIE -fPIC" cmake ${WORKING_DIR}/armnn \
-DCMAKE_ANDROID_NDK=$NDK \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION=29 \
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
-DCMAKE_EXE_LINKER_FLAGS="-pie -llog -lz" \
--DARMCOMPUTE_ROOT=$AOSP_ROOT/vendor/arm/clframework/ \
--DARMCOMPUTE_BUILD_DIR=$AOSP_ROOT/vendor/arm/clframework/build/android-arm64v8a/ \
+-DARMCOMPUTE_ROOT=$WORKING_DIR/clframework/ \
+-DARMCOMPUTE_BUILD_DIR=$WORKING_DIR/clframework/build/android-arm64v8a/ \
-DARMCOMPUTENEON=1 -DARMCOMPUTECL=1 -DARMNNREF=1 \
-DFLATBUFFERS_ROOT=$FLATBUFFERS_ANDROID_BUILD \
-DFLATC_DIR=$FLATBUFFERS_X86_BUILD \
@@ -98,15 +107,17 @@ make -j16
## Build Arm NN Support Library
Building the support library requires building some AOSP libraries via the NDK.
-It should be possible to create a symlink from $AOSP_ROOT to $AOSP_ROOT/vendor/arm/armnn/sl/aosp.
-However this example will instead clone the necessary AOSP repos and apply some minor patches which were required to get it to build.
+It should be possible to use $AOSP_ROOT instead of $AOSP_MODULES_ROOT.
+
+However this example will instead clone the necessary AOSP repos outside of the Android tree and apply some minor patches
+which were required to get it to build with the Android version used in this guide.
+
```bash
-cd $AOSP_ROOT/vendor/arm/armnn/shim/sl/
-# Call a script which will clone the necessary AOSP repos
-./scripts/clone_aosp_libs.sh
+# Call a script which will clone the necessary AOSP repos (do not clone them into Android tree)
+${WORKING_DIR}/armnn/shim/sl/scripts/clone_aosp_libs.sh $AOSP_MODULES_ROOT
-# Modify the repos by applying patches and 'switching off' Android.bp/.mk files by renaming them
-./scripts/modify_aosp_libs.sh
+# Modify the repos by applying patches
+${WORKING_DIR}/armnn/shim/sl/scripts/modify_aosp_libs.sh $AOSP_MODULES_ROOT
# Build the Support Library
CMARGS="$CMARGS \
@@ -115,10 +126,12 @@ CMARGS="$CMARGS \
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
-DCMAKE_ANDROID_NDK=$NDK \
-DANDROID_PLATFORM=android-29 \
--DARMNN_SOURCE_DIR=$AOSP_ROOT/vendor/arm/armnn/ "
+-DAOSP_MODULES_ROOT=$AOSP_MODULES_ROOT \
+-DARMNN_SOURCE_DIR=$WORKING_DIR/armnn \
+-DArmnn_DIR=$ARMNN_BUILD_DIR "
-mkdir build
-cd build
+mkdir ${WORKING_DIR}/armnn/shim/sl/build
+cd ${WORKING_DIR}/armnn/shim/sl/build
CXX=aarch64-linux-android29-clang++ \
CC=aarch64-linux-android29-clang \
@@ -146,5 +159,4 @@ $AOSP_ROOT/out/target/product/<device>/vendor/bin/hw/android.hardware.neuralnetw
$AOSP_ROOT/out/target/product/<device>/vendor/etc/vintf/manifest/android.hardware.neuralnetworks-shim-service-armnn.xml
Currently the Arm NN libraries are shared libraries and therefore will need to be pushed to the device:
-$AOSP_ROOT/vendor/arm/armnn/build/libarmnnSerializer.so
-$AOSP_ROOT/vendor/arm/armnn/build/libarmnn.so
+$ARMNN_BUILD_DIR/libarmnn.so