xref: /aosp_15_r20/external/armnn/scripts/get_compute_library.sh (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1#!/bin/bash
2#
3# Copyright © 2018-2023 Arm Ltd. All rights reserved.
4# SPDX-License-Identifier: MIT
5#
6
7CMD=$( basename "$0" )
8
9# For pinning to a ref use this:
10#DEFAULT_CLFRAMEWORKREVISION="branches/arm_compute_23_02" # Release 23.02
11#
12# For pinning to a revision use this:
13DEFAULT_CLFRAMEWORKREVISION="467daef993fe29cc4319058200b7ad797398e4b0" #9454: Implement CL kernel for a native batched matmul Quantized - LHS transposed, RHS transposed
14
15usage() {
16  echo -e "get_compute_library.sh: Clones the Arm Compute Library (ACL) repo from the ML Platform server and checks out
17  the pinned version of ACL based on the SHA string defined at the top of this script (DEFAULT_CLFRAMEWORKREVISION).
18  If the ACL repo already exists, this script will skip cloning and only checkout the relevant SHA.
19  The pinned ACL version is a known version that works correctly with the version of Arm NN being used. This pin is
20  regularly updated by the Arm NN team on the Arm NN 'main' branch.
21  During release periods, the ACL pin will point to an ACL release branch which exists on the ML Platform server.
22  The repo directory will be named 'clframework' unless defined by the '-n' argument to this script.\n"
23  echo "Usage: $CMD (Use the default clframework SHA)"
24  echo "Usage: $CMD -s <CLFRAMEWORK_SHA>"
25  echo "Usage: $CMD -p (Print current default clframework SHA)"
26  echo "Usage: $CMD -n Name of the directory into which the ACL repo will be cloned, default is 'clframework'"
27  exit 0
28}
29
30PrintDefaultClframeworkSha() {
31  echo $DEFAULT_CLFRAMEWORKREVISION
32  exit 0;
33}
34
35function AssertZeroExitCode {
36  EXITCODE=$?
37  if [ $EXITCODE -ne 0 ]; then
38    echo "$1"
39    echo "+++ Command exited with code $EXITCODE. Please fix the above errors and re-run"
40    exit 1
41  fi
42}
43
44# process the options given
45while getopts "s:n:ph" opt; do
46  case "$opt" in
47    s) CLFRAMEWORK_SHA="$OPTARG";;
48    p) PrintDefaultClframeworkSha;;
49    n) ACL_REPO_NAME_OPTION="$OPTARG";;
50    h|\?) usage;;
51  esac
52done
53shift $((OPTIND - 1))
54
55#
56# This script is designed to be called from anywhere
57# so it will resolve where to checkout out the clframework
58# relative to its own location in armnn/scripts
59#
60SRC="${BASH_SOURCE[0]}"
61# resolve $SRC until it is no longer a symlink
62while [ -h "$SRC" ]; do
63  DIR="$( cd -P "$( dirname "$SRC" )" >/dev/null && pwd )"
64  SRC="$(readlink "$SRC")"
65  # if $SRC was a relative symlink, we need to resolve it
66  # relative to the path where the symlink file originally was
67  [[ $SRC != /* ]] && SRC="$DIR/$SRC"
68done
69DIR="$( cd -P "$( dirname "$SRC" )" >/dev/null && pwd )"
70pushd "${DIR}" > /dev/null
71# shellcheck disable=SC2164
72cd ../..
73
74# Default ACL repo directory name is 'clframework'
75# This can be overwritten by command line option '-n'
76ACL_REPO_NAME="clframework"
77if [ ! -z "$ACL_REPO_NAME_OPTION" ]; then
78  ACL_REPO_NAME="$ACL_REPO_NAME_OPTION"
79fi
80
81if [ ! -d "$ACL_REPO_NAME" ]; then
82  echo "Cloning CL Framework"
83  git clone https://review.mlplatform.org/ml/ComputeLibrary "$ACL_REPO_NAME"
84  AssertZeroExitCode "Cloning CL Framework failed"
85fi
86pushd "$ACL_REPO_NAME" > /dev/null
87
88CLFRAMEWORKREVISION=$DEFAULT_CLFRAMEWORKREVISION
89if [ ! -z "$CLFRAMEWORK_SHA" ]; then
90  CLFRAMEWORKREVISION=$CLFRAMEWORK_SHA
91fi
92
93echo "git fetch && git fetch https://review.mlplatform.org/ml/ComputeLibrary && git checkout $CLFRAMEWORKREVISION"
94git fetch && git fetch https://review.mlplatform.org/ml/ComputeLibrary && git checkout "${CLFRAMEWORKREVISION}"
95AssertZeroExitCode "Fetching and checking out ${CLFRAMEWORKREVISION} failed"
96# If the target ACL revision includes a branch we also need to do a pull.
97# This generally occurs with a release branch.
98if [[ "${CLFRAMEWORKREVISION}" == *"branches"* ]]; then
99  git pull
100  AssertZeroExitCode "ACL reference includes a branch but git pull failed."
101fi
102
103# Set commit hook so we can submit reviews to gerrit
104# shellcheck disable=SC2006
105(curl -Lo "$(git rev-parse --git-dir)"/hooks/commit-msg https://review.mlplatform.org/tools/hooks/commit-msg; chmod +x "$(git rev-parse --git-dir)"/hooks/commit-msg)
106AssertZeroExitCode "Setting commit hooks failed"
107
108popd > /dev/null # out of clframework / "$ACL_REPO_NAME"
109popd > /dev/null # back to wherever we were when called
110# Make sure the SHA of the revision that was checked out is the last line
111# of output from the script... just in case we ever need it.
112echo "$CLFRAMEWORKREVISION"
113exit 0
114