Mike Kelly | 4b88770 | 2021-12-14 15:22:48 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Colm Donelan | 718966f | 2022-10-10 10:06:12 +0100 | [diff] [blame] | 3 | # Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
Mike Kelly | 4b88770 | 2021-12-14 15:22:48 +0000 | [diff] [blame] | 4 | # |
| 5 | # SPDX-License-Identifier: MIT |
| 6 | # |
| 7 | |
James Conroy | 04cd603 | 2022-04-20 17:16:50 +0100 | [diff] [blame] | 8 | CMD=$( basename "$0" ) |
Mike Kelly | 4b88770 | 2021-12-14 15:22:48 +0000 | [diff] [blame] | 9 | |
| 10 | # Revision or tag that Arm NN has been tested with: |
Colm Donelan | 718966f | 2022-10-10 10:06:12 +0100 | [diff] [blame] | 11 | DEFAULT_TENSORFLOW_REVISION="tags/v2.10.0" # Release 2.10.0 tag |
Mike Kelly | 4b88770 | 2021-12-14 15:22:48 +0000 | [diff] [blame] | 12 | |
| 13 | Usage() { |
| 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 | |
| 23 | PrintDefaultTensorFlowSha() { |
| 24 | echo $DEFAULT_TENSORFLOW_REVISION |
| 25 | exit 0; |
| 26 | } |
| 27 | |
| 28 | function 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 |
| 38 | TENSORFLOW_REVISION=$DEFAULT_TENSORFLOW_REVISION |
| 39 | |
| 40 | # process the options given |
James Conroy | 04cd603 | 2022-04-20 17:16:50 +0100 | [diff] [blame] | 41 | while getopts "s:ph" opt; do |
Mike Kelly | 4b88770 | 2021-12-14 15:22:48 +0000 | [diff] [blame] | 42 | case "$opt" in |
| 43 | s) TENSORFLOW_REVISION="$OPTARG";; |
| 44 | p) PrintDefaultTensorFlowSha;; |
James Conroy | 04cd603 | 2022-04-20 17:16:50 +0100 | [diff] [blame] | 45 | h) Usage;; |
Mike Kelly | 4b88770 | 2021-12-14 15:22:48 +0000 | [diff] [blame] | 46 | esac |
| 47 | done |
| 48 | shift $((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 | # |
| 55 | SRC="${BASH_SOURCE[0]}" |
| 56 | # resolve $SRC until it is no longer a symlink |
| 57 | while [ -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" |
| 63 | done |
| 64 | DIR="$( cd -P "$( dirname "$SRC" )" >/dev/null && pwd )" |
James Conroy | 04cd603 | 2022-04-20 17:16:50 +0100 | [diff] [blame] | 65 | pushd "${DIR}" > /dev/null |
| 66 | cd ../.. || exit |
Mike Kelly | 4b88770 | 2021-12-14 15:22:48 +0000 | [diff] [blame] | 67 | |
| 68 | # Clone TensorFlow if we don't already have a directory |
| 69 | if [ ! -d tensorflow ]; then |
| 70 | echo "Cloning TensorFlow" |
| 71 | git clone https://github.com/tensorflow/tensorflow.git |
| 72 | AssertZeroExitCode "Cloning TensorFlow failed" |
| 73 | fi |
| 74 | pushd tensorflow > /dev/null |
| 75 | |
| 76 | # Checkout the TensorFlow revision |
| 77 | echo "Checking out ${TENSORFLOW_REVISION}" |
James Conroy | 04cd603 | 2022-04-20 17:16:50 +0100 | [diff] [blame] | 78 | git fetch && git checkout "${TENSORFLOW_REVISION}" |
Mike Kelly | 4b88770 | 2021-12-14 15:22:48 +0000 | [diff] [blame] | 79 | AssertZeroExitCode "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. |
| 82 | if [[ "${TENSORFLOW_REVISION}" == *"branches"* ]]; then |
| 83 | git pull |
| 84 | AssertZeroExitCode "TensorFlow reference includes a branch but git pull failed." |
| 85 | fi |
| 86 | |
| 87 | popd > /dev/null # out of tensorflow |
| 88 | popd > /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 Conroy | 04cd603 | 2022-04-20 17:16:50 +0100 | [diff] [blame] | 91 | echo "$TENSORFLOW_REVISION" |
Mike Kelly | 4b88770 | 2021-12-14 15:22:48 +0000 | [diff] [blame] | 92 | exit 0 |