Skip to content

Commit fea3684

Browse files
authored
Arm: Create script for model testing and split run.sh example script (#8460)
Create model test script and break up run.sh into smaller scripts that can be used from both places. This makes it possible to run things in run.sh in separate steps like this: 1. Build needed libs backends/arm/scripts/build_executorch.sh backends/arm/scripts/build_portable_kernels.sh --portable_kernels=<OPS> backends/arm/scripts/build_quantized_ops_aot_lib.sh 2. Build <PTE FILE> python3 -m examples.arm.aot_arm_compiler --target=ethos-u85-128 --delegate --quantize --so_library=<PATH>/libquantized_ops_aot_lib.so --model_name=<MODEL> 3. Build target executable <ELF FILE> backends/arm/scripts/build_executorch_runner.sh --pte=<PTE_FILE> --target=ethos-u55-128 4. Test target executable in FVP backends/arm/scripts/run_fvp.sh --elf=<ELF_FILE> --target=ethos-u85-128 Signed-off-by: Zingo Andersen <[email protected]>
1 parent f0ef51c commit fea3684

File tree

14 files changed

+893
-335
lines changed

14 files changed

+893
-335
lines changed

.github/workflows/trunk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ jobs:
159159
sudo sysctl fs.inotify.max_user_watches=1048576 # 1024 * 1024
160160
161161
# Test ethos-u delegate examples with run.sh
162-
backends/arm/test/test_arm_baremetal.sh test_run_ethosu_fvp
162+
backends/arm/test/test_arm_baremetal.sh test_full_ethosu_fvp
163163
164164
165165
test-arm-reference-delegation:

backends/arm/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ To run the unit test suite with Corstone3x0 FVP simulator support use
5555
backends/arm/test/test_arm_baremetal.sh test_pytest_ethosu_fvp
5656
```
5757

58-
You can test to run some models with the run.sh flow
58+
You can test to run some models with the full fvp test flow
5959

6060
```
61-
backends/arm/test/test_arm_baremetal.sh test_run_ethosu_fvp
61+
backends/arm/test/test_arm_baremetal.sh test_full_ethosu_fvp
6262
```
6363

6464
## Unit tests
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2025 Arm Limited and/or its affiliates.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Optional parameter:
8+
# --build_type= "Release" | "Debug" | "RelWithDebInfo"
9+
# --etdump build with devtools-etdump support
10+
11+
set -eu
12+
13+
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
14+
et_root_dir=$(cd ${script_dir}/../../.. && pwd)
15+
et_root_dir=$(realpath ${et_root_dir})
16+
toolchain_cmake=${script_dir}/../../../examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake
17+
toolchain_cmake=$(realpath ${toolchain_cmake})
18+
19+
20+
21+
et_build_root="${et_root_dir}/arm_test"
22+
build_type="Release"
23+
build_with_etdump=false
24+
25+
26+
help() {
27+
echo "Usage: $(basename $0) [options]"
28+
echo "Options:"
29+
echo " --et_build_root=<FOLDER> Build output root folder to use, defaults to ${et_build_root}"
30+
echo " --build_type=<TYPE> Build with Release, Debug or RelWithDebInfo, default is ${build_type}"
31+
echo " --etdump Adds Devtools etdump support to track timing, etdump area will be base64 encoded in the log"
32+
exit 0
33+
}
34+
35+
for arg in "$@"; do
36+
case $arg in
37+
-h|--help) help ;;
38+
--et_build_root=*) et_build_root="${arg#*=}";;
39+
--build_type=*) build_type="${arg#*=}";;
40+
--etdump) build_with_etdump=true ;;
41+
*)
42+
;;
43+
esac
44+
done
45+
46+
et_build_dir="${et_build_root}/cmake-out"
47+
et_build_host_dir=${et_build_root}/cmake-out-host-tools
48+
49+
set -x
50+
cd "${et_root_dir}"
51+
52+
build_with_etdump_flags=""
53+
if [ "$build_with_etdump" = true ] ; then
54+
( set +x ;
55+
echo "--------------------------------------------------------------------------------" ;
56+
echo "Build ExecuTorch Libraries host flatcc bin ${build_type} into ${et_build_host_dir} - ${et_build_host_dir}/bin/flatcc" ;
57+
echo "--------------------------------------------------------------------------------" )
58+
59+
60+
# Build host flatcc bin
61+
# This is a way to work around that the flatcc executable get build for target (e.g. Arm) later
62+
# and get replaced. flatcc is a tool used on the host for etdump and BundleIO handling.
63+
# The way to solve this is to generate it once for the host, then copy it to ${et_build_host_dir}/bin
64+
# and later point that out with -DFLATCC_EXECUTABLE=${et_build_host_dir}/bin/flatcc later.
65+
mkdir -p ${et_build_host_dir}
66+
cmake \
67+
-DCMAKE_INSTALL_PREFIX=${et_build_host_dir} \
68+
-DCMAKE_BUILD_TYPE=${build_type} \
69+
-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \
70+
-DEXECUTORCH_ENABLE_LOGGING=ON \
71+
-DEXECUTORCH_BUILD_ARM_BAREMETAL=ON \
72+
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
73+
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
74+
-DEXECUTORCH_BUILD_DEVTOOLS=ON \
75+
-DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
76+
-DEXECUTORCH_SEPARATE_FLATCC_HOST_PROJECT=ON \
77+
-DFLATCC_ALLOW_WERROR=OFF \
78+
-DFLATC_EXECUTABLE="$(which flatc)" \
79+
-B"${et_build_host_dir}" \
80+
"${et_root_dir}"
81+
82+
# Copy host flatcc excutable to it's saved when we build for target (Arm) later
83+
mkdir -p ${et_build_host_dir}/bin
84+
cp third-party/flatcc/bin/flatcc ${et_build_host_dir}/bin
85+
86+
# Add DevTools flags use in the Target build below
87+
build_with_etdump_flags="-DEXECUTORCH_BUILD_DEVTOOLS=ON \
88+
-DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
89+
-DEXECUTORCH_SEPARATE_FLATCC_HOST_PROJECT=OFF \
90+
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=OFF \
91+
-DFLATCC_ALLOW_WERROR=OFF \
92+
-DFLATCC_EXECUTABLE=${et_build_host_dir}/bin/flatcc "
93+
echo "build_with_etdump_flags=$build_with_etdump_flags"
94+
fi
95+
96+
( set +x ;
97+
echo "--------------------------------------------------------------------------------" ;
98+
echo "Build ExecuTorch target libs ${build_type} into '${et_build_dir}'" ;
99+
echo "--------------------------------------------------------------------------------" )
100+
101+
# Build
102+
cmake \
103+
-DCMAKE_INSTALL_PREFIX=${et_build_dir} \
104+
-DCMAKE_BUILD_TYPE=${build_type} \
105+
-DCMAKE_TOOLCHAIN_FILE="${toolchain_cmake}" \
106+
-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \
107+
-DEXECUTORCH_BUILD_ARM_BAREMETAL=ON \
108+
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
109+
-DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \
110+
-DEXECUTORCH_ENABLE_LOGGING=ON \
111+
${build_with_etdump_flags} \
112+
-DFLATC_EXECUTABLE="$(which flatc)" \
113+
-B"${et_build_dir}" \
114+
"${et_root_dir}"
115+
116+
echo "[$(basename $0)] Configured CMAKE"
117+
118+
cmake --build ${et_build_dir} --parallel --target install --config ${build_type} --
119+
120+
set +x
121+
122+
echo "[$(basename $0)] Generated static libraries for ExecuTorch:"
123+
find ${et_build_dir} -name "*.a" -exec ls -al {} \;
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2025 Arm Limited and/or its affiliates.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
set -eu
8+
9+
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
10+
et_root_dir=$(cd ${script_dir}/../../.. && pwd)
11+
et_root_dir=$(realpath ${et_root_dir})
12+
toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake
13+
14+
pte_file=""
15+
target="ethos-u55-128"
16+
build_type="Release"
17+
system_config=""
18+
build_with_etdump=false
19+
extra_build_flags=""
20+
output_folder_set=false
21+
output_folder="."
22+
et_build_root="${et_root_dir}/arm_test"
23+
ethosu_tools_dir=${et_root_dir}/examples/arm/ethos-u-scratch
24+
25+
help() {
26+
echo "Usage: $(basename $0) [options]"
27+
echo "Options:"
28+
echo " --pte=<PTE_FILE> pte file (genrated by the aot_arm_compier from the model to include in the elf"
29+
echo " --target=<TARGET> Target to build and run for Default: ${target}"
30+
echo " --build_type=<TYPE> Build with Release, Debug or RelWithDebInfo, default is ${build_type}"
31+
echo " --system_config=<CONFIG> System configuration to select from the Vela configuration file (see vela.ini). Default: Ethos_U55_High_End_Embedded for EthosU55 targets, Ethos_U85_SYS_DRAM_Mid for EthosU85 targets."
32+
echo " NOTE: If given, this option must match the given target. This option also sets timing adapter values customized for specific hardware, see ./executor_runner/CMakeLists.txt."
33+
echo " --etdump Adds Devtools etdump support to track timing, etdump area will be base64 encoded in the log"
34+
echo " --extra_build_flags=<FLAGS> Extra flags to pass to cmake like -DET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE=60000 Default: none "
35+
echo " --output=<FOLDER> Output folder Default: <MODEL>/<MODEL>_<TARGET INFO>.pte"
36+
echo " --et_build_root=<FOLDER> Build output root folder to use, defaults to ${et_build_root}"
37+
echo " --ethosu_tools_dir=<FOLDER> Path to your Ethos-U tools dir if you not using default: ${ethosu_tools_dir}"
38+
exit 0
39+
}
40+
41+
for arg in "$@"; do
42+
case $arg in
43+
-h|--help) help ;;
44+
--pte=*) pte_file="${arg#*=}";;
45+
--target=*) target="${arg#*=}";;
46+
--build_type=*) build_type="${arg#*=}";;
47+
--system_config=*) system_config="${arg#*=}";;
48+
--etdump) build_with_etdump=true ;;
49+
--extra_build_flags=*) extra_build_flags="${arg#*=}";;
50+
--output=*) output_folder="${arg#*=}" ; output_folder_set=true ;;
51+
--et_build_root=*) et_build_root="${arg#*=}";;
52+
--ethosu_tools_dir=*) ethosu_tools_dir="${arg#*=}";;
53+
*)
54+
;;
55+
esac
56+
done
57+
58+
pte_file=$(realpath ${pte_file})
59+
ethosu_tools_dir=$(realpath ${ethosu_tools_dir})
60+
ethos_u_root_dir="$ethosu_tools_dir/ethos-u"
61+
ethosu_tools_dir=$(realpath ${ethos_u_root_dir})
62+
63+
et_build_dir=${et_build_root}/cmake-out
64+
et_build_dir=$(realpath ${et_build_dir})
65+
66+
if [ "$output_folder_set" = false ] ; then
67+
pte_folder=$(cd -- "$( dirname -- "${pte_file}" )" &> /dev/null && pwd)
68+
pte_short_name=$(basename -- "${pte_file}" ".pte")
69+
output_folder="$pte_folder/$pte_short_name"
70+
fi
71+
72+
if [[ ${system_config} == "" ]]
73+
then
74+
system_config="Ethos_U55_High_End_Embedded"
75+
if [[ ${target} =~ "ethos-u85" ]]
76+
then
77+
system_config="Ethos_U85_SYS_DRAM_Mid"
78+
fi
79+
fi
80+
81+
output_folder=$(realpath ${output_folder})
82+
83+
if [[ ${target} == *"ethos-u55"* ]]; then
84+
target_cpu=cortex-m55
85+
else
86+
target_cpu=cortex-m85
87+
fi
88+
echo "--------------------------------------------------------------------------------"
89+
echo "Build Arm Baremetal executor_runner for ${target} with ${pte_file} using ${system_config} to '${output_folder}/cmake-out'"
90+
echo "--------------------------------------------------------------------------------"
91+
92+
cd ${et_root_dir}/examples/arm/executor_runner
93+
94+
build_with_etdump_flags=""
95+
if [ "$build_with_etdump" = true ] ; then
96+
echo "Building with etdump e.g. -DEXECUTORCH_ENABLE_EVENT_TRACER=ON"
97+
build_with_etdump_flags=" -DEXECUTORCH_ENABLE_EVENT_TRACER=ON "
98+
fi
99+
100+
mkdir -p "$output_folder"
101+
102+
cmake \
103+
-DCMAKE_BUILD_TYPE=${build_type} \
104+
-DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} \
105+
-DTARGET_CPU=${target_cpu} \
106+
-DET_DIR_PATH:PATH=${et_root_dir} \
107+
-DET_BUILD_DIR_PATH:PATH=${et_build_dir} \
108+
-DET_PTE_FILE_PATH:PATH="${pte_file}" \
109+
-DETHOS_SDK_PATH:PATH=${ethos_u_root_dir} \
110+
-DETHOSU_TARGET_NPU_CONFIG=${target} \
111+
${build_with_etdump_flags} \
112+
-DPYTHON_EXECUTABLE=$(which python3) \
113+
-DSYSTEM_CONFIG=${system_config} \
114+
${extra_build_flags} \
115+
-B ${output_folder}/cmake-out
116+
117+
echo "[${BASH_SOURCE[0]}] Configured CMAKE"
118+
119+
cmake --build ${output_folder}/cmake-out --parallel -- arm_executor_runner
120+
121+
echo "[${BASH_SOURCE[0]}] Generated baremetal elf file:"
122+
find ${output_folder}/cmake-out -name "arm_executor_runner"
123+
echo "executable_text: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $1}') bytes"
124+
echo "executable_data: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $2}') bytes"
125+
echo "executable_bss: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $3}') bytes"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2025 Arm Limited and/or its affiliates.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Optional parameter:
8+
# --build_type= "Release" | "Debug" | "RelWithDebInfo"
9+
# --etdump build with devtools-etdump support
10+
11+
set -eu
12+
13+
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
14+
et_root_dir=$(cd ${script_dir}/../../.. && pwd)
15+
et_root_dir=$(realpath ${et_root_dir})
16+
toolchain_cmake=${script_dir}/../../../examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake
17+
toolchain_cmake=$(realpath ${toolchain_cmake})
18+
19+
20+
et_build_root="${et_root_dir}/arm_test"
21+
build_type="Release"
22+
portable_kernels="aten::_softmax.out"
23+
24+
help() {
25+
echo "Usage: $(basename $0) [options]"
26+
echo "Options:"
27+
echo " --et_build_root=<FOLDER> Build output root folder to use, defaults to ${et_build_root}"
28+
echo " --build_type=<TYPE> Build with Release, Debug or RelWithDebInfo, default is ${build_type}"
29+
echo " --portable_kernels=<OPS> Comma separated list of portable (non delagated) kernels to include Default: ${portable_kernels}"
30+
exit 0
31+
}
32+
33+
for arg in "$@"; do
34+
case $arg in
35+
-h|--help) help ;;
36+
--et_build_root=*) et_build_root="${arg#*=}";;
37+
--build_type=*) build_type="${arg#*=}";;
38+
--portable_kernels=*) portable_kernels="${arg#*=}";;
39+
*)
40+
;;
41+
esac
42+
done
43+
44+
et_build_dir=${et_build_root}/cmake-out
45+
46+
cd "${et_root_dir}"
47+
48+
echo "--------------------------------------------------------------------------------" ;
49+
echo "Build ExecuTorch Libraries ${build_type} portable kernels: ${portable_kernels} into '${et_build_dir}'" ;
50+
echo "--------------------------------------------------------------------------------"
51+
52+
if ! [[ $portable_kernels =~ ^((^|,)aten::[a-zA-Z0-9_]+\.[a-zA-Z0-9_]*out)*$ ]]; then
53+
echo " ERROR: specified argument --portable_kernels=${portable_kernels}"
54+
echo " is in the wrong format please use \"aten::<OP1>.out,aten::<OP2>.out,...\""
55+
echo " e.g. \"aten::_softmax.out,aten::add.out\""
56+
exit 1
57+
fi
58+
59+
set -x
60+
61+
cmake \
62+
-DCMAKE_INSTALL_PREFIX=${et_build_dir} \
63+
-DCMAKE_BUILD_TYPE=${build_type} \
64+
-DCMAKE_TOOLCHAIN_FILE="${toolchain_cmake}" \
65+
-DEXECUTORCH_SELECT_OPS_LIST=${portable_kernels} \
66+
-B"${et_build_dir}/examples/arm" \
67+
"${et_root_dir}/examples/arm"
68+
69+
cmake --build "${et_build_dir}/examples/arm" --parallel --config ${build_type} --
70+
71+
set +x
72+
73+
echo "[$(basename $0)] Generated static libraries for ExecuTorch:"
74+
find "${et_build_dir}/examples/arm" -name "*.a" -exec ls -al {} \;

0 commit comments

Comments
 (0)