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