Skip to content

Commit 338e663

Browse files
digantdesaifacebook-github-bot
authored andcommitted
Add example script to run on cpu
Summary: An example script to build and run executor_runner baremetal version on ARM M-class CPUs Differential Revision: D49900956 fbshipit-source-id: e30571f95abd5311f3ab649fcb1d154b4f5c3310
1 parent 0a103f5 commit 338e663

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

examples/backend/arm/run.sh

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -eu
9+
10+
########
11+
### Hardcoded constants
12+
########
13+
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
14+
et_root_dir=$(readlink -f ${script_dir}/../../../)
15+
et_build_dir=${et_root_dir}/cmake-out
16+
ethos_u_root_dir=${1:-"$(readlink -f ${script_dir}/../ethos-u)"}
17+
ethos_u_build_dir=${ethos_u_root_dir}/core_platform/build
18+
fvp_model=FVP_Corstone_SSE-300_Ethos-U55
19+
toolchain_cmake=${ethos_u_root_dir}/core_platform/cmake/toolchain/arm-none-eabi-gcc.cmake
20+
_setup_msg="please refer to ${script_dir}/ethos-u-setup/setup.sh to properly install necessary tools."
21+
22+
23+
# Generate eager mode results
24+
# TODO
25+
26+
# Generate the PTE file
27+
function generate_pte_file() {
28+
cd $et_root_dir
29+
python3 -m examples.export.export_example --model_name="softmax"
30+
local pte_file=$(readlink -f ./softmax.pte)
31+
[[ -f ${pte_file} ]] || { echo "Failed to generate a pte file - ${pte_file}"; exit 1; }
32+
echo "${pte_file}"
33+
}
34+
35+
# build ExecuTorch Libraries
36+
function build_executorch() {
37+
mkdir "${et_build_dir}"
38+
cd "${et_build_dir}"
39+
cmake \
40+
-DBUCK2=/tmp/buck2 \
41+
-DEXECUTORCH_BUILD_XNNPACK=OFF \
42+
-DFLATC_EXECUTABLE="$(which flatc)" \
43+
-DCMAKE_TOOLCHAIN_FILE="${toolchain_cmake}" \
44+
-DCMAKE_BUILD_TYPE=Release \
45+
-DEXECUTORCH_ENABLE_LOGGING_RELEASE_MODE=ON \
46+
-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \
47+
-DEXECUTORCH_BUILD_GFLAGS=OFF \
48+
-DSELECT_OPS_LIST="aten::_softmax.out" \
49+
"${et_root_dir}"
50+
51+
echo "[${FUNCNAME[0]}] Configured CMAKE"
52+
53+
n=$(nproc)
54+
cmake --build . -j"$((n - 5))"
55+
echo "[${FUNCNAME[0]}] Generated static libraries for ExecuTorch:"
56+
find . -name "*.a" -exec ls -al {} \;
57+
}
58+
59+
# build Arm Baremetal executor_runner
60+
function build_executorch_runner() {
61+
[[ $# -ne 1 ]] && { echo "[${FUNCNAME[0]}] Expecting pte file as an argument got, $@"; exit 1; }
62+
local pte=${1}
63+
cd "${ethos_u_root_dir}"/core_platform
64+
cmake \
65+
-DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} \
66+
-B build targets/corstone-300 \
67+
-DET_DIR_PATH:PATH=${et_root_dir} \
68+
-DET_BUILD_DIR_PATH:PATH=${et_build_dir} \
69+
-DET_PTE_FILE_PATH:PATH="${pte}" \
70+
-DPYTHON_EXECUTABLE=$(which python3)
71+
echo "[${FUNCNAME[0]}] Configured CMAKE"
72+
73+
n=$(nproc)
74+
cmake --build -- -j"$((n - 5))" executor_runner VERBOSE=1
75+
echo "[${FUNCNAME[0]}] Generated baremetal elf file:"
76+
find . -name "executor_runner.elf"
77+
}
78+
79+
# Execute the executor_runner on FVP Simulator
80+
function run_fvp() {
81+
cd "${ethod_u_root_dir}"
82+
elf=$(find . -name "executor_runner.elf")
83+
[[ ! -f $elf ]] && { echo "[${FUNCNAME[0]}]: Unable to find executor_runner elf: ${elf}"; exit 1; }
84+
FVP_Corstone_SSE-300_Ethos-U55 \
85+
-C ethosu.num_macs=128 \
86+
-C mps3_board.visualisation.disable-visualisation=1 \
87+
-C mps3_board.telnetterminal0.start_telnet=0 \
88+
-C mps3_board.uart0.out_file='-' \
89+
-a build/applications/*/executor_runner.elf \
90+
--timelimit 30 # seconds
91+
}
92+
93+
#######
94+
### Main
95+
#######
96+
97+
# basic checks before we get started
98+
hash ${fvp_model} \
99+
|| { echo "Could not find ${fvp_model} on PATH, ${_setup_msg}"; exit 1; }
100+
101+
hash arm-none-eabi-gcc \
102+
|| { echo "Could not find arm baremetal toolchain on PATH, ${_setup_msg}"; exit 1; }
103+
104+
[[ -f ${toolchain_cmake} ]] \
105+
|| { echo "Could not find ${toolchain_cmake} file, ${_setup_msg}"; exit 1; }
106+
107+
[[ -f ${et_root_dir}/CMakeLists.txt ]] \
108+
|| { echo "Executorch repo doesn't contain CMakeLists.txt file at root level"; exit 1; }
109+
110+
# get the pte
111+
pte=$(generate_pte_file)
112+
113+
# build et
114+
build_executorch
115+
116+
# build the et baremetal app
117+
build_executorch_runner "${pte}"
118+
119+
# run the app
120+
run_fvp
121+
122+
exit $?

0 commit comments

Comments
 (0)