Skip to content

Commit ee1ef03

Browse files
authored
Arm backend: Enable building and running with the pte on an address (#13761)
### Summary This makes it possible to put the pte separated from the elf file/code in its own area in the memory/flash. ### Test plan Tests are added in this patch Signed-off-by: Zingo Andersen <[email protected]>
1 parent 473df33 commit ee1ef03

File tree

6 files changed

+229
-67
lines changed

6 files changed

+229
-67
lines changed

backends/arm/scripts/build_executor_runner.sh

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,26 @@ build_with_etdump_flags=" -DEXECUTORCH_ENABLE_EVENT_TRACER=OFF "
3333
help() {
3434
echo "Usage: $(basename $0) [options]"
3535
echo "Options:"
36-
echo " --pte=<PTE_FILE>|semihosting pte file (generated by the aot_arm_compier from the model to include in the elf), or semihosting to supply pte at runtime."
37-
echo " --target=<TARGET> Target to build and run for Default: ${target}"
38-
echo " --build_type=<TYPE> Build with Release, Debug or RelWithDebInfo, default is ${build_type}"
39-
echo " --bundleio Support both pte and Bundle IO bpte using Devtools BundelIO with Input/RefOutput included"
40-
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."
41-
echo " NOTE: If given, this option must match the given target. This option along with the memory_mode sets timing adapter values customized for specific hardware, see ./executor_runner/CMakeLists.txt."
42-
echo " --memory_mode=<CONFIG> Vela memory mode, used for setting the Timing Adapter parameters of the Corstone platforms."
43-
echo " Valid values are Shared_Sram(for Ethos-U55, Ethos-U65, Ethos-85), Sram_Only(for Ethos-U55, Ethos-U65, Ethos-U85) or Dedicated_Sram(for Ethos-U65, Ethos-U85)."
44-
echo " Default: Shared_Sram for the Ethos-U55 and Sram_Only for the Ethos-U85"
45-
echo " --etdump Adds Devtools etdump support to track timing, etdump area will be base64 encoded in the log"
46-
echo " --extra_build_flags=<FLAGS> Extra flags to pass to cmake like -DET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE=60000 Default: none "
47-
echo " --output=<FOLDER> Output folder Default: <MODEL>/<MODEL>_<TARGET INFO>.pte"
48-
echo " --et_build_root=<FOLDER> Build output root folder to use, defaults to ${et_build_root}"
49-
echo " --ethosu_tools_dir=<FOLDER> Path to your Ethos-U tools dir if you not using default: ${ethosu_tools_dir}"
50-
echo " --toolchain=<TOOLCHAIN> Toolchain can be specified (e.g. bare metal as arm-none-eabi-gcc or zephyr as arm-zephyr-eabi-gcc Default: ${toolchain}"
51-
echo " --select_ops_list=<OPS> Comma separated list of portable (non delagated) kernels to include Default: ${select_ops_list}"
52-
echo " NOTE: This is used when select_ops_model is not possible to use, e.g. for semihosting or bundleio."
53-
echo " See https://docs.pytorch.org/executorch/stable/kernel-library-selective-build.html for more information."
36+
echo " --pte=<PTE_FILE>|<ADDR>|semihosting Set to a pte file (generated by the aot_arm_compier) to include the model in the elf."
37+
echo " Or a hex address in the format of 0x00000000 if placed in memory you need to place it on this ADDR on your target, with your flash tool or other means."
38+
echo " Or specify the word 'semihosting' to supply pte at runtime."
39+
echo " --target=<TARGET> Target to build and run for Default: ${target}"
40+
echo " --build_type=<TYPE> Build with Release, Debug or RelWithDebInfo, default is ${build_type}"
41+
echo " --bundleio Support both pte and Bundle IO bpte using Devtools BundelIO with Input/RefOutput included"
42+
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."
43+
echo " NOTE: If given, this option must match the given target. This option along with the memory_mode sets timing adapter values customized for specific hardware, see ./executor_runner/CMakeLists.txt."
44+
echo " --memory_mode=<CONFIG> Vela memory mode, used for setting the Timing Adapter parameters of the Corstone platforms."
45+
echo " Valid values are Shared_Sram(for Ethos-U55, Ethos-U65, Ethos-85), Sram_Only(for Ethos-U55, Ethos-U65, Ethos-U85) or Dedicated_Sram(for Ethos-U65, Ethos-U85)."
46+
echo " Default: Shared_Sram for the Ethos-U55 and Sram_Only for the Ethos-U85"
47+
echo " --etdump Adds Devtools etdump support to track timing, etdump area will be base64 encoded in the log"
48+
echo " --extra_build_flags=<FLAGS> Extra flags to pass to cmake like -DET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE=60000 Default: none "
49+
echo " --output=<FOLDER> Output folder Default: <MODEL>/<MODEL>_<TARGET INFO>.pte"
50+
echo " --et_build_root=<FOLDER> Build output root folder to use, defaults to ${et_build_root}"
51+
echo " --ethosu_tools_dir=<FOLDER> Path to your Ethos-U tools dir if you not using default: ${ethosu_tools_dir}"
52+
echo " --toolchain=<TOOLCHAIN> Toolchain can be specified (e.g. bare metal as arm-none-eabi-gcc or zephyr as arm-zephyr-eabi-gcc Default: ${toolchain}"
53+
echo " --select_ops_list=<OPS> Comma separated list of portable (non delagated) kernels to include Default: ${select_ops_list}"
54+
echo " NOTE: This is used when select_ops_model is not possible to use, e.g. for semihosting or bundleio."
55+
echo " See https://docs.pytorch.org/executorch/stable/kernel-library-selective-build.html for more information."
5456
exit 0
5557
}
5658

@@ -94,10 +96,24 @@ toolchain_cmake=$(realpath ${toolchain_cmake})
9496
source ${setup_path_script}
9597

9698
if [[ ${pte_file} == "semihosting" ]]; then
97-
extra_build_flags="${extra_build_flags} -DSEMIHOSTING=ON"
99+
pte_data="-DSEMIHOSTING=ON"
98100
else
99-
pte_file=$(realpath ${pte_file})
100-
extra_build_flags="${extra_build_flags} -DET_PTE_FILE_PATH:PATH='${pte_file}'"
101+
if [[ "$pte_file" =~ ^0x[0-9a-fA-F]{1,16}$ ]]; then
102+
echo "PTE in memory at ${pte_file}, make sure to put it there on your target before starting."
103+
pte_data="-DET_MODEL_PTE_ADDR=${pte_file}"
104+
if [ "$output_folder_set" = false ] ; then
105+
# Not locked down to a PTE use
106+
output_folder=${et_build_root}/${target}_${pte_file}/cmake-out
107+
fi
108+
else
109+
echo "PTE included in elf from file ${pte_file}"
110+
pte_file=$(realpath ${pte_file})
111+
pte_data="-DET_PTE_FILE_PATH:PATH=${pte_file}"
112+
if [ "$output_folder_set" = false ] ; then
113+
# remove file ending
114+
output_folder=${pte_file%.*}/cmake-out
115+
fi
116+
fi
101117
fi
102118
ethosu_tools_dir=$(realpath ${ethosu_tools_dir})
103119
ethos_u_root_dir="$ethosu_tools_dir/ethos-u"
@@ -108,11 +124,6 @@ et_build_dir=${et_build_root}/cmake-out
108124
mkdir -p ${et_build_dir}
109125
et_build_dir=$(realpath ${et_build_dir})
110126

111-
if [ "$output_folder_set" = false ] ; then
112-
# remove file ending
113-
output_folder=${pte_file%.*}/cmake-out
114-
fi
115-
116127
if [[ ${system_config} == "" ]]
117128
then
118129
system_config="Ethos_U55_High_End_Embedded"
@@ -140,7 +151,7 @@ else
140151
target_cpu=cortex-m85
141152
fi
142153
echo "--------------------------------------------------------------------------------"
143-
echo "Build Arm ${toolchain/-gcc/} executor_runner for ${target} with ${pte_file} using ${system_config} ${memory_mode} ${extra_build_flags} to '${output_folder}'"
154+
echo "Build Arm ${toolchain/-gcc/} executor_runner for ${target} PTE: ${pte_file} using ${system_config} ${memory_mode} ${extra_build_flags} to '${output_folder}'"
144155
echo "--------------------------------------------------------------------------------"
145156

146157
cd ${et_root_dir}/examples/arm/executor_runner
@@ -162,6 +173,7 @@ cmake \
162173
-DET_BUILD_DIR_PATH:PATH=${et_build_dir} \
163174
-DETHOS_SDK_PATH:PATH=${ethos_u_root_dir} \
164175
-DETHOSU_TARGET_NPU_CONFIG=${target} \
176+
${pte_data} \
165177
${build_bundleio_flags} \
166178
${build_with_etdump_flags} \
167179
-DPYTHON_EXECUTABLE=$(which python3) \

backends/arm/scripts/run_fvp.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ _setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly ins
1818

1919

2020
elf_file=""
21+
data_file=""
2122
target="ethos-u55-128"
2223
timeout="600"
2324

2425
help() {
2526
echo "Usage: $(basename $0) [options]"
2627
echo "Options:"
2728
echo " --elf=<ELF_FILE> elf file to run"
29+
echo " --data=<FILE>@<ADDRESS> Place a file in memory at this address, useful to emulate a PTE flashed into memory instead as part of the code."
2830
echo " --target=<TARGET> Target to build and run for Default: ${target}"
2931
echo " --timeout=<TIME_IN_SEC> Maximum target runtime, used to detect hanging, might need to be higer on large models Default: ${timeout}"
3032
exit 0
@@ -34,6 +36,7 @@ for arg in "$@"; do
3436
case $arg in
3537
-h|--help) help ;;
3638
--elf=*) elf_file="${arg#*=}";;
39+
--data=*) data_file="--data ${arg#*=}";;
3740
--target=*) target="${arg#*=}";;
3841
--timeout=*) timeout="${arg#*=}";;
3942
*)
@@ -80,27 +83,27 @@ fi
8083

