Skip to content

Commit 2871fcf

Browse files
authored
Plumbing for Arm Example Runnner to use Zephyr Toolchain (#12078)
### Summary Once `setup.sh` and `PATH` have been set to point to Arm Zephyr toolchain, the `run.sh` script and its child processes must use the specified toolchain. This change adds the plumbing needed to support this. This change **does not** include the Zephyr binary in the `arm_executor_runner`, but merely uses allows the runner to be built with a different toolchain. ### Test plan Environment setup: ``` ./examples/arm/setup.sh --i-agree-to-the-contained-eula --target-toolchain zephyr source /home/zephyruser/executorch/examples/arm/ethos-u-scratch/setup_path.sh ``` The following can be run to produce the same results as in the [Arm Ethos-U tutorial](https://docs.pytorch.org/executorch/main/tutorial-arm-ethos-u.html), now utilizing the Arm Zephyr toolchain instead of the bare metal: ``` examples/arm/run.sh --toolchain=arm-zephyr-eabi-gcc --model_name=add --no_quantize --target=ethos-u55-128 ``` Which still produces the following output: ``` I [executorch:arm_executor_runner.cpp:747 main()] Model executed successfully. I [executorch:arm_executor_runner.cpp:751 main()] 1 outputs: Output[0][0]: (int) 2 Output[0][1]: (int) 2 Output[0][2]: (int) 2 Output[0][3]: (int) 2 Output[0][4]: (int) 2 I [executorch:arm_executor_runner.cpp:874 main()] Program complete, exiting. I [executorch:arm_executor_runner.cpp:878 main()] ♦ Info: /OSCI/SystemC: Simulation stopped by user. [warning ][main@0][3440 ns] Simulation stopped by user [backends/arm/scripts/run_fvp.sh] Simulation complete, 0 Checking for problems in log: No problems found! + set +x ```
1 parent d533a87 commit 2871fcf

File tree

4 files changed

+64
-17
lines changed

4 files changed

+64
-17
lines changed

backends/arm/scripts/build_executor_runner.sh

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set -eu
99
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
1010
et_root_dir=$(cd ${script_dir}/../../.. && pwd)
1111
et_root_dir=$(realpath ${et_root_dir})
12-
toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake
12+
toolchain=arm-none-eabi-gcc
1313
setup_path_script=${et_root_dir}/examples/arm/ethos-u-scratch/setup_path.sh
1414
_setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly install necessary tools."
1515

@@ -46,6 +46,7 @@ help() {
4646
echo " --output=<FOLDER> Output folder Default: <MODEL>/<MODEL>_<TARGET INFO>.pte"
4747
echo " --et_build_root=<FOLDER> Build output root folder to use, defaults to ${et_build_root}"
4848
echo " --ethosu_tools_dir=<FOLDER> Path to your Ethos-U tools dir if you not using default: ${ethosu_tools_dir}"
49+
echo " --toolchain=<TOOLCHAIN> Toolchain can be specified (e.g. bare metal as arm-none-eabi-gcc or zephyr as arm-zephyr-eabi-gcc"
4950
exit 0
5051
}
5152

@@ -63,11 +64,23 @@ for arg in "$@"; do
6364
--output=*) output_folder="${arg#*=}" ; output_folder_set=true ;;
6465
--et_build_root=*) et_build_root="${arg#*=}";;
6566
--ethosu_tools_dir=*) ethosu_tools_dir="${arg#*=}";;
67+
--toolchain=*) toolchain="${arg#*=}";;
6668
*)
6769
;;
6870
esac
6971
done
7072

