blob: 9bd6f5b20cc7842e4322ee8d49a1af78c082fb6f [file] [log] [blame]
Mike Kelly4b887702021-12-14 15:22:48 +00001#!/bin/bash
2#
Colm Donelan718966f2022-10-10 10:06:12 +01003# Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
Mike Kelly4b887702021-12-14 15:22:48 +00004#
5# SPDX-License-Identifier: MIT
6#
7
James Conroy04cd6032022-04-20 17:16:50 +01008CMD=$( basename "$0" )
Mike Kelly4b887702021-12-14 15:22:48 +00009
10# Revision or tag that Arm NN has been tested with:
Colm Donelan718966f2022-10-10 10:06:12 +010011DEFAULT_TENSORFLOW_REVISION="tags/v2.10.0" # Release 2.10.0 tag
Mike Kelly4b887702021-12-14 15:22:48 +000012
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
James Conroy04cd6032022-04-20 17:16:50 +010041while getopts "s:ph" opt; do
Mike Kelly4b887702021-12-14 15:22:48 +000042 case "$opt" in
43 s) TENSORFLOW_REVISION="$OPTARG";;
44 p) PrintDefaultTensorFlowSha;;
James Conroy04cd6032022-04-20 17:16:50 +010045 h) Usage;;
Mike Kelly4b887702021-12-14 15:22:48 +000046 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 )"
James Conroy04cd6032022-04-20 17:16:50 +010065pushd "${DIR}" > /dev/null
66cd ../.. || exit
Mike Kelly4b887702021-12-14 15:22:48 +000067
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}"
James Conroy04cd6032022-04-20 17:16:50 +010078git fetch && git checkout "${TENSORFLOW_REVISION}"
Mike Kelly4b887702021-12-14 15:22:48 +000079AssertZeroExitCode "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.
James Conroy04cd6032022-04-20 17:16:50 +010091echo "$TENSORFLOW_REVISION"
Mike Kelly4b887702021-12-14 15:22:48 +000092exit 0