8184
log_file=$(mktemp)
8285

83-
84-
8586
if [[ ${target} == *"ethos-u55"* ]]; then
86-
${nobuf} ${fvp_model} \
87+
${nobuf} ${fvp_model} \
8788
-C ethosu.num_macs=${num_macs} \
8889
-C mps3_board.visualisation.disable-visualisation=1 \
8990
-C mps3_board.telnetterminal0.start_telnet=0 \
9091
-C mps3_board.uart0.out_file='-' \
9192
-C mps3_board.uart0.shutdown_on_eot=1 \
92-
-a "${elf_file}" \
93+
-a "${elf_file}" \
94+
${data_file} \
9395
--timelimit ${timeout} 2>&1 | tee ${log_file} || true # seconds
9496
echo "[${BASH_SOURCE[0]}] Simulation complete, $?"
9597
elif [[ ${target} == *"ethos-u85"* ]]; then
96-
${nobuf} ${fvp_model} \
98+
${nobuf} ${fvp_model} \
9799
-C mps4_board.subsystem.ethosu.num_macs=${num_macs} \
98100
-C mps4_board.visualisation.disable-visualisation=1 \
99101
-C vis_hdlcd.disable_visualisation=1 \
100102
-C mps4_board.telnetterminal0.start_telnet=0 \
101103
-C mps4_board.uart0.out_file='-' \
102104
-C mps4_board.uart0.shutdown_on_eot=1 \
103-
-a "${elf_file}" \
105+
-a "${elf_file}" \
106+
${data_file} \
104107
--timelimit ${timeout} 2>&1 | tee ${log_file} || true # seconds
105108
echo "[${BASH_SOURCE[0]}] Simulation complete, $?"
106109
else