73+
if [[ ${toolchain} == "arm-none-eabi-gcc" ]]; then
74+
toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/${toolchain}.cmake
75+
elif [[ ${toolchain} == "arm-zephyr-eabi-gcc" ]]; then
76+
toolchain_cmake=${et_root_dir}/examples/zephyr/x86_64-linux-arm-zephyr-eabi-gcc.cmake
77+
else
78+
echo "Error: Invalid toolchain selection, provided: ${tolchain}"
79+
echo " Valid options are {arm-none-eabi-gcc, arm-zephyr-eabi-gcc}"
80+
exit 1;
81+
fi
82+
toolchain_cmake=$(realpath ${toolchain_cmake})
83+
7184
# Source the tools
7285
# This should be prepared by the setup.sh
7386
[[ -f ${setup_path_script} ]] \
@@ -116,7 +129,7 @@ else
116129
target_cpu=cortex-m85
117130
fi
118131
echo "--------------------------------------------------------------------------------"
119-
echo "Build Arm Baremetal executor_runner for ${target} with ${pte_file} using ${system_config} ${memory_mode} ${extra_build_flags} to '${output_folder}/cmake-out'"
132+
echo "Build Arm ${toolchain/-gcc/} executor_runner for ${target} with ${pte_file} using ${system_config} ${memory_mode} ${extra_build_flags} to '${output_folder}/cmake-out'"
120133
echo "--------------------------------------------------------------------------------"
121134

122135
cd ${et_root_dir}/examples/arm/executor_runner
@@ -130,7 +143,6 @@ if [ "$build_with_etdump" = true ] ; then
130143
fi
131144

132145
echo "Building with BundleIO/etdump/extra flags: ${build_bundleio_flags} ${build_with_etdump_flags} ${extra_build_flags}"
133-
134146
cmake \
135147
-DCMAKE_BUILD_TYPE=${build_type} \
136148
-DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} \
@@ -152,8 +164,8 @@ echo "[${BASH_SOURCE[0]}] Configured CMAKE"
152164

153165
cmake --build ${output_folder}/cmake-out -j$(nproc) -- arm_executor_runner
154166

155-
echo "[${BASH_SOURCE[0]}] Generated baremetal elf file:"
167+
echo "[${BASH_SOURCE[0]}] Generated ${toolchain} elf file:"
156168
find ${output_folder}/cmake-out -name "arm_executor_runner"
157-
echo "executable_text: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $1}') bytes"
158-
echo "executable_data: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $2}') bytes"
159-
echo "executable_bss: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $3}') bytes"
169+
echo "executable_text: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec ${toolchain/-gcc/-size} {} \; | grep -v filename | awk '{print $1}') bytes"
170+
echo "executable_data: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec ${toolchain/-gcc/-size} {} \; | grep -v filename | awk '{print $2}') bytes"
171+
echo "executable_bss: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec ${toolchain/-gcc/-size} {} \; | grep -v filename | awk '{print $3}') bytes"

backends/arm/scripts/build_executorch.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ set -eu
1313
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
1414
et_root_dir=$(cd ${script_dir}/../../.. && pwd)
1515
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})
16+
toolchain=arm-none-eabi-gcc
1817
setup_path_script=${et_root_dir}/examples/arm/ethos-u-scratch/setup_path.sh
1918
_setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly install necessary tools."
2019

@@ -30,6 +29,7 @@ help() {
3029
echo " --build_type=<TYPE> Build with Release, Debug or RelWithDebInfo, default is ${build_type}"
3130
echo " --devtools Build Devtools libs"
3231
echo " --etdump Adds Devtools etdump support to track timing, etdump area will be base64 encoded in the log"
32+
echo " --toolchain=<TOOLCHAIN> Toolchain can be specified (e.g. bare metal as arm-none-eabi-gcc or zephyr as arm-zephyr-eabi-gcc"
3333
exit 0
3434
}
3535

@@ -40,11 +40,23 @@ for arg in "$@"; do
4040
--build_type=*) build_type="${arg#*=}";;
4141
--devtools) build_devtools=true ;;
4242
--etdump) build_with_etdump=true ;;
43+
--toolchain=*) toolchain="${arg#*=}";;
4344
*)
4445
;;
4546
esac
4647
done
4748

