blob: 0c34c7e7dfcec946a865bd0a00cbf76aecb02458 [file] [log] [blame]
James Conroy919ec712022-07-13 12:57:53 +01001#!/bin/bash
2#
Tracy Narine2883a862024-02-26 15:05:11 +00003# Copyright © 2022-2024 Arm Ltd and Contributors. All rights reserved.
James Conroy919ec712022-07-13 12:57:53 +01004# 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
12set -o nounset # Catch references to undefined variables.
13set -o pipefail # Catch non zero exit codes within pipelines.
14set -o errexit # Catch and propagate non zero exit codes.
15
16# ROOT_DIR is the directory in which a script is called from
17ROOT_DIR=$(pwd)
18SOURCE_DIR="$ROOT_DIR"/source
19BUILD_DIR="$ROOT_DIR"/build
20
21# Host architecture e.g. x86_64, aarch64
22HOST_ARCH=$(uname -m)
23
24# Number of online cores on host
25NUM_THREADS=$(getconf _NPROCESSORS_ONLN)
26
27# Validate common user-defined options
28# shellcheck source=validation.sh
29source "$rel_path"/validation.sh
30
31# target_arch supplied as command line arg
32TARGET_ARCH="$target_arch"
33
34NATIVE_BUILD=0
35if [ "$TARGET_ARCH" == "$HOST_ARCH" ]; then
36 NATIVE_BUILD=1
Tracy Narine2883a862024-02-26 15:05:11 +000037elif [ "$TARGET_ARCH" == "aarch64" ]; then
38 if [ "$HOST_ARCH" == "arm64" ]; then
39 NATIVE_BUILD=1
40 fi
James Conroy919ec712022-07-13 12:57:53 +010041fi
42
43AARCH64_COMPILER_FLAGS+="CC=/usr/bin/aarch64-linux-gnu-gcc CXX=/usr/bin/aarch64-linux-gnu-g++ "
Tracy Narine2883a862024-02-26 15:05:11 +000044if [ "$HOST_ARCH" == "arm64" ]; then
45 AARCH64_COMPILER_FLAGS+="CC=/usr/bin/clang CXX=/usr/bin/clang++ "
46fi
James Conroy919ec712022-07-13 12:57:53 +010047
John Mcloughlin35bae832023-07-24 11:55:13 +010048# NDK
Nikhil Raj58a49232023-12-21 12:08:42 +000049NDK_VERSION=26b
John Mcloughlin35bae832023-07-24 11:55:13 +010050NDK_SRC="$SOURCE_DIR"/android-ndk-r"$NDK_VERSION"
51
52# ANDROID
53ANDROID_API_VERSION=30
54ANDROID_ARM_ARCH="arm64-v8a"
Nikhil Rajba6dcb22023-11-24 16:25:10 +000055ANDROID64_x86_TOOLCHAIN="$NDK_SRC/toolchains/llvm/prebuilt/linux-x86_64/"
56ANDROID64_COMPILER_FLAGS="CC="$ANDROID64_x86_TOOLCHAIN"/bin/aarch64-linux-android"$ANDROID_API_VERSION"-clang \
John Mcloughlin35bae832023-07-24 11:55:13 +010057 CXX="$ANDROID64_x86_TOOLCHAIN"/bin/aarch64-linux-android"$ANDROID_API_VERSION"-clang++ "
58
James Conroy919ec712022-07-13 12:57:53 +010059# Flatbuffers
Ciara Sookarry4a43c942023-09-20 12:10:31 +010060FLATBUFFERS_VERSION=23.5.26
James Conroy919ec712022-07-13 12:57:53 +010061FLATBUFFERS_SRC="$SOURCE_DIR"/flatbuffers-"$FLATBUFFERS_VERSION"
62FLATBUFFERS_BUILD_ROOT="$BUILD_DIR"/flatbuffers
63FLATBUFFERS_BUILD_TARGET="$FLATBUFFERS_BUILD_ROOT"/"$TARGET_ARCH"_build
64FLATBUFFERS_BUILD_HOST="$FLATBUFFERS_BUILD_ROOT"/"$HOST_ARCH"_build # Location of flatc compiler
65
66# Tensorflow
Declan-ARM1c3be8f2024-01-16 12:10:41 +000067TENSORFLOW_VERSION=v2.15.0 # v2.15.0
James Conroy919ec712022-07-13 12:57:53 +010068TENSORFLOW_SRC="$SOURCE_DIR"/tensorflow
69TFLITE_SRC="$TENSORFLOW_SRC"/tensorflow/lite
70SCHEMA_SRC="$TFLITE_SRC"/schema/schema.fbs
71
72# TF Lite Schema
73FLATC="$FLATBUFFERS_BUILD_HOST"/bin/flatc
74TFLITE_BUILD_ROOT="$BUILD_DIR"/tflite # Generated TF Lite Schema location
75TFLITE_BUILD_TARGET="$TFLITE_BUILD_ROOT"/"$TARGET_ARCH"_build
76
77# Protobuf
78PROTOBUF_VERSION=3.12.0
79PROTOBUF_SRC="$SOURCE_DIR"/protobuf-"$PROTOBUF_VERSION"
80PROTOBUF_BUILD_ROOT="$BUILD_DIR"/protobuf
81PROTOBUF_BUILD_HOST="$PROTOBUF_BUILD_ROOT"/"$HOST_ARCH"_build
82PROTOCOL_COMPILER_HOST="$PROTOBUF_BUILD_HOST"/bin/protoc
83PROTOBUF_BUILD_TARGET="$PROTOBUF_BUILD_ROOT"/"$TARGET_ARCH"_build
Tracy Narine2883a862024-02-26 15:05:11 +000084if [ "$osname" == "Darwin" ]; then
85 PROTOBUF_LIBRARY_TARGET="$PROTOBUF_BUILD_HOST"/lib/libprotobuf.dylib
86else
87 PROTOBUF_LIBRARY_TARGET="$PROTOBUF_BUILD_TARGET"/lib/libprotobuf.so.23.0.0
88fi
John Mcloughlin35bae832023-07-24 11:55:13 +010089PROTOBUF_ANDROID_LIB_TARGET="$PROTOBUF_BUILD_TARGET"/lib/libprotobuf.so
James Conroy919ec712022-07-13 12:57:53 +010090
91# ONNX
92ONNX_VERSION=1.6.0
93ONNX_SRC="$SOURCE_DIR"/onnx-"$ONNX_VERSION"
94ONNX_BUILD_TARGET="$BUILD_DIR"/onnx/"$TARGET_ARCH"_build
95
96# Arm NN / ACL
97ARMNN_SRC="$SOURCE_DIR"/armnn
James Conroy210897d2022-08-04 16:55:05 +010098ACL_SRC="$SOURCE_DIR"/acl
99
100# Check if directory at $1 is a repository or not
101check_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-ARM1c3be8f2024-01-16 12:10:41 +0000112}