blob: b399a5aa6640caad3fa57a218f232d6df6125083 [file] [log] [blame]
James Conroy919ec712022-07-13 12:57:53 +01001#!/bin/bash
Teresa Charlinad1b3d72023-03-14 12:10:28 +00002
James Conroy919ec712022-07-13 12:57:53 +01003#
John Mcloughlin04a0da62024-02-19 11:34:03 +00004# Copyright © 2022-2024 Arm Ltd and Contributors. All rights reserved.
James Conroy919ec712022-07-13 12:57:53 +01005# 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
11set -o nounset # Catch references to undefined variables.
12set -o pipefail # Catch non zero exit codes within pipelines.
13set -o errexit # Catch and propagate non zero exit codes.
14
Tracy Narine83530f72024-02-23 11:23:54 +000015rel_path=$(dirname "$0") # relative path from where script is executed to script location
16abs_script_path=$(cd "$rel_path" ; pwd -P) # absolute path to script directory
17abs_btool_path=$(dirname "$abs_script_path") # absolute path to build-tool directory
18abs_armnn_path=$(dirname "$abs_btool_path") # absolute path to armnn directory
James Conroy919ec712022-07-13 12:57:53 +010019
Tracy Narine2883a862024-02-26 15:05:11 +000020# Figure out platform specific settings
21osname=$(uname)
22osgetopt=getopt
23os_darwin=0
24if [ "$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
38fi
39
James Conroy919ec712022-07-13 12:57:53 +010040build_acl()
41{
42 cd "$ACL_SRC"
43
James Conroye6f30ad2022-09-08 12:04:26 +010044 # $acl_scons_params are additional options provided by the user and will overwrite any previously defined args
Tracy Narine2883a862024-02-26 15:05:11 +000045 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 Conroy919ec712022-07-13 12:57:53 +010050
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 Mcloughlin35bae832023-07-24 11:55:13 +010072 "android64")
Nikhil Rajba6dcb22023-11-24 16:25:10 +000073 compile_flags+="$ANDROID64_COMPILER_FLAGS"
John Mcloughlin35bae832023-07-24 11:55:13 +010074 acl_arch="arch=arm64-v8a"
75 ;;
76
James Conroy919ec712022-07-13 12:57:53 +010077 "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 Mcloughlin35bae832023-07-24 11:55:13 +010091 if [ "$TARGET_ARCH" == "android64" ]; then
92 eval "$compile_flags" \
Nikhil Rajba6dcb22023-11-24 16:25:10 +000093 scons toolchain_prefix=llvm- compiler_prefix="" \
John Mcloughlin35bae832023-07-24 11:55:13 +010094 "$acl_arch" \
95 "$acl_params" \
Nikhil Rajba6dcb22023-11-24 16:25:10 +000096 build_dir="$ACL_BUILD_TARGET" \
John Mcloughlin35bae832023-07-24 11:55:13 +010097 "$extra_cxx_flags" \
Nikhil Rajba6dcb22023-11-24 16:25:10 +000098 build=cross_compile os=android
John Mcloughlin35bae832023-07-24 11:55:13 +010099 else
100 eval "$compile_flags" \
101 scons "$native_flag" \
James Conroy919ec712022-07-13 12:57:53 +0100102 "$acl_arch" \
103 "$acl_params" \
104 build_dir="$ACL_BUILD_TARGET" \
105 "$extra_cxx_flags" \
106 -j "$NUM_THREADS"
John Mcloughlin35bae832023-07-24 11:55:13 +0100107 fi
James Conroy919ec712022-07-13 12:57:53 +0100108
109 echo -e "\n***** Built ACL for $TARGET_ARCH *****"
110
111 return 0
112}
113
114build_armnn()
115{
Cathal Corbett80ef5112024-03-13 10:41:02 +0000116 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 Conroy919ec712022-07-13 12:57:53 +0100121 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 Mcloughlin35bae832023-07-24 11:55:13 +0100129 local cmake_flags=""
James Conroy919ec712022-07-13 12:57:53 +0100130 local compile_flags=""
John Mcloughlin35bae832023-07-24 11:55:13 +0100131 local android_cmake_args=""
Tracy Narine2883a862024-02-26 15:05:11 +0000132 local linker_cmake_args=""
133 local warn_flags=""
James Conroy919ec712022-07-13 12:57:53 +0100134
135 case "$TARGET_ARCH" in
136 "aarch64")
137 compile_flags+="$AARCH64_COMPILER_FLAGS"
Tracy Narine2883a862024-02-26 15:05:11 +0000138 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 Conroy919ec712022-07-13 12:57:53 +0100142 ;;
John Mcloughlin35bae832023-07-24 11:55:13 +0100143 "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 Conroy919ec712022-07-13 12:57:53 +0100154 esac
155
James Conroy919ec712022-07-13 12:57:53 +0100156 echo -e "\n***** Building Arm NN for $TARGET_ARCH *****"
157
Tracy Narine2883a862024-02-26 15:05:11 +0000158 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 Conroy919ec712022-07-13 12:57:53 +0100165 eval "$compile_flags" \
John Mcloughlin35bae832023-07-24 11:55:13 +0100166 cmake "$android_cmake_args" \
Tracy Narine2883a862024-02-26 15:05:11 +0000167 "$linker_cmake_args" \
168 "$warn_flags" \
John Mcloughlin35bae832023-07-24 11:55:13 +0100169 -DCMAKE_BUILD_TYPE="$build_type" \
Nikhil Raj542c8482023-04-26 16:22:10 +0100170 -DBUILD_CLASSIC_DELEGATE="$flag_tflite_classic_delegate" \
171 -DBUILD_OPAQUE_DELEGATE="$flag_tflite_opaque_delegate" \
James Conroy919ec712022-07-13 12:57:53 +0100172 -DBUILD_TF_LITE_PARSER="$flag_tflite_parser" \
Nikhil Raj0d294532023-04-20 15:19:05 +0100173 -DBUILD_DELEGATE_JNI_INTERFACE="$flag_jni" \
James Conroy919ec712022-07-13 12:57:53 +0100174 -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 Mcloughlin35bae832023-07-24 11:55:13 +0100181 -DTFLITE_ROOT_DIR="$TFLITE_SRC" \
182 -DTF_LITE_GENERATED_PATH="$TFLITE_SRC"/schema \
183 -DTF_LITE_SCHEMA_INCLUDE_PATH="$TFLITE_SRC"/schema \
James Conroy919ec712022-07-13 12:57:53 +0100184 -DTFLITE_LIB_ROOT="$TFLITE_BUILD_TARGET" \
Tracy Narine2883a862024-02-26 15:05:11 +0000185 -DFLATBUFFERS_ROOT="$flatbuffers_root" \
James Conroy919ec712022-07-13 12:57:53 +0100186 -DFLATC_DIR="$FLATBUFFERS_BUILD_HOST" \
187 -DONNX_GENERATED_SOURCES="$ONNX_BUILD_TARGET" \
Tracy Narine2883a862024-02-26 15:05:11 +0000188 -DPROTOBUF_ROOT="$protobuf_root" \
Cathal Corbett80ef5112024-03-13 10:41:02 +0000189 -DBUILD_TESTS=1 \
James Conroy919ec712022-07-13 12:57:53 +0100190 "$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 Narine2883a862024-02-26 15:05:11 +0000196 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 Conroy919ec712022-07-13 12:57:53 +0100201 cd "$ARMNN_BUILD_TARGET"
202 rm -f libprotobuf.so libprotobuf.so.23 libprotobuf.so.23.0.0
John Mcloughlin35bae832023-07-24 11:55:13 +0100203 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 Conroy919ec712022-07-13 12:57:53 +0100210 fi
211
James Conroy3106c7f2022-12-07 10:30:19 +0000212 # 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 Corbett97d911f2024-03-13 12:27:49 +0000217 # Copy all delegate header files to ./include/armnnDelegate
Cathal Corbettad375302024-03-11 11:59:54 +0000218 if [ "$flag_tflite_classic_delegate" -eq 1 ] || [ "$flag_tflite_opaque_delegate" -eq 1 ]; then
Cathal Corbettad375302024-03-11 11:59:54 +0000219 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 Mcloughlin04a0da62024-02-19 11:34:03 +0000226 if [ "$flag_tflite_classic_delegate" -eq 1 ]; then
Cathal Corbettad375302024-03-11 11:59:54 +0000227 mkdir -p ./include/armnnDelegate/armnn/delegate/classic/
228 cp -r "$SOURCE_DIR"/armnn/delegate/classic/include ./include/armnnDelegate/armnn/delegate/classic/
John Mcloughlin04a0da62024-02-19 11:34:03 +0000229 fi
230 if [ "$flag_tflite_opaque_delegate" -eq 1 ]; then
Cathal Corbettad375302024-03-11 11:59:54 +0000231 mkdir -p ./include/armnnDelegate/armnn/delegate/opaque/
232 cp -r "$SOURCE_DIR"/armnn/delegate/opaque/include ./include/armnnDelegate/armnn/delegate/opaque/
John Mcloughlin04a0da62024-02-19 11:34:03 +0000233 fi
234
Cathal Corbett80ef5112024-03-13 10:41:02 +0000235 # move ExecuteNetwork to outer directory
236 mv tests/ExecuteNetwork .
237
James Conroy919ec712022-07-13 12:57:53 +0100238 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 Conroy210897d2022-08-04 16:55:05 +0100253download_armnn()
254{
255 cd "$SOURCE_DIR"
256
257 echo -e "\n***** Downloading Arm NN *****"
258
259 rm -rf "$ARMNN_SRC"
260
Nikhil Raj50ed2a62023-11-16 15:56:07 +0000261 # Latest release branch of Arm NN is checked out by default
262 git clone https://github.com/ARM-software/armnn.git armnn
James Conroy210897d2022-08-04 16:55:05 +0100263
264 cd "$ARMNN_SRC"
James Conroyc4fbbec2022-09-22 16:40:00 +0100265 local armnn_branch="$(git rev-parse --abbrev-ref HEAD)"
James Conroy210897d2022-08-04 16:55:05 +0100266
267 echo -e "\n***** Arm NN Downloaded: $armnn_branch *****"
268}
269
270download_acl()
271{
James Conroyc4fbbec2022-09-22 16:40:00 +0100272 # 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 Conroy210897d2022-08-04 16:55:05 +0100275
James Conroyc4fbbec2022-09-22 16:40:00 +0100276 echo -e "\n***** Downloading corresponding ACL version using Arm NN branch: $armnn_branch *****"
277
278 cd "$SOURCE_DIR"
James Conroy210897d2022-08-04 16:55:05 +0100279
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 Narine2883a862024-02-26 15:05:11 +0000289 if [ "$acl_tag" == "" ]; then
290 # Take the latest
291 git checkout main
292 else
293 git checkout v"$acl_tag"
294 fi
James Conroy210897d2022-08-04 16:55:05 +0100295
296 echo -e "\n***** ACL Downloaded: $acl_tag *****"
297}
298
James Conroy919ec712022-07-13 12:57:53 +0100299usage()
300{
301 cat <<EOF
302build-armnn.sh - Build Arm NN and ACL
303build-armnn.sh [OPTION]...
Nikhil Raj542c8482023-04-26 16:22:10 +0100304 --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 Conroy919ec712022-07-13 12:57:53 +0100308 --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 Mcloughlin35bae832023-07-24 11:55:13 +0100314 --target-arch=[aarch64|android64|x86_64]
James Conroy919ec712022-07-13 12:57:53 +0100315 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 Conroyc8d7a662022-11-18 10:17:27 +0000327 provide additional comma-separated CMake arguments string for building Arm NN (optional)
James Conroy919ec712022-07-13 12:57:53 +0100328 --acl-scons-params=<PARAM LIST STRING>
James Conroyc8d7a662022-11-18 10:17:27 +0000329 provide additional comma-separated scons parameters string for building ACL (optional)
James Conroy919ec712022-07-13 12:57:53 +0100330 --num-threads=<INTEGER>
331 specify number of threads/cores to build dependencies with (optional: defaults to number of online CPU cores on host)
Tracy Narine83530f72024-02-23 11:23:54 +0000332 --symlink-armnn
333 instead of cloning, make a symbolic link from the armnn directory containing the build-tool to the source directory
James Conroy919ec712022-07-13 12:57:53 +0100334 -h, --help
335 print brief usage information and exit
336 -x
337 enable shell tracing in this script
338
Nikhil Raj542c8482023-04-26 16:22:10 +0100339At 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 Conroy919ec712022-07-13 12:57:53 +0100340At least one backend (i.e. --neon-backend, --cl-backend, --ref-backend) must be chosen.
341This script must be executed from the same root directory in which setup-armnn.sh was executed from.
342
James Conroy210897d2022-08-04 16:55:05 +0100343The first execution of this script will download the latest release branches of Arm NN and ACL, by default.
James Conroyc4fbbec2022-09-22 16:40:00 +0100344Alternatively, place custom/modified repositories named "armnn" and (optionally) "acl" in <ROOT_DIR>/source.
345Providing custom "acl" repo is optional since it is only required if backend flags --neon-backend or --cl-backend are chosen.
James Conroy919ec712022-07-13 12:57:53 +0100346
347By 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
349Examples:
350Build 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
352Build for aarch64 with TF Lite Delegate, OpenCL enabled and additional ACL scons params:
Nikhil Raj542c8482023-04-26 16:22:10 +0100353 <PATH_TO>/build-armnn.sh --target-arch=aarch64 --tflite-classic-delegate --cl-backend --acl-scons-params='compress_kernels=1,benchmark_examples=1'
James Conroye6f30ad2022-09-08 12:04:26 +0100354Setup for aarch64 with all Arm NN dependencies, OpenCL enabled and additional Arm NN cmake args:
James Conroyc8d7a662022-11-18 10:17:27 +0000355 <PATH_TO>/build-armnn.sh --target-arch=aarch64 --all --cl-backend --armnn-cmake-args='-DBUILD_SAMPLE_APP=1,-DBUILD_UNIT_TESTS=0'
James Conroy919ec712022-07-13 12:57:53 +0100356EOF
357}
358
359# This will catch in validation.sh if not set
360target_arch=""
361
362# Default flag values
Nikhil Raj542c8482023-04-26 16:22:10 +0100363flag_tflite_classic_delegate=0
364flag_tflite_opaque_delegate=0
James Conroy919ec712022-07-13 12:57:53 +0100365flag_tflite_parser=0
366flag_onnx_parser=0
367flag_neon_backend=0
368flag_cl_backend=0
369flag_ref_backend=0
370flag_clean=0
371flag_debug=0
Nikhil Raj0d294532023-04-20 15:19:05 +0100372flag_jni=0
Tracy Narine83530f72024-02-23 11:23:54 +0000373flag_symlink_armnn=0
James Conroy919ec712022-07-13 12:57:53 +0100374
375# Empty strings for optional additional args by default
376armnn_cmake_args=""
377acl_scons_params=""
378
379# If --num-threads is not set, the default NUM_THREADS value in common.sh will be used
380num_threads=0
381
382name=$(basename "$0")
383
384# If no options provided, show help
385if [ $# -eq 0 ]; then
386 usage
387 exit 1
388fi
389
Tracy Narine2883a862024-02-26 15:05:11 +0000390args=$($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 Conroy919ec712022-07-13 12:57:53 +0100391eval set -- "$args"
392while [ $# -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 Raj542c8482023-04-26 16:22:10 +0100411 --tflite-classic-delegate)
Nikhil Raj365fa4b2023-05-03 09:39:56 +0100412 flag_tflite_classic_delegate=1
James Conroy919ec712022-07-13 12:57:53 +0100413 ;;
414
Nikhil Raj542c8482023-04-26 16:22:10 +0100415 --tflite-opaque-delegate)
416 flag_tflite_opaque_delegate=1
417 ;;
418
James Conroy919ec712022-07-13 12:57:53 +0100419 --onnx-parser)
420 flag_onnx_parser=1
421 ;;
422
423 --all)
Nikhil Raj542c8482023-04-26 16:22:10 +0100424 flag_tflite_classic_delegate=1
425 flag_tflite_opaque_delegate=1
James Conroy919ec712022-07-13 12:57:53 +0100426 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 Narine83530f72024-02-23 11:23:54 +0000466 --symlink-armnn)
467 flag_symlink_armnn=1
468 ;;
469
James Conroy919ec712022-07-13 12:57:53 +0100470 -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
486done
487
488# shellcheck source=common.sh
489source "$rel_path"/common.sh
490
491# Validation of chosen Arm NN backends
492if [ "$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
495fi
496
497if [ "$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
502fi
503
504# Verify that root source and build directories are present (post execution of setup-armnn.sh)
505if [ ! -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
512fi
513
514if [ ! -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
521fi
522
James Conroyc4fbbec2022-09-22 16:40:00 +0100523# Download Arm NN if not done already in a previous execution of this script
James Conroy210897d2022-08-04 16:55:05 +0100524# Check if Arm NN source directory exists AND that it is a repository (not empty)
Tracy Narine83530f72024-02-23 11:23:54 +0000525made_symlink_armnn=0
James Conroy210897d2022-08-04 16:55:05 +0100526if [ -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 Conroyc4fbbec2022-09-22 16:40:00 +0100528else
Tracy Narine83530f72024-02-23 11:23:54 +0000529 # 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 Conroyc4fbbec2022-09-22 16:40:00 +0100542fi
James Conroy919ec712022-07-13 12:57:53 +0100543
James Conroyc4fbbec2022-09-22 16:40:00 +0100544# 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
546if [ "$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 Conroy210897d2022-08-04 16:55:05 +0100548 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 Conroyc4fbbec2022-09-22 16:40:00 +0100551 # Download latest release branch of ACL
552 download_acl
James Conroy919ec712022-07-13 12:57:53 +0100553 fi
James Conroy210897d2022-08-04 16:55:05 +0100554else
James Conroyc4fbbec2022-09-22 16:40:00 +0100555 echo -e "\n***** Backend options --neon-backend and --cl-backend not selected - skipping cloning of ACL *****"
James Conroy919ec712022-07-13 12:57:53 +0100556fi
557
558# Adjust output build directory names for Arm NN and ACL if debug is enabled
559DEBUG_POSTFIX=""
560if [ "$flag_debug" -eq 1 ]; then
561 DEBUG_POSTFIX="_debug"
562fi
563
James Conroyc8d7a662022-11-18 10:17:27 +0000564# Replace commas with spaces in additional Arm NN / ACL build args
565# shellcheck disable=SC2001
566armnn_cmake_args="$(echo "$armnn_cmake_args" | sed 's/,/ /g')"
567
568# shellcheck disable=SC2001
569acl_scons_params="$(echo "$acl_scons_params" | sed 's/,/ /g')"
570
James Conroy919ec712022-07-13 12:57:53 +0100571# Directories for Arm NN and ACL build outputs
572ARMNN_BUILD_ROOT="$BUILD_DIR"/armnn
573ARMNN_BUILD_DIR_NAME="$TARGET_ARCH"_build"$DEBUG_POSTFIX"
574ARMNN_BUILD_TARGET="$ARMNN_BUILD_ROOT"/"$ARMNN_BUILD_DIR_NAME"
575ACL_BUILD_TARGET="$BUILD_DIR"/acl/"$TARGET_ARCH"_build"$DEBUG_POSTFIX"
576
577echo -e "\nINFO: Displaying configuration information before execution of $name"
Nikhil Raj542c8482023-04-26 16:22:10 +0100578echo " target-arch: $TARGET_ARCH"
579echo " host-arch: $HOST_ARCH"
580echo "tflite-classic-delegate: $flag_tflite_classic_delegate"
581echo "tflite-opaque-delegate : $flag_tflite_opaque_delegate"
582echo " tflite-parser: $flag_tflite_parser"
583echo " onnx-parser: $flag_onnx_parser"
584echo " neon-backend: $flag_neon_backend"
585echo " cl-backend: $flag_cl_backend"
586echo " ref-backend: $flag_ref_backend"
587echo " clean: $flag_clean"
588echo " debug: $flag_debug"
589echo " armnn-cmake-args: $armnn_cmake_args"
590echo " acl-scons-params: $acl_scons_params"
591echo " num-threads: $NUM_THREADS"
592echo " root directory: $ROOT_DIR"
593echo " source directory: $SOURCE_DIR"
Tracy Narine83530f72024-02-23 11:23:54 +0000594if [ "$made_symlink_armnn" -eq 1 ]; then
595 echo "armnn symlink directory: $abs_armnn_path"
596fi
Nikhil Raj542c8482023-04-26 16:22:10 +0100597echo " build directory: $BUILD_DIR"
598echo " armnn build dir: $ARMNN_BUILD_TARGET"
James Conroy919ec712022-07-13 12:57:53 +0100599
600if [ "$flag_neon_backend" -eq 1 ] || [ "$flag_cl_backend" -eq 1 ]; then
601 build_acl
602else
603 echo -e "\n***** Skipping ACL build: --neon-backend and --cl-backend not set in options. *****"
604fi
605
606build_armnn
607
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000608exit 0