James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 3 | # Copyright © 2022-2023 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 |
| 37 | fi |
| 38 | |
| 39 | AARCH64_COMPILER_FLAGS+="CC=/usr/bin/aarch64-linux-gnu-gcc CXX=/usr/bin/aarch64-linux-gnu-g++ " |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 40 | |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 41 | # NDK |
| 42 | NDK_VERSION=25 |
| 43 | NDK_SRC="$SOURCE_DIR"/android-ndk-r"$NDK_VERSION" |
| 44 | |
| 45 | # ANDROID |
| 46 | ANDROID_API_VERSION=30 |
| 47 | ANDROID_ARM_ARCH="arm64-v8a" |
| 48 | ANDROID64_x86_TOOLCHAIN+="$NDK_SRC/toolchains/llvm/prebuilt/linux-x86_64" |
| 49 | ANDROID64_COMPILER_FLAGS+="CC="$ANDROID64_x86_TOOLCHAIN"/bin/aarch64-linux-android"$ANDROID_API_VERSION"-clang \ |
| 50 | CXX="$ANDROID64_x86_TOOLCHAIN"/bin/aarch64-linux-android"$ANDROID_API_VERSION"-clang++ " |
| 51 | |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 52 | # Flatbuffers |
James Conroy | 2d273bf | 2022-10-05 11:21:53 +0100 | [diff] [blame] | 53 | FLATBUFFERS_VERSION=2.0.6 |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 54 | FLATBUFFERS_SRC="$SOURCE_DIR"/flatbuffers-"$FLATBUFFERS_VERSION" |
| 55 | FLATBUFFERS_BUILD_ROOT="$BUILD_DIR"/flatbuffers |
| 56 | FLATBUFFERS_BUILD_TARGET="$FLATBUFFERS_BUILD_ROOT"/"$TARGET_ARCH"_build |
| 57 | FLATBUFFERS_BUILD_HOST="$FLATBUFFERS_BUILD_ROOT"/"$HOST_ARCH"_build # Location of flatc compiler |
| 58 | |
| 59 | # Tensorflow |
Nikhil Raj | 0d29453 | 2023-04-20 15:19:05 +0100 | [diff] [blame] | 60 | TENSORFLOW_VERSION="6f692f73cb2043b4a0b0446539cd8c15b3dd9220" #2.12 RC1 + PR #60015 to fix Cmake build. |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 61 | TENSORFLOW_SRC="$SOURCE_DIR"/tensorflow |
| 62 | TFLITE_SRC="$TENSORFLOW_SRC"/tensorflow/lite |
| 63 | SCHEMA_SRC="$TFLITE_SRC"/schema/schema.fbs |
| 64 | |
| 65 | # TF Lite Schema |
| 66 | FLATC="$FLATBUFFERS_BUILD_HOST"/bin/flatc |
| 67 | TFLITE_BUILD_ROOT="$BUILD_DIR"/tflite # Generated TF Lite Schema location |
| 68 | TFLITE_BUILD_TARGET="$TFLITE_BUILD_ROOT"/"$TARGET_ARCH"_build |
| 69 | |
| 70 | # Protobuf |
| 71 | PROTOBUF_VERSION=3.12.0 |
| 72 | PROTOBUF_SRC="$SOURCE_DIR"/protobuf-"$PROTOBUF_VERSION" |
| 73 | PROTOBUF_BUILD_ROOT="$BUILD_DIR"/protobuf |
| 74 | PROTOBUF_BUILD_HOST="$PROTOBUF_BUILD_ROOT"/"$HOST_ARCH"_build |
| 75 | PROTOCOL_COMPILER_HOST="$PROTOBUF_BUILD_HOST"/bin/protoc |
| 76 | PROTOBUF_BUILD_TARGET="$PROTOBUF_BUILD_ROOT"/"$TARGET_ARCH"_build |
| 77 | PROTOBUF_LIBRARY_TARGET="$PROTOBUF_BUILD_TARGET"/lib/libprotobuf.so.23.0.0 |
John Mcloughlin | 35bae83 | 2023-07-24 11:55:13 +0100 | [diff] [blame] | 78 | PROTOBUF_ANDROID_LIB_TARGET="$PROTOBUF_BUILD_TARGET"/lib/libprotobuf.so |
James Conroy | 919ec71 | 2022-07-13 12:57:53 +0100 | [diff] [blame] | 79 | |
| 80 | # ONNX |
| 81 | ONNX_VERSION=1.6.0 |
| 82 | ONNX_SRC="$SOURCE_DIR"/onnx-"$ONNX_VERSION" |
| 83 | ONNX_BUILD_TARGET="$BUILD_DIR"/onnx/"$TARGET_ARCH"_build |
| 84 | |
| 85 | # Arm NN / ACL |
| 86 | ARMNN_SRC="$SOURCE_DIR"/armnn |
James Conroy | 210897d | 2022-08-04 16:55:05 +0100 | [diff] [blame] | 87 | ACL_SRC="$SOURCE_DIR"/acl |
| 88 | |
| 89 | # Check if directory at $1 is a repository or not |
| 90 | check_if_repository() |
| 91 | { |
| 92 | pushd "$1" > /dev/null |
| 93 | |
| 94 | if [ "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]; then |
| 95 | popd > /dev/null |
| 96 | return 0 |
| 97 | else |
| 98 | popd > /dev/null |
| 99 | return 1 |
| 100 | fi |
| 101 | } |