49+
if [[ ${toolchain} == "arm-none-eabi-gcc" ]]; then
50+
toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/${toolchain}.cmake
51+
elif [[ ${toolchain} == "arm-zephyr-eabi-gcc" ]]; then
52+
toolchain_cmake=${et_root_dir}/examples/zephyr/x86_64-linux-arm-zephyr-eabi-gcc.cmake
53+
else
54+
echo "Error: Invalid toolchain selection, provided: ${tolchain}"
55+
echo " Valid options are {arm-none-eabi-gcc, arm-zephyr-eabi-gcc}"
56+
exit 1;
57+
fi
58+
toolchain_cmake=$(realpath ${toolchain_cmake})
59+
4860
# Source the tools
4961
# This should be prepared by the setup.sh
5062
[[ -f ${setup_path_script} ]] \

backends/arm/scripts/build_portable_kernels.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ set -eu
1313
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
1414
et_root_dir=$(cd ${script_dir}/../../.. && pwd)
1515
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})
16+
toolchain=arm-none-eabi-gcc
1817
setup_path_script=${et_root_dir}/examples/arm/ethos-u-scratch/setup_path.sh
1918
_setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly install necessary tools."
2019

@@ -29,6 +28,7 @@ help() {
2928
echo " --et_build_root=<FOLDER> Build output root folder to use, defaults to ${et_build_root}"
3029
echo " --build_type=<TYPE> Build with Release, Debug or RelWithDebInfo, default is ${build_type}"
3130
echo " --portable_kernels=<OPS> Comma separated list of portable (non delagated) kernels to include Default: ${portable_kernels}"
31+
echo " --toolchain=<TOOLCHAIN> Toolchain can be specified (e.g. bare metal as arm-none-eabi-gcc or zephyr as arm-zephyr-eabi-gcc"
3232
exit 0
3333
}
3434

@@ -38,11 +38,23 @@ for arg in "$@"; do
3838
--et_build_root=*) et_build_root="${arg#*=}";;
3939
--build_type=*) build_type="${arg#*=}";;
4040
--portable_kernels=*) portable_kernels="${arg#*=}";;
41+
--toolchain=*) toolchain="${arg#*=}";;
4142
*)
4243
;;
4344
esac
4445
done
4546

47+
if [[ ${toolchain} == "arm-none-eabi-gcc" ]]; then
48+
toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/${toolchain}.cmake
49+
elif [[ ${toolchain} == "arm-zephyr-eabi-gcc" ]]; then
50+
toolchain_cmake=${et_root_dir}/examples/zephyr/x86_64-linux-arm-zephyr-eabi-gcc.cmake
51+
else
52+
echo "Error: Invalid toolchain selection, provided: ${tolchain}"
53+
echo " Valid options are {arm-none-eabi-gcc, arm-zephyr-eabi-gcc}"
54+
exit 1;
55+
fi
56+
toolchain_cmake=$(realpath ${toolchain_cmake})
57+
4658
# Source the tools
4759
# This should be prepared by the setup.sh
4860
[[ -f ${setup_path_script} ]] \

examples/arm/run.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ memory_mode=""
3838
et_build_root="${et_root_dir}/arm_test"
3939
ethos_u_scratch_dir=${script_dir}/ethos-u-scratch
4040
scratch_dir_set=false
41+
toolchain=arm-none-eabi-gcc
4142

