James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Tracy Narine | 2883a86 | 2024-02-26 15:05:11 +0000 | [diff] [blame] | 3 | # Copyright © 2022-2024 Arm Ltd and Contributors. All rights reserved. |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | # Script which stores common variables and paths used by setup-armnn.sh and build-armnn.sh |
| 8 | |
| 9 | # shellcheck disable=SC2034 |
| 10 | # SC2034: false positives for variables appear unused - variables are used in setup-armnn.sh and build-armnn.sh |
| 11 | |
| 12 | set -o nounset # Catch references to undefined variables. |
| 13 | set -o pipefail # Catch non zero exit codes within pipelines. |
| 14 | set -o errexit # Catch and propagate non zero exit codes. |
| 15 | |
| 16 | # ROOT_DIR is the directory in which a script is called from |
| 17 | ROOT_DIR=$(pwd) |
| 18 | SOURCE_DIR="$ROOT_DIR"/source |
| 19 | BUILD_DIR="$ROOT_DIR"/build |
| 20 | |
| 21 | # Host architecture e.g. x86_64, aarch64 |
| 22 | HOST_ARCH=$(uname -m) |
| 23 | |
| 24 | # Number of online cores on host |
| 25 | NUM_THREADS=$(getconf _NPROCESSORS_ONLN) |
| 26 | |
| 27 | # Validate common user-defined options |
| 28 | # shellcheck source=validation.sh |
| 29 | source "$rel_path"/validation.sh |
| 30 | |
| 31 | # target_arch supplied as command line arg |
| 32 | TARGET_ARCH="$target_arch" |
| 33 | |
| 34 | NATIVE_BUILD=0 |
| 35 | if [ "$TARGET_ARCH" == "$HOST_ARCH" ]; then |
| 36 | NATIVE_BUILD=1 |
Tracy Narine | 2883a86 | 2024-02-26 15:05:11 +0000 | [diff] [blame] | 37 | elif [ "$TARGET_ARCH" == "aarch64" ]; then |
| 38 | if [ "$HOST_ARCH" == "arm64" ]; then |
| 39 | NATIVE_BUILD=1 |
| 40 | fi |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 41 | fi |
| 42 | |
| 43 | AARCH64_COMPILER_FLAGS+="CC=/usr/bin/aarch64-linux-gnu-gcc CXX=/usr/bin/aarch64-linux-gnu-g++ " |
Tracy Narine | 2883a86 | 2024-02-26 15:05:11 +0000 | [diff] [blame] | 44 | if [ "$HOST_ARCH" == "arm64" ]; then |
| 45 | AARCH64_COMPILER_FLAGS+="CC=/usr/bin/clang CXX=/usr/bin/clang++ " |
| 46 | fi |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 47 | |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 48 | # NDK |
Nikhil Raj | 58a4923 | 2023-12-21 12:08:42 +0000 | [diff] [blame] | 49 | NDK_VERSION=26b |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 50 | NDK_SRC="$SOURCE_DIR"/android-ndk-r"$NDK_VERSION" |
| 51 | |
| 52 | # ANDROID |
| 53 | ANDROID_API_VERSION=30 |
| 54 | ANDROID_ARM_ARCH="arm64-v8a" |
Nikhil Raj | ba6dcb2 | 2023-11-24 16:25:10 +0000 | [diff] [blame] | 55 | ANDROID64_x86_TOOLCHAIN="$NDK_SRC/toolchains/llvm/prebuilt/linux-x86_64/" |
| 56 | ANDROID64_COMPILER_FLAGS="CC="$ANDROID64_x86_TOOLCHAIN"/bin/aarch64-linux-android"$ANDROID_API_VERSION"-clang \ |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 57 | CXX="$ANDROID64_x86_TOOLCHAIN"/bin/aarch64-linux-android"$ANDROID_API_VERSION"-clang++ " |
| 58 | |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 59 | # Flatbuffers |
Ciara Sookarry | 4a43c94 | 2023-09-20 12:10:31 +0100 | [diff] [blame] | 60 | FLATBUFFERS_VERSION=23.5.26 |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 61 | FLATBUFFERS_SRC="$SOURCE_DIR"/flatbuffers-"$FLATBUFFERS_VERSION" |
| 62 | FLATBUFFERS_BUILD_ROOT="$BUILD_DIR"/flatbuffers |
| 63 | FLATBUFFERS_BUILD_TARGET="$FLATBUFFERS_BUILD_ROOT"/"$TARGET_ARCH"_build |
| 64 | FLATBUFFERS_BUILD_HOST="$FLATBUFFERS_BUILD_ROOT"/"$HOST_ARCH"_build # Location of flatc compiler |
| 65 | |
| 66 | # Tensorflow |
Declan-ARM | 1c3be8f | 2024-01-16 12:10:41 +0000 | [diff] [blame] | 67 | TENSORFLOW_VERSION=v2.15.0 # v2.15.0 |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 68 | TENSORFLOW_SRC="$SOURCE_DIR"/tensorflow |
| 69 | TFLITE_SRC="$TENSORFLOW_SRC"/tensorflow/lite |
| 70 | SCHEMA_SRC="$TFLITE_SRC"/schema/schema.fbs |
| 71 | |
| 72 | # TF Lite Schema |
| 73 | FLATC="$FLATBUFFERS_BUILD_HOST"/bin/flatc |
| 74 | TFLITE_BUILD_ROOT="$BUILD_DIR"/tflite # Generated TF Lite Schema location |
| 75 | TFLITE_BUILD_TARGET="$TFLITE_BUILD_ROOT"/"$TARGET_ARCH"_build |
| 76 | |
| 77 | # Protobuf |
| 78 | PROTOBUF_VERSION=3.12.0 |
| 79 | PROTOBUF_SRC="$SOURCE_DIR"/protobuf-"$PROTOBUF_VERSION" |
| 80 | PROTOBUF_BUILD_ROOT="$BUILD_DIR"/protobuf |
| 81 | PROTOBUF_BUILD_HOST="$PROTOBUF_BUILD_ROOT"/"$HOST_ARCH"_build |
| 82 | PROTOCOL_COMPILER_HOST="$PROTOBUF_BUILD_HOST"/bin/protoc |
| 83 | PROTOBUF_BUILD_TARGET="$PROTOBUF_BUILD_ROOT"/"$TARGET_ARCH"_build |
Tracy Narine | 2883a86 | 2024-02-26 15:05:11 +0000 | [diff] [blame] | 84 | if [ "$osname" == "Darwin" ]; then |
| 85 | PROTOBUF_LIBRARY_TARGET="$PROTOBUF_BUILD_HOST"/lib/libprotobuf.dylib |
| 86 | else |
| 87 | PROTOBUF_LIBRARY_TARGET="$PROTOBUF_BUILD_TARGET"/lib/libprotobuf.so.23.0.0 |
| 88 | fi |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 89 | PROTOBUF_ANDROID_LIB_TARGET="$PROTOBUF_BUILD_TARGET"/lib/libprotobuf.so |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 90 | |
| 91 | # ONNX |
| 92 | ONNX_VERSION=1.6.0 |
| 93 | ONNX_SRC="$SOURCE_DIR"/onnx-"$ONNX_VERSION" |
| 94 | ONNX_BUILD_TARGET="$BUILD_DIR"/onnx/"$TARGET_ARCH"_build |
| 95 | |
| 96 | # Arm NN / ACL |
| 97 | ARMNN_SRC="$SOURCE_DIR"/armnn |
James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 98 | ACL_SRC="$SOURCE_DIR"/acl |
| 99 | |
| 100 | # Check if directory at $1 is a repository or not |
| 101 | check_if_repository() |
| 102 | { |
| 103 | pushd "$1" > /dev/null |
| 104 | |
| 105 | if [ "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]; then |
| 106 | popd > /dev/null |
| 107 | return 0 |
| 108 | else |
| 109 | popd > /dev/null |
| 110 | return 1 |
| 111 | fi |
Declan-ARM | 1c3be8f | 2024-01-16 12:10:41 +0000 | [diff] [blame] | 112 | } |