From 2883a86c5a167aea3c736529bff5921ab6cbc99c Mon Sep 17 00:00:00 2001 From: Tracy Narine Date: Mon, 26 Feb 2024 15:05:11 +0000 Subject: IVGCVSW-8172 Add macOS support to build tool setup * Updates build rules for platform * Failing unit tests excluded (dynamic backends, profiling) * install-packages.sh generates manual setup information Signed-off-by: Tracy Narine Change-Id: I2d3d434aa615a8796c0cb94cd5b9c35a5acfd148 --- build-tool/scripts/build-armnn.sh | 60 ++++++++++++++++++++++++++++++---- build-tool/scripts/common.sh | 15 +++++++-- build-tool/scripts/install-packages.sh | 21 +++++++++++- build-tool/scripts/setup-armnn.sh | 44 +++++++++++++++++++++++-- build-tool/scripts/validation.sh | 6 ++-- 5 files changed, 132 insertions(+), 14 deletions(-) (limited to 'build-tool') diff --git a/build-tool/scripts/build-armnn.sh b/build-tool/scripts/build-armnn.sh index 18e59e1cb5..5bc8d697ff 100755 --- a/build-tool/scripts/build-armnn.sh +++ b/build-tool/scripts/build-armnn.sh @@ -17,12 +17,36 @@ abs_script_path=$(cd "$rel_path" ; pwd -P) # absolute path to script directory abs_btool_path=$(dirname "$abs_script_path") # absolute path to build-tool directory abs_armnn_path=$(dirname "$abs_btool_path") # absolute path to armnn directory +# Figure out platform specific settings +osname=$(uname) +osgetopt=getopt +os_darwin=0 +if [ "$osname" == "Darwin" ]; then + os_darwin=1 + osgetoptsys="/opt/homebrew/opt/gnu-getopt/bin/getopt" + osgetopthome="$HOME/homebrew/opt/gnu-getopt/bin/getopt" + if [ -f "$osgetoptsys" ]; then + echo "gnu-getopt found at: $osgetoptsys" + osgetopt=$osgetoptsys + elif [ -f "$osgetopthome" ]; then + echo "gnu-getopt found at: $osgetopthome" + osgetopt=$osgetopthome + else + echo "Run $rel_path/install-packages.sh and follow the instructions to configure the environment for $osname" + exit 1 + fi +fi + build_acl() { cd "$ACL_SRC" # $acl_scons_params are additional options provided by the user and will overwrite any previously defined args - 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" + acl_extra="" + if [ "$os_darwin" -eq 1 ]; then + acl_extra="os=macos " + fi + 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" if [ "$flag_debug" -eq 1 ]; then acl_params="$acl_params debug=1 asserts=1" @@ -100,10 +124,16 @@ build_armnn() local cmake_flags="" local compile_flags="" local android_cmake_args="" + local linker_cmake_args="" + local warn_flags="" case "$TARGET_ARCH" in "aarch64") compile_flags+="$AARCH64_COMPILER_FLAGS" + if [ "$os_darwin" -eq 1 ]; then + linker_cmake_args="-DCMAKE_SHARED_LINKER_FLAGS='-framework CoreFoundation -framework Foundation'" + warn_flags="-DCMAKE_CXX_FLAGS='-Wno-error=deprecated-declarations'" + fi ;; "android64") compile_flags+="$ANDROID64_COMPILER_FLAGS" @@ -125,8 +155,17 @@ build_armnn() echo -e "\n***** Building Arm NN for $TARGET_ARCH *****" + local flatbuffers_root="$FLATBUFFERS_BUILD_TARGET" + local protobuf_root="$PROTOBUF_BUILD_TARGET" + if [ "$os_darwin" -eq 1 ]; then + flatbuffers_root="$FLATBUFFERS_BUILD_HOST" + protobuf_root="$PROTOBUF_BUILD_HOST" + fi + eval "$compile_flags" \ cmake "$android_cmake_args" \ + "$linker_cmake_args" \ + "$warn_flags" \ -DCMAKE_BUILD_TYPE="$build_type" \ -DBUILD_CLASSIC_DELEGATE="$flag_tflite_classic_delegate" \ -DBUILD_OPAQUE_DELEGATE="$flag_tflite_opaque_delegate" \ @@ -143,17 +182,21 @@ build_armnn() -DTF_LITE_GENERATED_PATH="$TFLITE_SRC"/schema \ -DTF_LITE_SCHEMA_INCLUDE_PATH="$TFLITE_SRC"/schema \ -DTFLITE_LIB_ROOT="$TFLITE_BUILD_TARGET" \ - -DFLATBUFFERS_ROOT="$FLATBUFFERS_BUILD_TARGET" \ + -DFLATBUFFERS_ROOT="$flatbuffers_root" \ -DFLATC_DIR="$FLATBUFFERS_BUILD_HOST" \ -DONNX_GENERATED_SOURCES="$ONNX_BUILD_TARGET" \ - -DPROTOBUF_ROOT="$PROTOBUF_BUILD_TARGET" \ + -DPROTOBUF_ROOT="$protobuf_root" \ "$armnn_cmake_args" \ "$ARMNN_SRC" make -j "$NUM_THREADS" # Copy protobuf library into Arm NN build directory, if ONNX Parser is enabled - if [ "$flag_onnx_parser" -eq 1 ]; then + if [ "$flag_onnx_parser" -eq 1 ] && [ "$os_darwin" -eq 1 ]; then + cd "$ARMNN_BUILD_TARGET" + rm -f libprotobuf.dylib libprotobuf.23.dylib + cp "$PROTOBUF_LIBRARY_TARGET" . + elif [ "$flag_onnx_parser" -eq 1 ]; then cd "$ARMNN_BUILD_TARGET" rm -f libprotobuf.so libprotobuf.so.23 libprotobuf.so.23.0.0 if [ "$TARGET_ARCH" != "android64" ]; then @@ -228,7 +271,12 @@ download_acl() acl_tag="$(echo "$armnn_branch" | tr '\n' ' ' | sed -e 's/[^0-9]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' ' | sed 's/ /./g')" cd "$ACL_SRC" - git checkout v"$acl_tag" + if [ "$acl_tag" == "" ]; then + # Take the latest + git checkout main + else + git checkout v"$acl_tag" + fi echo -e "\n***** ACL Downloaded: $acl_tag *****" } @@ -324,7 +372,7 @@ if [ $# -eq 0 ]; then exit 1 fi -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:,symlink-armnn,help -n "$name" -- "$@") +args=$($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" -- "$@") eval set -- "$args" while [ $# -gt 0 ]; do if [ -n "${opt_prev:-}" ]; then diff --git a/build-tool/scripts/common.sh b/build-tool/scripts/common.sh index e68de99c9d..0c34c7e7df 100755 --- a/build-tool/scripts/common.sh +++ b/build-tool/scripts/common.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved. +# Copyright © 2022-2024 Arm Ltd and Contributors. All rights reserved. # SPDX-License-Identifier: MIT # @@ -34,9 +34,16 @@ TARGET_ARCH="$target_arch" NATIVE_BUILD=0 if [ "$TARGET_ARCH" == "$HOST_ARCH" ]; then NATIVE_BUILD=1 +elif [ "$TARGET_ARCH" == "aarch64" ]; then + if [ "$HOST_ARCH" == "arm64" ]; then + NATIVE_BUILD=1 + fi fi AARCH64_COMPILER_FLAGS+="CC=/usr/bin/aarch64-linux-gnu-gcc CXX=/usr/bin/aarch64-linux-gnu-g++ " +if [ "$HOST_ARCH" == "arm64" ]; then + AARCH64_COMPILER_FLAGS+="CC=/usr/bin/clang CXX=/usr/bin/clang++ " +fi # NDK NDK_VERSION=26b @@ -74,7 +81,11 @@ PROTOBUF_BUILD_ROOT="$BUILD_DIR"/protobuf PROTOBUF_BUILD_HOST="$PROTOBUF_BUILD_ROOT"/"$HOST_ARCH"_build PROTOCOL_COMPILER_HOST="$PROTOBUF_BUILD_HOST"/bin/protoc PROTOBUF_BUILD_TARGET="$PROTOBUF_BUILD_ROOT"/"$TARGET_ARCH"_build -PROTOBUF_LIBRARY_TARGET="$PROTOBUF_BUILD_TARGET"/lib/libprotobuf.so.23.0.0 +if [ "$osname" == "Darwin" ]; then + PROTOBUF_LIBRARY_TARGET="$PROTOBUF_BUILD_HOST"/lib/libprotobuf.dylib +else + PROTOBUF_LIBRARY_TARGET="$PROTOBUF_BUILD_TARGET"/lib/libprotobuf.so.23.0.0 +fi PROTOBUF_ANDROID_LIB_TARGET="$PROTOBUF_BUILD_TARGET"/lib/libprotobuf.so # ONNX diff --git a/build-tool/scripts/install-packages.sh b/build-tool/scripts/install-packages.sh index 1a238b6c98..4a461a0d55 100755 --- a/build-tool/scripts/install-packages.sh +++ b/build-tool/scripts/install-packages.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +# Copyright © 2022, 2024 Arm Ltd and Contributors. All rights reserved. # SPDX-License-Identifier: MIT # @@ -91,6 +91,25 @@ install_apt_packages() rm -rf /var/lib/apt/lists/* } +usage_darwin() +{ + cat <