4243
function help() {
4344
echo "Usage: $(basename $0) [options]"
@@ -75,6 +76,7 @@ for arg in "$@"; do
7576
--no_quantize) aot_arm_compiler_flag_quantize="" ;;
7677
--portable_kernels=*) portable_kernels="${arg#*=}";;
7778
--target=*) target="${arg#*=}";;
79+
--toolchain=*) toolchain="${arg#*=}";;
7880
--output=*) output_folder="${arg#*=}" ; output_folder_set=true ;;
7981
--bundleio) bundleio=true ;;
8082
--etdump) build_with_etdump=true ;;
@@ -94,7 +96,16 @@ done
9496
# Default Ethos-u tool folder override with --scratch-dir=<FOLDER>
9597
ethos_u_scratch_dir=$(realpath ${ethos_u_scratch_dir})
9698
setup_path_script=${ethos_u_scratch_dir}/setup_path.sh
97-
toolchain_cmake=${script_dir}/ethos-u-setup/arm-none-eabi-gcc.cmake
99+
if [[ ${toolchain} == "arm-none-eabi-gcc" ]]; then
100+
toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/${toolchain}.cmake
101+
elif [[ ${toolchain} == "arm-zephyr-eabi-gcc" ]]; then
102+
toolchain_cmake=${et_root_dir}/examples/zephyr/x86_64-linux-arm-zephyr-eabi-gcc.cmake
103+
else
104+
echo "Error: Invalid toolchain selection, provided: ${tolchain}"
105+
echo " Valid options are {arm-none-eabi-gcc, arm-zephyr-eabi-gcc}"
106+
exit 1;
107+
fi
108+
toolchain_cmake=$(realpath ${toolchain_cmake})
98109
_setup_msg="please refer to ${script_dir}/setup.sh to properly install necessary tools."
99110

100111

@@ -134,8 +145,8 @@ function check_setup () {
134145
fi
135146

136147
# If setup_path_script was correct all these checks should now pass
137-
hash arm-none-eabi-gcc \
138-
|| { echo "Could not find arm baremetal toolchain on PATH, ${_setup_msg}"; return 1; }
148+
hash ${toolchain} \
149+
|| { echo "Could not find ${toolchain} toolchain on PATH, ${_setup_msg}"; return 1; }
139150

140151
[[ -f ${toolchain_cmake} ]] \
141152
|| { echo "Could not find ${toolchain_cmake} file, ${_setup_msg}"; return 1; }
@@ -180,8 +191,8 @@ if [ "$bundleio" = true ] ; then
180191
et_dump_flag="--etdump"
181192
fi
182193

183-
backends/arm/scripts/build_executorch.sh --et_build_root="${et_build_root}" --build_type=$build_type $devtools_flag
184-
backends/arm/scripts/build_portable_kernels.sh --et_build_root="${et_build_root}" --build_type=$build_type --portable_kernels=$portable_kernels
194+
backends/arm/scripts/build_executorch.sh --et_build_root="${et_build_root}" --build_type=$build_type $devtools_flag --toolchain="${toolchain}"
195+
backends/arm/scripts/build_portable_kernels.sh --et_build_root="${et_build_root}" --build_type=$build_type --portable_kernels=$portable_kernels --toolchain="${toolchain}"
185196

186197
if [[ -z "$model_name" ]]; then
187198
# the test models run, and whether to delegate
@@ -265,7 +276,7 @@ for i in "${!test_model[@]}"; do
265276
else
266277
set -x
267278
# Rebuild the application as the pte is imported as a header/c array
268-
backends/arm/scripts/build_executor_runner.sh --et_build_root="${et_build_root}" --pte="${pte_file}" --build_type=${build_type} --target=${target} --system_config=${system_config} --memory_mode=${memory_mode} ${bundleio_flag} ${et_dump_flag} --extra_build_flags="${extra_build_flags}" --ethosu_tools_dir="${ethos_u_scratch_dir}"
279+
backends/arm/scripts/build_executor_runner.sh --et_build_root="${et_build_root}" --pte="${pte_file}" --build_type=${build_type} --target=${target} --system_config=${system_config} --memory_mode=${memory_mode} ${bundleio_flag} ${et_dump_flag} --extra_build_flags="${extra_build_flags}" --ethosu_tools_dir="${ethos_u_scratch_dir}" --toolchain="${toolchain}"
269280
if [ "$build_only" = false ] ; then
270281
# Execute the executor_runner on FVP Simulator
271282
elf_file="${output_folder}/${elf_folder}/cmake-out/arm_executor_runner"

0 commit comments

Comments
 (0)