Skip to content

[Arm][Example] Minor Script Updates #715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/arm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ run.sh also takes a second optional positional arg to specify a buck2 command.
To run these scripts. On a Linux system, in a terminal, with a working internet connection,
```
# Step [1] - setup necessary tools
$ ./setup.sh
$ ./setup.sh --i-agree-to-the-contained-eula [optional-scratch-dir]

# Step [2] - build + run ExecuTorch and executor_runner baremetal application
# suited for Corstone300 to run a simple PyTorch model.
$ ./run.sh
$ ./run.sh [same-optional-scratch-dir-as-before]
```
15 changes: 9 additions & 6 deletions examples/arm/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

set -eu

if [[ "${1:-"."}" == "-h" ]]; then
if [[ "${1:-'.'}" == "-h" || "${#}" -gt 2 ]]; then
echo "Usage: $(basename $0) [path-to-a-scratch-dir] [buck2 binary]"
exit 0
echo "Supplied args: $*"
exit 1
fi

########
Expand Down Expand Up @@ -47,8 +48,8 @@ function generate_pte_file() {
# Generate the ethos delegate PTE file
function generate_ethos_pte_file() {
cd $et_root_dir
python3 examples/arm/arm_ethosu_minimal.py &> /dev/null
cd ./ethosout/simple_add/torch/
python3 examples/arm/arm_ethosu_minimal.py &> /dev/null
cd ./ethosout/simple_add/torch/
local pte_file=$(realpath ./delegated.pte)
[[ -f ${pte_file} ]] || { echo "Failed to generate a pte file - ${pte_file}"; exit 1; }
echo "${pte_file}"
Expand All @@ -67,6 +68,7 @@ function build_executorch() {
-DEXECUTORCH_BUILD_GFLAGS=OFF \
-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \
-DEXECUTORCH_BUILD_HOST_TARGETS=OFF \
-DEXECUTORCH_BUILD_SDK=OFF \
-DEXECUTORCH_BUILD_ARM_BAREMETAL=ON \
-DCMAKE_BUILD_TYPE=Release \
-DEXECUTORCH_ENABLE_LOGGING=ON \
Expand All @@ -78,13 +80,14 @@ function build_executorch() {
echo "[${FUNCNAME[0]}] Configured CMAKE"

n=$(nproc)
cmake --build . -j"$((n - 5))" -- VERBOSE=1
cmake --build . -- -j"$((n - 5))"
echo "[${FUNCNAME[0]}] Generated static libraries for ExecuTorch:"
find . -name "*.a" -exec ls -al {} \;
}

# build Arm Baremetal executor_runner
function build_executorch_runner() {
echo "[${FUNCNAME[0]}] Generating ExecuTorch libraries"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice a few other functions do not have this diagnostic output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we should standardize a bit more

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deferring this for later

[[ $# -ne 2 ]] && { echo "[${FUNCNAME[0]}]" "Expecting 2 pte files as arguments got, $*"; exit 1; }
local pte=${1}
local pte_delegate=${2}
Expand All @@ -100,7 +103,7 @@ function build_executorch_runner() {
echo "[${FUNCNAME[0]}] Configured CMAKE"

n=$(nproc)
cmake --build build -- -j"$((n - 5))" executor_runner executor_runner_delegate VERBOSE=1
cmake --build build -- -j"$((n - 5))" executor_runner executor_runner_delegate
echo "[${FUNCNAME[0]}] Generated baremetal elf file:"
find . -name "executor_runner.elf"
}
Expand Down
102 changes: 57 additions & 45 deletions examples/arm/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

set -eu

if [[ "${1:-'.'}" == "-h" ]]; then
echo "Usage: $(basename $0) [path-to-a-scratch-dir]"
exit 0
if [[ "${1:-'.'}" == "-h" || "${#}" -eq 0 || "${#}" -gt 2 ]]; then
echo "Usage: $(basename $0) <--i-agree-to-the-contained-eula> [path-to-a-scratch-dir]"
echo "Supplied args: $*"
exit 1
fi

########
Expand Down Expand Up @@ -44,33 +45,42 @@ function verify_md5() {
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)

if [[ $(get_cpu_arch) == "x86_64" ]]; then
# FVP
fvp_url="https://developer.arm.com/-/media/Arm%20Developer%20Community/Downloads/OSS/FVP/Corstone-300/FVP_Corstone_SSE-300_11.22_20_Linux64.tgz?rev=018659bd574f4e7b95fa647e7836ccf4&hash=22A79103C6FA5FFA7AFF3BE0447F3FF9"
fvp_model_dir="Linux64_GCC-9.3"
fvp_md5_checksum="98e93b949d0fbac977292d8668d34523"

# toochain
toolchain_url="https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu/12.3.rel1/binrel/arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-eabi.tar.xz"
toolchain_dir="arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-eabi"
toolchain_md5_checksum="00ebb1b70b1f88906c61206457eacb61"
# FVP
fvp_url="https://developer.arm.com/-/media/Arm%20Developer%20Community/Downloads/OSS/FVP/Corstone-300/FVP_Corstone_SSE-300_11.22_20_Linux64.tgz?rev=018659bd574f4e7b95fa647e7836ccf4&hash=22A79103C6FA5FFA7AFF3BE0447F3FF9"
fvp_model_dir="Linux64_GCC-9.3"
fvp_md5_checksum="98e93b949d0fbac977292d8668d34523"

# toochain
toolchain_url="https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu/12.3.rel1/binrel/arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-eabi.tar.xz"
toolchain_dir="arm-gnu-toolchain-12.3.rel1-x86_64-arm-none-eabi"
toolchain_md5_checksum="00ebb1b70b1f88906c61206457eacb61"
elif [[ $(get_cpu_arch) == "aarch64" ]]; then
# FVP
fvp_url="https://developer.arm.com/-/media/Arm%20Developer%20Community/Downloads/OSS/FVP/Corstone-300/FVP_Corstone_SSE-300_11.22_20_Linux64_armv8l.tgz?rev=9cc6e9a32bb947ca9b21fa162144cb01&hash=7657A4CF27D42E892E3F08D452AAB073"
fvp_url="https://developer.arm.com/-/media/Arm%20Developer%20Community/Downloads/OSS/FVP/Corstone-300/FVP_Corstone_SSE-300_11.22_20_Linux64_armv8l.tgz?rev=9cc6e9a32bb947ca9b21fa162144cb01&hash=7657A4CF27D42E892E3F08D452AAB073"
fvp_model_dir="Linux64_armv8l_GCC-9.3"
fvp_md5_checksum="cbbabbe39b07939cff7a3738e1492ef1"
fvp_md5_checksum="cbbabbe39b07939cff7a3738e1492ef1"

# toochain
toolchain_url="https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu/12.3.rel1/binrel/arm-gnu-toolchain-12.3.rel1-aarch64-arm-none-eabi.tar.xz"
toolchain_dir="arm-gnu-toolchain-12.3.rel1-aarch64-arm-none-eabi"
toolchain_md5_checksum="02c9b0d3bb1110575877d8eee1f223f2"
toolchain_md5_checksum="02c9b0d3bb1110575877d8eee1f223f2"
else
echo "[main] Error: only x86-64 & aarch64 architecture is supported for now!"; exit 1;
echo "[main] Error: only x86-64 & aarch64 architecture is supported for now!"; exit 1;
fi

# ethos-u
ethos_u_repo_url="https://review.mlplatform.org/ml/ethos-u/ethos-u"
ethos_u_base_rev="0995223100e3da8011700f58e491f1bf59511e3c"

########
### Mandatory user args
########
eula_acceptance="${1:-'.'}"; shift
if [[ "${eula_acceptance}" != "--i-agree-to-the-contained-eula" ]]; then
echo "Must pass first positional argument '--i-agree-to-the-contained-eula' to agree to EULA associated with downloading the FVP. Exiting!"
exit 1
fi

########
### Optional user args
########
Expand Down Expand Up @@ -152,38 +162,40 @@ function patch_repo() {
}

function setup_tosa_reference_model() {
# The debug flow on the host includes running on a reference implementation of TOSA
# This is useful primarily for debug of quantization accuracy, but also for internal
# errors for the early codebase
cd "${root_dir}"
if [[ ! -e reference_model ]]; then
git clone https://git.mlplatform.org/tosa/reference_model.git -b v0.80.0
cd reference_model
git submodule update --init --recursive
cd ..
fi
cd reference_model
mkdir -p build
cd build
cmake ..
make
cd reference_model
tosa_bin_path=`pwd`
echo "export PATH=\${PATH}:${tosa_bin_path}" >> "${setup_path_script}"
# The debug flow on the host includes running on a reference implementation of TOSA
# This is useful primarily for debug of quantization accuracy, but also for internal
# errors for the early codebase
cd "${root_dir}"
if [[ ! -e reference_model ]]; then
git clone https://git.mlplatform.org/tosa/reference_model.git -b v0.80.0
cd reference_model
git submodule update --init --recursive
cd ..
fi
cd reference_model
mkdir -p build
cd build
cmake ..
n=$(nproc)
make -j"$((n - 5))"
cd reference_model
tosa_bin_path=`pwd`
echo "export PATH=\${PATH}:${tosa_bin_path}" >> "${setup_path_script}"
}

function setup_vela() {
#
# Prepare the Vela compiler for AoT to Ethos-U compilation
#
cd "${root_dir}/ethos-u/"
if [[ ! -e ethos-u-vela ]]; then
git clone https://git.mlplatform.org/ml/ethos-u/ethos-u-vela.git
name="ethos-u-vela"
base_rev=00a15db3e1a188b25065d095152d701f4394cdc5
patch_repo
fi
pip install .
#
# Prepare the Vela compiler for AoT to Ethos-U compilation
#
cd "${root_dir}/ethos-u/"
if [[ ! -e ethos-u-vela ]]; then
git clone https://git.mlplatform.org/ml/ethos-u/ethos-u-vela.git
name="ethos-u-vela"
base_rev=00a15db3e1a188b25065d095152d701f4394cdc5
patch_repo
fi
cd "${root_dir}/ethos-u/ethos-u-vela"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this was because patch_repo was leaving us in ethos-u-vela directory and so pip install . was in the right place (a clean re-run works on this stage) ; do we want to consistently sub-shell functions to prevent this kind of leak?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good. But still we don't want to make too many assumption (beyond var values) when we enter the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deferring this for later

pip install .
}

########
Expand Down