backends/arm/test/test_arm_baremetal.sh

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,30 +155,44 @@ test_run_ethosu_fvp() { # End to End model tests using run.sh
155155
echo "${TEST_SUITE_NAME}: Test ethos-u delegate examples with run.sh"
156156

157157
# TOSA quantized
158-
echo "${TEST_SUITE_NAME}: Test ethos-u target TOSA"
158+
echo "${TEST_SUITE_NAME}: Test target TOSA"
159159
examples/arm/run.sh --et_build_root=arm_test/test_run --target=TOSA-1.0+INT --model_name=add
160160
examples/arm/run.sh --et_build_root=arm_test/test_run --target=TOSA-1.0+INT --model_name=mul
161161

162162
# Ethos-U55
163-
echo "${TEST_SUITE_NAME}: Test ethos-u target Ethos-U55"
164-
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=add
163+
echo "${TEST_SUITE_NAME}: Test target Ethos-U55"
164+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-64 --model_name=add
165165
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=add --bundleio
166-
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=add --bundleio --etdump
166+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-256 --model_name=add --bundleio --etdump
167167
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=add --etdump
168168
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=mul
169+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=add --pte_placement=elf
170+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-256 --model_name=add --pte_placement=0x38000000
171+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=mul --bundleio --pte_placement=elf
172+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=mul --bundleio --pte_placement=0x38000000
173+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=add --bundleio --pte_placement=0x38000000
174+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=examples/arm/example_modules/add.py
175+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=examples/arm/example_modules/add.py --bundleio
169176

170177
# Ethos-U85
171-
echo "${TEST_SUITE_NAME}: Test ethos-u target Ethos-U85"
178+
echo "${TEST_SUITE_NAME}: Test target Ethos-U85"
172179
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-128 --model_name=add
173-
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-128 --model_name=add --bundleio
174-
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-128 --model_name=add --bundleio --etdump
175-
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-128 --model_name=add --etdump
176-
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-128 --model_name=mul
180+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-256 --model_name=add --bundleio
181+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-512 --model_name=add --bundleio --etdump
182+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-1024 --model_name=add --etdump
183+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-2048 --model_name=mul --pte_placement=elf
184+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-128 --model_name=mul --pte_placement=0x38000000
185+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-128 --model_name=mul --bundleio --pte_placement=elf
186+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-256 --model_name=mul --bundleio --pte_placement=0x38000000
187+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-128 --model_name=examples/arm/example_modules/add.py
188+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-1024 --model_name=examples/arm/example_modules/add.py --bundleio
177189

178190
# Cortex-M op tests
191+
echo "${TEST_SUITE_NAME}: Test target Cortex-M55 (on a Ethos-U)"
192+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=add --bundleio --no_delegate --select_ops_list="aten::add.out"
179193
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=qadd --bundleio
180194
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=qops --bundleio
181-
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=qops --bundleio --no_delegate --portable_kernels="aten::sub.out,aten::add.out,aten::mul.out"
195+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=qops --bundleio --no_delegate --select_ops_list="aten::sub.out,aten::add.out,aten::mul.out"
182196
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-128 --model_name=qops --bundleio
183197

184198
echo "${TEST_SUITE_NAME}: PASS"

examples/arm/executor_runner/CMakeLists.txt

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ option(
1212
"Set ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE to specify memory alloction pool size"
1313
OFF
1414
)
15+
option(
16+
ET_MODEL_PTE_ADDR
17+
"Place in memory that the PTE file is located/flashed, if set to OFF the PTE is built into the code as a big data area."
18+
OFF
19+
)
1520
option(ET_BUNDLE_IO "Set to compile in BundleIO support" OFF)
1621
option(ET_ATOL "Set atol to use for BundleIO testing" OFF)
1722
option(ET_RTOL "Set rtol to use for BundleIO testing" OFF)
@@ -25,11 +30,16 @@ set(ET_NUM_INFERENCES
2530
CACHE STRING "Number of inferences to run"
2631
)
2732

28-
if(NOT DEFINED ET_PTE_FILE_PATH AND NOT ${SEMIHOSTING})
33+
if(NOT DEFINED ET_MODEL_PTE_ADDR
34+
AND NOT DEFINED ET_PTE_FILE_PATH
35+
AND NOT DEFINED SEMIHOSTING
36+
)
2937
message(
3038
FATAL_ERROR
31-
"ET_PTE_FILE_PATH must specify a model .pte or .bpte, for bare metal systems the "
32-
"model is built into the binary."
39+
"You must specify one of "
40+
"ET_MODEL_PTE_ADDR - .pte (or .bpte) on address, "
41+
"ET_PTE_FILE_PATH - .pte (or .bpte) built into the binary or "
42+
"SEMIHOSTING - pte and input via host filesystem (use by pytest)"
3343
)
3444
endif()
3545

@@ -113,7 +123,7 @@ find_package(
113123
)
114124

115125
# Convert pte to header
116-
if(NOT ${SEMIHOSTING})
126+
if(NOT ${ET_MODEL_PTE_ADDR} AND NOT SEMIHOSTING)
117127
add_custom_target(
118128
gen_model_header DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/model_pte.h
119129
)
@@ -308,10 +318,12 @@ target_compile_definitions(
308318
arm_executor_runner PRIVATE C10_USING_CUSTOM_GENERATED_MACROS
309319
)
310320

321+
if(NOT ${ET_MODEL_PTE_ADDR} AND NOT SEMIHOSTING)
322+
add_dependencies(arm_executor_runner gen_model_header)
323+
endif()
324+
311325
if(SEMIHOSTING)
312326
target_compile_definitions(arm_executor_runner PUBLIC SEMIHOSTING)
313-
else()
314-
add_dependencies(arm_executor_runner gen_model_header)
315327
endif()
316328

317329
if(ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE)
@@ -335,6 +347,12 @@ if(DEFINED ET_ARM_BAREMETAL_FAST_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE)
335347
)
336348
endif()
337349

350+
if(ET_MODEL_PTE_ADDR)
351+
target_compile_definitions(
352+
arm_executor_runner PUBLIC -DET_MODEL_PTE_ADDR=${ET_MODEL_PTE_ADDR}
353+
)
354+
endif()
355+
338356
if(ET_BUNDLE_IO)
339357
target_compile_definitions(arm_executor_runner PUBLIC -DET_BUNDLE_IO)
340358
endif()

0 commit comments

Comments
 (0)