1#!/bin/bash 2# 3# Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved. 4# 5# SPDX-License-Identifier: MIT 6# 7 8CMD=$( basename "$0" ) 9 10# Revision or tag that Arm NN has been tested with: 11DEFAULT_TENSORFLOW_REVISION=6f692f73cb2043b4a0b0446539cd8c15b3dd9220 # r2.12 + PR #60015 to fix Cmake build. 12 13Usage() { 14 echo "Gets the revision or tag of TensorFlow that this version of Arm NN has been" 15 echo "tested with." 16 echo 17 echo "Usage: $CMD Gets the default TensorFlow revision/tag ($DEFAULT_TENSORFLOW_REVISION)" 18 echo "Usage: $CMD -s <TENSORFLOW_SHA>" 19 echo "Usage: $CMD -p (Print current default revision/tag)" 20 exit 0 21} 22 23PrintDefaultTensorFlowSha() { 24 echo $DEFAULT_TENSORFLOW_REVISION 25 exit 0; 26} 27 28function AssertZeroExitCode { 29 EXITCODE=$? 30 if [ $EXITCODE -ne 0 ]; then 31 echo "$1" 32 echo "+++ Command exited with code $EXITCODE. Please fix the above errors and re-run" 33 exit 1 34 fi 35} 36 37# Revision or tag to check out 38TENSORFLOW_REVISION=$DEFAULT_TENSORFLOW_REVISION 39 40# process the options given 41while getopts "s:ph" opt; do 42 case "$opt" in 43 s) TENSORFLOW_REVISION="$OPTARG";; 44 p) PrintDefaultTensorFlowSha;; 45 h) Usage;; 46 esac 47done 48shift $((OPTIND - 1)) 49 50# 51# This script is designed to be called from anywhere 52# so it will resolve where to checkout out TensorFlow 53# relative to its own location in armnn/scripts 54# 55SRC="${BASH_SOURCE[0]}" 56# resolve $SRC until it is no longer a symlink 57while [ -h "$SRC" ]; do 58 DIR="$( cd -P "$( dirname "$SRC" )" >/dev/null && pwd )" 59 SRC="$(readlink "$SRC")" 60 # if $SRC was a relative symlink, we need to resolve it 61 # relative to the path where the symlink file originally was 62 [[ $SRC != /* ]] && SRC="$DIR/$SRC" 63done 64DIR="$( cd -P "$( dirname "$SRC" )" >/dev/null && pwd )" 65pushd "${DIR}" > /dev/null 66cd ../.. || exit 67 68# Clone TensorFlow if we don't already have a directory 69if [ ! -d tensorflow ]; then 70 echo "Cloning TensorFlow" 71 git clone https://github.com/tensorflow/tensorflow.git 72 AssertZeroExitCode "Cloning TensorFlow failed" 73fi 74pushd tensorflow > /dev/null 75 76# Checkout the TensorFlow revision 77echo "Checking out ${TENSORFLOW_REVISION}" 78git fetch && git checkout "${TENSORFLOW_REVISION}" 79AssertZeroExitCode "Fetching and checking out ${TENSORFLOW_REVISION} failed" 80# If the target tensorflow revision includes a branch we also need to do a pull. 81# This generally occurs with a release branch. 82if [[ "${TENSORFLOW_REVISION}" == *"branches"* ]]; then 83 git pull 84 AssertZeroExitCode "TensorFlow reference includes a branch but git pull failed." 85fi 86 87popd > /dev/null # out of tensorflow 88popd > /dev/null # back to wherever we were when called 89# Make sure the SHA of the revision that was checked out is the last line 90# of output from the script... just in case we ever need it. 91echo "$TENSORFLOW_REVISION" 92exit 0 93