James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 1 | #!/bin/bash |
Teresa Charlin | ad1b3d7 | 2023-03-14 12:10:28 +0000 | [diff] [blame] | 2 | |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 3 | # |
John Mcloughlin | 04a0da6 | 2024-02-19 11:34:03 +0000 | [diff] [blame] | 4 | # Copyright © 2022-2024 Arm Ltd and Contributors. All rights reserved. |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 5 | # SPDX-License-Identifier: MIT |
| 6 | # |
| 7 | |
| 8 | # Script which builds Arm NN and ACL |
| 9 | # setup-armnn.sh must be executed in the same directory, before running this script |
| 10 | |
| 11 | set -o nounset # Catch references to undefined variables. |
| 12 | set -o pipefail # Catch non zero exit codes within pipelines. |
| 13 | set -o errexit # Catch and propagate non zero exit codes. |
| 14 | |
Tracy Narine | 83530f7 | 2024-02-23 11:23:54 +0000 | [diff] [blame] | 15 | rel_path=$(dirname "$0") # relative path from where script is executed to script location |
| 16 | abs_script_path=$(cd "$rel_path" ; pwd -P) # absolute path to script directory |
| 17 | abs_btool_path=$(dirname "$abs_script_path") # absolute path to build-tool directory |
| 18 | abs_armnn_path=$(dirname "$abs_btool_path") # absolute path to armnn directory |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 19 | |
Tracy Narine | 2883a86 | 2024-02-26 15:05:11 +0000 | [diff] [blame] | 20 | # Figure out platform specific settings |
| 21 | osname=$(uname) |
| 22 | osgetopt=getopt |
| 23 | os_darwin=0 |
| 24 | if [ "$osname" == "Darwin" ]; then |
| 25 | os_darwin=1 |
| 26 | osgetoptsys="/opt/homebrew/opt/gnu-getopt/bin/getopt" |
| 27 | osgetopthome="$HOME/homebrew/opt/gnu-getopt/bin/getopt" |
| 28 | if [ -f "$osgetoptsys" ]; then |
| 29 | echo "gnu-getopt found at: $osgetoptsys" |
| 30 | osgetopt=$osgetoptsys |
| 31 | elif [ -f "$osgetopthome" ]; then |
| 32 | echo "gnu-getopt found at: $osgetopthome" |
| 33 | osgetopt=$osgetopthome |
| 34 | else |
| 35 | echo "Run $rel_path/install-packages.sh and follow the instructions to configure the environment for $osname" |
| 36 | exit 1 |
| 37 | fi |
| 38 | fi |
| 39 | |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 40 | build_acl() |
| 41 | { |
| 42 | cd "$ACL_SRC" |
| 43 | |
James Conroy | e6f30ad | 2022-09-08 12:04:26 +0100 | [diff] [blame] | 44 | # $acl_scons_params are additional options provided by the user and will overwrite any previously defined args |
Tracy Narine | 2883a86 | 2024-02-26 15:05:11 +0000 | [diff] [blame] | 45 | acl_extra="" |
| 46 | if [ "$os_darwin" -eq 1 ]; then |
| 47 | acl_extra="os=macos " |
| 48 | fi |
| 49 | local acl_params="$acl_extra neon=$flag_neon_backend opencl=$flag_cl_backend Werror=0 embed_kernels=1 examples=0 validation_tests=0 benchmark_tests=0 benchmark_examples=0 $acl_scons_params" |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 50 | |
| 51 | if [ "$flag_debug" -eq 1 ]; then |
| 52 | acl_params="$acl_params debug=1 asserts=1" |
| 53 | fi |
| 54 | |
| 55 | local native_flag="" |
| 56 | if [ "$NATIVE_BUILD" ]; then |
| 57 | native_flag="build=native" |
| 58 | fi |
| 59 | |
| 60 | # Force -fPIC so that ACL is suitable for inclusion in Arm NN library |
| 61 | local extra_cxx_flags="extra_cxx_flags='-fPIC'" |
| 62 | |
| 63 | local compile_flags="" |
| 64 | local acl_arch="" |
| 65 | |
| 66 | case "$TARGET_ARCH" in |
| 67 | "aarch64") |
| 68 | compile_flags+="$AARCH64_COMPILER_FLAGS" |
| 69 | acl_arch="arch=arm64-v8a" |
| 70 | ;; |
| 71 | |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 72 | "android64") |
Nikhil Raj | ba6dcb2 | 2023-11-24 16:25:10 +0000 | [diff] [blame] | 73 | compile_flags+="$ANDROID64_COMPILER_FLAGS" |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 74 | acl_arch="arch=arm64-v8a" |
| 75 | ;; |
| 76 | |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 77 | "x86_64") |
| 78 | acl_arch="arch=x86_64" |
| 79 | ;; |
| 80 | esac |
| 81 | |
| 82 | echo -e "\n***** Building ACL for $TARGET_ARCH *****" |
| 83 | |
| 84 | if [ "$flag_clean" -eq 1 ]; then |
| 85 | echo -e "\n***** Clean flag detected: removing existing ACL build *****" |
| 86 | rm -rf "$ACL_BUILD_TARGET" |
| 87 | fi |
| 88 | |
| 89 | mkdir -p "$ACL_BUILD_TARGET" |
| 90 | |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 91 | if [ "$TARGET_ARCH" == "android64" ]; then |
| 92 | eval "$compile_flags" \ |
Nikhil Raj | ba6dcb2 | 2023-11-24 16:25:10 +0000 | [diff] [blame] | 93 | scons toolchain_prefix=llvm- compiler_prefix="" \ |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 94 | "$acl_arch" \ |
| 95 | "$acl_params" \ |
Nikhil Raj | ba6dcb2 | 2023-11-24 16:25:10 +0000 | [diff] [blame] | 96 | build_dir="$ACL_BUILD_TARGET" \ |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 97 | "$extra_cxx_flags" \ |
Nikhil Raj | ba6dcb2 | 2023-11-24 16:25:10 +0000 | [diff] [blame] | 98 | build=cross_compile os=android |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 99 | else |
| 100 | eval "$compile_flags" \ |
| 101 | scons "$native_flag" \ |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 102 | "$acl_arch" \ |
| 103 | "$acl_params" \ |
| 104 | build_dir="$ACL_BUILD_TARGET" \ |
| 105 | "$extra_cxx_flags" \ |
| 106 | -j "$NUM_THREADS" |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 107 | fi |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 108 | |
| 109 | echo -e "\n***** Built ACL for $TARGET_ARCH *****" |
| 110 | |
| 111 | return 0 |
| 112 | } |
| 113 | |
| 114 | build_armnn() |
| 115 | { |
Cathal Corbett | 80ef511 | 2024-03-13 10:41:02 +0000 | [diff] [blame] | 116 | if [ "$flag_clean" -eq 1 ]; then |
| 117 | echo -e "\n***** Clean flag detected: removing existing Arm NN build *****" |
| 118 | rm -rf "$ARMNN_BUILD_TARGET" |
| 119 | fi |
| 120 | |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 121 | mkdir -p "$ARMNN_BUILD_TARGET" |
| 122 | cd "$ARMNN_BUILD_TARGET" |
| 123 | |
| 124 | local build_type="Release" |
| 125 | if [ "$flag_debug" -eq 1 ]; then |
| 126 | build_type="Debug" |
| 127 | fi |
| 128 | |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 129 | local cmake_flags="" |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 130 | local compile_flags="" |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 131 | local android_cmake_args="" |
Tracy Narine | 2883a86 | 2024-02-26 15:05:11 +0000 | [diff] [blame] | 132 | local linker_cmake_args="" |
| 133 | local warn_flags="" |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 134 | |
| 135 | case "$TARGET_ARCH" in |
| 136 | "aarch64") |
| 137 | compile_flags+="$AARCH64_COMPILER_FLAGS" |
Tracy Narine | 2883a86 | 2024-02-26 15:05:11 +0000 | [diff] [blame] | 138 | if [ "$os_darwin" -eq 1 ]; then |
| 139 | linker_cmake_args="-DCMAKE_SHARED_LINKER_FLAGS='-framework CoreFoundation -framework Foundation'" |
| 140 | warn_flags="-DCMAKE_CXX_FLAGS='-Wno-error=deprecated-declarations'" |
| 141 | fi |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 142 | ;; |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 143 | "android64") |
| 144 | compile_flags+="$ANDROID64_COMPILER_FLAGS" |
| 145 | cmake_flags+="CXXFLAGS='-fPIE -fPIC'" |
| 146 | android_cmake_args+="-DCMAKE_ANDROID_NDK=$NDK_SRC \ |
| 147 | -DNDK_VERSION=r$NDK_VERSION \ |
| 148 | -DCMAKE_SYSTEM_NAME=Android \ |
| 149 | -DCMAKE_SYSTEM_VERSION=$ANDROID_API_VERSION \ |
| 150 | -DCMAKE_ANDROID_ARCH_ABI=$ANDROID_ARM_ARCH \ |
| 151 | -DCMAKE_SYSROOT=$ANDROID64_x86_TOOLCHAIN/sysroot \ |
| 152 | -DCMAKE_EXE_LINKER_FLAGS='-pie -llog'" |
| 153 | ;; |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 154 | esac |
| 155 | |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 156 | echo -e "\n***** Building Arm NN for $TARGET_ARCH *****" |
| 157 | |
Tracy Narine | 2883a86 | 2024-02-26 15:05:11 +0000 | [diff] [blame] | 158 | local flatbuffers_root="$FLATBUFFERS_BUILD_TARGET" |
| 159 | local protobuf_root="$PROTOBUF_BUILD_TARGET" |
| 160 | if [ "$os_darwin" -eq 1 ]; then |
| 161 | flatbuffers_root="$FLATBUFFERS_BUILD_HOST" |
| 162 | protobuf_root="$PROTOBUF_BUILD_HOST" |
| 163 | fi |
| 164 | |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 165 | eval "$compile_flags" \ |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 166 | cmake "$android_cmake_args" \ |
Tracy Narine | 2883a86 | 2024-02-26 15:05:11 +0000 | [diff] [blame] | 167 | "$linker_cmake_args" \ |
| 168 | "$warn_flags" \ |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 169 | -DCMAKE_BUILD_TYPE="$build_type" \ |
Nikhil Raj | 542c848 | 2023-04-26 16:22:10 +0100 | [diff] [blame] | 170 | -DBUILD_CLASSIC_DELEGATE="$flag_tflite_classic_delegate" \ |
| 171 | -DBUILD_OPAQUE_DELEGATE="$flag_tflite_opaque_delegate" \ |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 172 | -DBUILD_TF_LITE_PARSER="$flag_tflite_parser" \ |
Nikhil Raj | 0d29453 | 2023-04-20 15:19:05 +0100 | [diff] [blame] | 173 | -DBUILD_DELEGATE_JNI_INTERFACE="$flag_jni" \ |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 174 | -DBUILD_ONNX_PARSER="$flag_onnx_parser" \ |
| 175 | -DARMCOMPUTENEON="$flag_neon_backend" \ |
| 176 | -DARMCOMPUTECL="$flag_cl_backend" \ |
| 177 | -DARMNNREF="$flag_ref_backend" \ |
| 178 | -DARMCOMPUTE_ROOT="$ACL_SRC" \ |
| 179 | -DARMCOMPUTE_BUILD_DIR="$ACL_BUILD_TARGET" \ |
| 180 | -DTENSORFLOW_ROOT="$TENSORFLOW_SRC" \ |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 181 | -DTFLITE_ROOT_DIR="$TFLITE_SRC" \ |
| 182 | -DTF_LITE_GENERATED_PATH="$TFLITE_SRC"/schema \ |
| 183 | -DTF_LITE_SCHEMA_INCLUDE_PATH="$TFLITE_SRC"/schema \ |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 184 | -DTFLITE_LIB_ROOT="$TFLITE_BUILD_TARGET" \ |
Tracy Narine | 2883a86 | 2024-02-26 15:05:11 +0000 | [diff] [blame] | 185 | -DFLATBUFFERS_ROOT="$flatbuffers_root" \ |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 186 | -DFLATC_DIR="$FLATBUFFERS_BUILD_HOST" \ |
| 187 | -DONNX_GENERATED_SOURCES="$ONNX_BUILD_TARGET" \ |
Tracy Narine | 2883a86 | 2024-02-26 15:05:11 +0000 | [diff] [blame] | 188 | -DPROTOBUF_ROOT="$protobuf_root" \ |
Cathal Corbett | 80ef511 | 2024-03-13 10:41:02 +0000 | [diff] [blame] | 189 | -DBUILD_TESTS=1 \ |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 190 | "$armnn_cmake_args" \ |
| 191 | "$ARMNN_SRC" |
| 192 | |
| 193 | make -j "$NUM_THREADS" |
| 194 | |
| 195 | # Copy protobuf library into Arm NN build directory, if ONNX Parser is enabled |
Tracy Narine | 2883a86 | 2024-02-26 15:05:11 +0000 | [diff] [blame] | 196 | if [ "$flag_onnx_parser" -eq 1 ] && [ "$os_darwin" -eq 1 ]; then |
| 197 | cd "$ARMNN_BUILD_TARGET" |
| 198 | rm -f libprotobuf.dylib libprotobuf.23.dylib |
| 199 | cp "$PROTOBUF_LIBRARY_TARGET" . |
| 200 | elif [ "$flag_onnx_parser" -eq 1 ]; then |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 201 | cd "$ARMNN_BUILD_TARGET" |
| 202 | rm -f libprotobuf.so libprotobuf.so.23 libprotobuf.so.23.0.0 |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 203 | if [ "$TARGET_ARCH" != "android64" ]; then |
| 204 | cp "$PROTOBUF_LIBRARY_TARGET" . |
| 205 | ln -s libprotobuf.so.23.0.0 ./libprotobuf.so.23 |
| 206 | ln -s libprotobuf.so.23.0.0 ./libprotobuf.so |
| 207 | else |
| 208 | cp "$PROTOBUF_ANDROID_LIB_TARGET" . |
| 209 | fi |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 210 | fi |
| 211 | |
James Conroy | 3106c7f | 2022-12-07 10:30:19 +0000 | [diff] [blame] | 212 | # Copy Arm NN include directory into build output |
| 213 | cd "$ARMNN_BUILD_TARGET" |
| 214 | rm -rf include |
| 215 | cp -r "$SOURCE_DIR"/armnn/include . |
| 216 | |
Cathal Corbett | 97d911f | 2024-03-13 12:27:49 +0000 | [diff] [blame^] | 217 | # Copy all delegate header files to ./include/armnnDelegate |
Cathal Corbett | ad37530 | 2024-03-11 11:59:54 +0000 | [diff] [blame] | 218 | if [ "$flag_tflite_classic_delegate" -eq 1 ] || [ "$flag_tflite_opaque_delegate" -eq 1 ]; then |
Cathal Corbett | ad37530 | 2024-03-11 11:59:54 +0000 | [diff] [blame] | 219 | mkdir -p ./include/armnnDelegate/ |
| 220 | cp -r "$SOURCE_DIR"/armnn/delegate/include/* ./include/armnnDelegate/ |
| 221 | |
| 222 | mkdir -p ./include/armnnDelegate/armnn/delegate/common/ |
| 223 | cp -r "$SOURCE_DIR"/armnn/delegate/common/include ./include/armnnDelegate/armnn/delegate/common/ |
| 224 | fi |
| 225 | |
John Mcloughlin | 04a0da6 | 2024-02-19 11:34:03 +0000 | [diff] [blame] | 226 | if [ "$flag_tflite_classic_delegate" -eq 1 ]; then |
Cathal Corbett | ad37530 | 2024-03-11 11:59:54 +0000 | [diff] [blame] | 227 | mkdir -p ./include/armnnDelegate/armnn/delegate/classic/ |
| 228 | cp -r "$SOURCE_DIR"/armnn/delegate/classic/include ./include/armnnDelegate/armnn/delegate/classic/ |
John Mcloughlin | 04a0da6 | 2024-02-19 11:34:03 +0000 | [diff] [blame] | 229 | fi |
| 230 | if [ "$flag_tflite_opaque_delegate" -eq 1 ]; then |
Cathal Corbett | ad37530 | 2024-03-11 11:59:54 +0000 | [diff] [blame] | 231 | mkdir -p ./include/armnnDelegate/armnn/delegate/opaque/ |
| 232 | cp -r "$SOURCE_DIR"/armnn/delegate/opaque/include ./include/armnnDelegate/armnn/delegate/opaque/ |
John Mcloughlin | 04a0da6 | 2024-02-19 11:34:03 +0000 | [diff] [blame] | 233 | fi |
| 234 | |
Cathal Corbett | 80ef511 | 2024-03-13 10:41:02 +0000 | [diff] [blame] | 235 | # move ExecuteNetwork to outer directory |
| 236 | mv tests/ExecuteNetwork . |
| 237 | |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 238 | echo -e "\n***** Built Arm NN for $TARGET_ARCH *****" |
| 239 | |
| 240 | local tarball_path="$ROOT_DIR/armnn_$ARMNN_BUILD_DIR_NAME.tar.gz" |
| 241 | echo -e "\n***** Creating tarball of Arm NN build at $tarball_path *****" |
| 242 | |
| 243 | cd "$ARMNN_BUILD_ROOT" |
| 244 | rm -f "$tarball_path" |
| 245 | tar -czf "$tarball_path" "$ARMNN_BUILD_DIR_NAME" |
| 246 | |
| 247 | echo -e "\n***** Created tarball of Arm NN build at $ROOT_DIR/armnn_$ARMNN_BUILD_DIR_NAME.tar.gz *****" |
| 248 | echo -e "\n***** To extract tarball, run: tar -xzf armnn_$ARMNN_BUILD_DIR_NAME.tar.gz *****\n" |
| 249 | |
| 250 | return 0 |
| 251 | } |
| 252 | |
James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 253 | download_armnn() |
| 254 | { |
| 255 | cd "$SOURCE_DIR" |
| 256 | |
| 257 | echo -e "\n***** Downloading Arm NN *****" |
| 258 | |
| 259 | rm -rf "$ARMNN_SRC" |
| 260 | |
Nikhil Raj | 50ed2a6 | 2023-11-16 15:56:07 +0000 | [diff] [blame] | 261 | # Latest release branch of Arm NN is checked out by default |
| 262 | git clone https://github.com/ARM-software/armnn.git armnn |
James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 263 | |
| 264 | cd "$ARMNN_SRC" |
James Conroy | c4fbbec | 2022-09-22 16:40:00 +0100 | [diff] [blame] | 265 | local armnn_branch="$(git rev-parse --abbrev-ref HEAD)" |
James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 266 | |
| 267 | echo -e "\n***** Arm NN Downloaded: $armnn_branch *****" |
| 268 | } |
| 269 | |
| 270 | download_acl() |
| 271 | { |
James Conroy | c4fbbec | 2022-09-22 16:40:00 +0100 | [diff] [blame] | 272 | # First get Arm NN branch so that we can download corresponding ACL tag |
| 273 | cd "$ARMNN_SRC" |
| 274 | local armnn_branch="$(git rev-parse --abbrev-ref HEAD)" |
James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 275 | |
James Conroy | c4fbbec | 2022-09-22 16:40:00 +0100 | [diff] [blame] | 276 | echo -e "\n***** Downloading corresponding ACL version using Arm NN branch: $armnn_branch *****" |
| 277 | |
| 278 | cd "$SOURCE_DIR" |
James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 279 | |
| 280 | rm -rf "$ACL_SRC" |
| 281 | |
| 282 | git clone https://github.com/ARM-software/ComputeLibrary.git acl |
| 283 | |
| 284 | # Get corresponding release tag for ACL by parsing release branch number for Arm NN |
| 285 | local acl_tag="" |
| 286 | acl_tag="$(echo "$armnn_branch" | tr '\n' ' ' | sed -e 's/[^0-9]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' ' | sed 's/ /./g')" |
| 287 | |
| 288 | cd "$ACL_SRC" |
Tracy Narine | 2883a86 | 2024-02-26 15:05:11 +0000 | [diff] [blame] | 289 | if [ "$acl_tag" == "" ]; then |
| 290 | # Take the latest |
| 291 | git checkout main |
| 292 | else |
| 293 | git checkout v"$acl_tag" |
| 294 | fi |
James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 295 | |
| 296 | echo -e "\n***** ACL Downloaded: $acl_tag *****" |
| 297 | } |
| 298 | |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 299 | usage() |
| 300 | { |
| 301 | cat <<EOF |
| 302 | build-armnn.sh - Build Arm NN and ACL |
| 303 | build-armnn.sh [OPTION]... |
Nikhil Raj | 542c848 | 2023-04-26 16:22:10 +0100 | [diff] [blame] | 304 | --tflite-classic-delegate |
| 305 | build the existing Arm NN TF Lite Delegate component |
| 306 | --tflite-opaque-delegate |
| 307 | build the new Arm NN opaque delegate component |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 308 | --tflite-parser |
| 309 | build the Arm NN TF Lite Parser component |
| 310 | --onnx-parser |
| 311 | build the Arm NN ONNX parser component |
| 312 | --all |
| 313 | build all Arm NN components listed above |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 314 | --target-arch=[aarch64|android64|x86_64] |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 315 | specify a target architecture (mandatory) |
| 316 | --neon-backend |
| 317 | build Arm NN with the NEON backend (CPU acceleration from ACL) |
| 318 | --cl-backend |
| 319 | build Arm NN with the OpenCL backend (GPU acceleration from ACL) |
| 320 | --ref-backend |
| 321 | build Arm NN with the reference backend (Should be used for verification purposes only. Does not provide any performance acceleration.) |
| 322 | --clean |
| 323 | remove previous Arm NN and ACL build prior to script execution (optional: defaults to off) |
| 324 | --debug |
| 325 | build Arm NN (and ACL) with debug turned on (optional: defaults to off) |
| 326 | --armnn-cmake-args=<ARG LIST STRING> |
James Conroy | c8d7a66 | 2022-11-18 10:17:27 +0000 | [diff] [blame] | 327 | provide additional comma-separated CMake arguments string for building Arm NN (optional) |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 328 | --acl-scons-params=<PARAM LIST STRING> |
James Conroy | c8d7a66 | 2022-11-18 10:17:27 +0000 | [diff] [blame] | 329 | provide additional comma-separated scons parameters string for building ACL (optional) |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 330 | --num-threads=<INTEGER> |
| 331 | specify number of threads/cores to build dependencies with (optional: defaults to number of online CPU cores on host) |
Tracy Narine | 83530f7 | 2024-02-23 11:23:54 +0000 | [diff] [blame] | 332 | --symlink-armnn |
| 333 | instead of cloning, make a symbolic link from the armnn directory containing the build-tool to the source directory |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 334 | -h, --help |
| 335 | print brief usage information and exit |
| 336 | -x |
| 337 | enable shell tracing in this script |
| 338 | |
Nikhil Raj | 542c848 | 2023-04-26 16:22:10 +0100 | [diff] [blame] | 339 | At least one component (i.e. --tflite-classic-delegate, --tflite-opaque-delegate, --tflite-parser, --onnx-parser) must be provided or else provide --all to build all Arm NN components. |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 340 | At least one backend (i.e. --neon-backend, --cl-backend, --ref-backend) must be chosen. |
| 341 | This script must be executed from the same root directory in which setup-armnn.sh was executed from. |
| 342 | |
James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 343 | The first execution of this script will download the latest release branches of Arm NN and ACL, by default. |
James Conroy | c4fbbec | 2022-09-22 16:40:00 +0100 | [diff] [blame] | 344 | Alternatively, place custom/modified repositories named "armnn" and (optionally) "acl" in <ROOT_DIR>/source. |
| 345 | Providing custom "acl" repo is optional since it is only required if backend flags --neon-backend or --cl-backend are chosen. |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 346 | |
| 347 | By default, a tarball tar.gz archive of the Arm NN build will be created in the directory from which this script is called from. |
| 348 | |
| 349 | Examples: |
| 350 | Build for aarch64 with all Arm NN components, NEON enabled and OpenCL enabled: |
| 351 | <PATH_TO>/build-armnn.sh --target-arch=aarch64 --all --neon-backend --cl-backend |
| 352 | Build for aarch64 with TF Lite Delegate, OpenCL enabled and additional ACL scons params: |
Nikhil Raj | 542c848 | 2023-04-26 16:22:10 +0100 | [diff] [blame] | 353 | <PATH_TO>/build-armnn.sh --target-arch=aarch64 --tflite-classic-delegate --cl-backend --acl-scons-params='compress_kernels=1,benchmark_examples=1' |
James Conroy | e6f30ad | 2022-09-08 12:04:26 +0100 | [diff] [blame] | 354 | Setup for aarch64 with all Arm NN dependencies, OpenCL enabled and additional Arm NN cmake args: |
James Conroy | c8d7a66 | 2022-11-18 10:17:27 +0000 | [diff] [blame] | 355 | <PATH_TO>/build-armnn.sh --target-arch=aarch64 --all --cl-backend --armnn-cmake-args='-DBUILD_SAMPLE_APP=1,-DBUILD_UNIT_TESTS=0' |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 356 | EOF |
| 357 | } |
| 358 | |
| 359 | # This will catch in validation.sh if not set |
| 360 | target_arch="" |
| 361 | |
| 362 | # Default flag values |
Nikhil Raj | 542c848 | 2023-04-26 16:22:10 +0100 | [diff] [blame] | 363 | flag_tflite_classic_delegate=0 |
| 364 | flag_tflite_opaque_delegate=0 |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 365 | flag_tflite_parser=0 |
| 366 | flag_onnx_parser=0 |
| 367 | flag_neon_backend=0 |
| 368 | flag_cl_backend=0 |
| 369 | flag_ref_backend=0 |
| 370 | flag_clean=0 |
| 371 | flag_debug=0 |
Nikhil Raj | 0d29453 | 2023-04-20 15:19:05 +0100 | [diff] [blame] | 372 | flag_jni=0 |
Tracy Narine | 83530f7 | 2024-02-23 11:23:54 +0000 | [diff] [blame] | 373 | flag_symlink_armnn=0 |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 374 | |
| 375 | # Empty strings for optional additional args by default |
| 376 | armnn_cmake_args="" |
| 377 | acl_scons_params="" |
| 378 | |
| 379 | # If --num-threads is not set, the default NUM_THREADS value in common.sh will be used |
| 380 | num_threads=0 |
| 381 | |
| 382 | name=$(basename "$0") |
| 383 | |
| 384 | # If no options provided, show help |
| 385 | if [ $# -eq 0 ]; then |
| 386 | usage |
| 387 | exit 1 |
| 388 | fi |
| 389 | |
Tracy Narine | 2883a86 | 2024-02-26 15:05:11 +0000 | [diff] [blame] | 390 | args=$($osgetopt -ohx -l tflite-classic-delegate,tflite-opaque-delegate,tflite-parser,onnx-parser,all,target-arch:,neon-backend,cl-backend,ref-backend,clean,debug,armnn-cmake-args:,acl-scons-params:,num-threads:,symlink-armnn,help -n "$name" -- "$@") |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 391 | eval set -- "$args" |
| 392 | while [ $# -gt 0 ]; do |
| 393 | if [ -n "${opt_prev:-}" ]; then |
| 394 | eval "$opt_prev=\$1" |
| 395 | opt_prev= |
| 396 | shift 1 |
| 397 | continue |
| 398 | elif [ -n "${opt_append:-}" ]; then |
| 399 | if [ -n "$1" ]; then |
| 400 | eval "$opt_append=\"\${$opt_append:-} \$1\"" |
| 401 | fi |
| 402 | opt_append= |
| 403 | shift 1 |
| 404 | continue |
| 405 | fi |
| 406 | case $1 in |
| 407 | --tflite-parser) |
| 408 | flag_tflite_parser=1 |
| 409 | ;; |
| 410 | |
Nikhil Raj | 542c848 | 2023-04-26 16:22:10 +0100 | [diff] [blame] | 411 | --tflite-classic-delegate) |
Nikhil Raj | 365fa4b | 2023-05-03 09:39:56 +0100 | [diff] [blame] | 412 | flag_tflite_classic_delegate=1 |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 413 | ;; |
| 414 | |
Nikhil Raj | 542c848 | 2023-04-26 16:22:10 +0100 | [diff] [blame] | 415 | --tflite-opaque-delegate) |
| 416 | flag_tflite_opaque_delegate=1 |
| 417 | ;; |
| 418 | |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 419 | --onnx-parser) |
| 420 | flag_onnx_parser=1 |
| 421 | ;; |
| 422 | |
| 423 | --all) |
Nikhil Raj | 542c848 | 2023-04-26 16:22:10 +0100 | [diff] [blame] | 424 | flag_tflite_classic_delegate=1 |
| 425 | flag_tflite_opaque_delegate=1 |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 426 | flag_tflite_parser=1 |
| 427 | flag_onnx_parser=1 |
| 428 | ;; |
| 429 | |
| 430 | --target-arch) |
| 431 | opt_prev=target_arch |
| 432 | ;; |
| 433 | |
| 434 | --neon-backend) |
| 435 | flag_neon_backend=1 |
| 436 | ;; |
| 437 | |
| 438 | --cl-backend) |
| 439 | flag_cl_backend=1 |
| 440 | ;; |
| 441 | |
| 442 | --ref-backend) |
| 443 | flag_ref_backend=1 |
| 444 | ;; |
| 445 | |
| 446 | --clean) |
| 447 | flag_clean=1 |
| 448 | ;; |
| 449 | |
| 450 | --debug) |
| 451 | flag_debug=1 |
| 452 | ;; |
| 453 | |
| 454 | --armnn-cmake-args) |
| 455 | opt_prev=armnn_cmake_args |
| 456 | ;; |
| 457 | |
| 458 | --acl-scons-params) |
| 459 | opt_prev=acl_scons_params |
| 460 | ;; |
| 461 | |
| 462 | --num-threads) |
| 463 | opt_prev=num_threads |
| 464 | ;; |
| 465 | |
Tracy Narine | 83530f7 | 2024-02-23 11:23:54 +0000 | [diff] [blame] | 466 | --symlink-armnn) |
| 467 | flag_symlink_armnn=1 |
| 468 | ;; |
| 469 | |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 470 | -h | --help) |
| 471 | usage |
| 472 | exit 0 |
| 473 | ;; |
| 474 | |
| 475 | -x) |
| 476 | set -x |
| 477 | ;; |
| 478 | |
| 479 | --) |
| 480 | shift |
| 481 | break 2 |
| 482 | ;; |
| 483 | |
| 484 | esac |
| 485 | shift 1 |
| 486 | done |
| 487 | |
| 488 | # shellcheck source=common.sh |
| 489 | source "$rel_path"/common.sh |
| 490 | |
| 491 | # Validation of chosen Arm NN backends |
| 492 | if [ "$flag_neon_backend" -eq 0 ] && [ "$flag_cl_backend" -eq 0 ] && [ "$flag_ref_backend" -eq 0 ]; then |
| 493 | echo -e "\n$name: at least one of flags --neon-backend, --cl-backend or --ref-backend must be set." |
| 494 | exit 1 |
| 495 | fi |
| 496 | |
| 497 | if [ "$target_arch" == "x86_64" ]; then |
| 498 | if [ "$flag_neon_backend" -eq 1 ] || [ "$flag_cl_backend" -eq 1 ]; then |
| 499 | echo "$name: Accelerated backends --neon-backend and --cl-backend are supported on Arm targets only (x86_64 chosen)." |
| 500 | exit 1 |
| 501 | fi |
| 502 | fi |
| 503 | |
| 504 | # Verify that root source and build directories are present (post execution of setup-armnn.sh) |
| 505 | if [ ! -d "$SOURCE_DIR" ]; then |
| 506 | echo -e "\nERROR: Root source directory does not exist at $SOURCE_DIR" |
| 507 | echo "Please check that:" |
| 508 | echo "1. setup-armnn.sh was executed successfully prior to running this script" |
| 509 | echo "2. This script is being executed in the same directory as setup-armnn.sh" |
| 510 | |
| 511 | exit 1 |
| 512 | fi |
| 513 | |
| 514 | if [ ! -d "$BUILD_DIR" ]; then |
| 515 | echo -e "\nERROR: Root build directory does not exist at $BUILD_DIR" |
| 516 | echo "Please check that:" |
| 517 | echo "1. setup-armnn.sh was executed successfully prior to running this script" |
| 518 | echo "2. This script is being executed in the same directory as setup-armnn.sh" |
| 519 | |
| 520 | exit 1 |
| 521 | fi |
| 522 | |
James Conroy | c4fbbec | 2022-09-22 16:40:00 +0100 | [diff] [blame] | 523 | # Download Arm NN if not done already in a previous execution of this script |
James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 524 | # Check if Arm NN source directory exists AND that it is a repository (not empty) |
Tracy Narine | 83530f7 | 2024-02-23 11:23:54 +0000 | [diff] [blame] | 525 | made_symlink_armnn=0 |
James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 526 | if [ -d "$ARMNN_SRC" ] && check_if_repository "$ARMNN_SRC"; then |
| 527 | echo -e "\n***** Arm NN source repository already located at $ARMNN_SRC. Skipping cloning of Arm NN. *****" |
James Conroy | c4fbbec | 2022-09-22 16:40:00 +0100 | [diff] [blame] | 528 | else |
Tracy Narine | 83530f7 | 2024-02-23 11:23:54 +0000 | [diff] [blame] | 529 | # Use sym link or download latest release branch of Arm NN |
| 530 | if [ "$flag_symlink_armnn" -eq 1 ]; then |
| 531 | if check_if_repository "$abs_armnn_path"; then |
| 532 | ln -s "$abs_armnn_path" "$SOURCE_DIR"/armnn |
| 533 | made_symlink_armnn=1 |
| 534 | echo -e "\n***** Arm NN source repository using symbolic link to: $abs_armnn_path *****" |
| 535 | else |
| 536 | echo "Arm NN directory found is not a repository: $abs_armnn_path" |
| 537 | exit 1 |
| 538 | fi |
| 539 | else |
| 540 | download_armnn |
| 541 | fi |
James Conroy | c4fbbec | 2022-09-22 16:40:00 +0100 | [diff] [blame] | 542 | fi |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 543 | |
James Conroy | c4fbbec | 2022-09-22 16:40:00 +0100 | [diff] [blame] | 544 | # Download ACL if not done already in a previous execution of this script |
| 545 | # Only download ACL if backend options --neon-backend and --cl-backend are chosen |
| 546 | if [ "$flag_neon_backend" -eq 1 ] || [ "$flag_cl_backend" -eq 1 ]; then |
| 547 | # Check if Arm NN source directory exists AND that it is a repository (not empty) |
James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 548 | if [ -d "$ACL_SRC" ] && check_if_repository "$ACL_SRC"; then |
| 549 | echo -e "\n***** ACL source repository already located at $ACL_SRC. Skipping cloning of ACL. *****" |
| 550 | else |
James Conroy | c4fbbec | 2022-09-22 16:40:00 +0100 | [diff] [blame] | 551 | # Download latest release branch of ACL |
| 552 | download_acl |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 553 | fi |
James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 554 | else |
James Conroy | c4fbbec | 2022-09-22 16:40:00 +0100 | [diff] [blame] | 555 | echo -e "\n***** Backend options --neon-backend and --cl-backend not selected - skipping cloning of ACL *****" |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 556 | fi |
| 557 | |
| 558 | # Adjust output build directory names for Arm NN and ACL if debug is enabled |
| 559 | DEBUG_POSTFIX="" |
| 560 | if [ "$flag_debug" -eq 1 ]; then |
| 561 | DEBUG_POSTFIX="_debug" |
| 562 | fi |
| 563 | |
James Conroy | c8d7a66 | 2022-11-18 10:17:27 +0000 | [diff] [blame] | 564 | # Replace commas with spaces in additional Arm NN / ACL build args |
| 565 | # shellcheck disable=SC2001 |
| 566 | armnn_cmake_args="$(echo "$armnn_cmake_args" | sed 's/,/ /g')" |
| 567 | |
| 568 | # shellcheck disable=SC2001 |
| 569 | acl_scons_params="$(echo "$acl_scons_params" | sed 's/,/ /g')" |
| 570 | |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 571 | # Directories for Arm NN and ACL build outputs |
| 572 | ARMNN_BUILD_ROOT="$BUILD_DIR"/armnn |
| 573 | ARMNN_BUILD_DIR_NAME="$TARGET_ARCH"_build"$DEBUG_POSTFIX" |
| 574 | ARMNN_BUILD_TARGET="$ARMNN_BUILD_ROOT"/"$ARMNN_BUILD_DIR_NAME" |
| 575 | ACL_BUILD_TARGET="$BUILD_DIR"/acl/"$TARGET_ARCH"_build"$DEBUG_POSTFIX" |
| 576 | |
| 577 | echo -e "\nINFO: Displaying configuration information before execution of $name" |
Nikhil Raj | 542c848 | 2023-04-26 16:22:10 +0100 | [diff] [blame] | 578 | echo " target-arch: $TARGET_ARCH" |
| 579 | echo " host-arch: $HOST_ARCH" |
| 580 | echo "tflite-classic-delegate: $flag_tflite_classic_delegate" |
| 581 | echo "tflite-opaque-delegate : $flag_tflite_opaque_delegate" |
| 582 | echo " tflite-parser: $flag_tflite_parser" |
| 583 | echo " onnx-parser: $flag_onnx_parser" |
| 584 | echo " neon-backend: $flag_neon_backend" |
| 585 | echo " cl-backend: $flag_cl_backend" |
| 586 | echo " ref-backend: $flag_ref_backend" |
| 587 | echo " clean: $flag_clean" |
| 588 | echo " debug: $flag_debug" |
| 589 | echo " armnn-cmake-args: $armnn_cmake_args" |
| 590 | echo " acl-scons-params: $acl_scons_params" |
| 591 | echo " num-threads: $NUM_THREADS" |
| 592 | echo " root directory: $ROOT_DIR" |
| 593 | echo " source directory: $SOURCE_DIR" |
Tracy Narine | 83530f7 | 2024-02-23 11:23:54 +0000 | [diff] [blame] | 594 | if [ "$made_symlink_armnn" -eq 1 ]; then |
| 595 | echo "armnn symlink directory: $abs_armnn_path" |
| 596 | fi |
Nikhil Raj | 542c848 | 2023-04-26 16:22:10 +0100 | [diff] [blame] | 597 | echo " build directory: $BUILD_DIR" |
| 598 | echo " armnn build dir: $ARMNN_BUILD_TARGET" |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 599 | |
| 600 | if [ "$flag_neon_backend" -eq 1 ] || [ "$flag_cl_backend" -eq 1 ]; then |
| 601 | build_acl |
| 602 | else |
| 603 | echo -e "\n***** Skipping ACL build: --neon-backend and --cl-backend not set in options. *****" |
| 604 | fi |
| 605 | |
| 606 | build_armnn |
| 607 | |
Teresa Charlin | ad1b3d7 | 2023-03-14 12:10:28 +0000 | [diff] [blame] | 608 | exit 0 |