Skip to content

Commit a1468ae

Browse files
committed
Add bundled IO support to portable executor runner
Executor runner supports both models with/wo bundled io in same path. To enable bundled IO EXECUTORCH_BUILD_DEVTOOLS and EXECUTORCH_ENABLE_BUNDLE_IO are required. Adds tests in Arm backend for testing this/depending on this. Except for enabling bundle-io for VGF backend where applicable, some additional resnets model tests are enabled as well. Avoids narrowing conversion errors in pte_to_header script by switching char to unsigned char. Signed-off-by: Måns Nilsson <[email protected]> Change-Id: Iffdf6c253a57b01abb02758b6ba2d1e3de25e3d8
1 parent fdfeaa4 commit a1468ae

File tree

10 files changed

+301
-108
lines changed

10 files changed

+301
-108
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ if(EXECUTORCH_ENABLE_EVENT_TRACER)
119119
add_definitions(-DET_EVENT_TRACER_ENABLED)
120120
endif()
121121

122+
if(EXECUTORCH_ENABLE_BUNDLE_IO)
123+
add_definitions(-DET_BUNDLE_IO_ENABLED)
124+
endif()
125+
122126
# -ffunction-sections -fdata-sections: breaks function and data into sections so
123127
# they can be properly gc'd. -s: strip symbol.
124128
if(WIN32)
@@ -1072,6 +1076,10 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
10721076
list(APPEND _executor_runner_libs etdump flatccrt)
10731077
endif()
10741078

1079+
if(EXECUTORCH_ENABLE_BUNDLE_IO)
1080+
list(APPEND _executor_runner_libs bundled_program)
1081+
endif()
1082+
10751083
add_executable(executor_runner ${_executor_runner__srcs})
10761084
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
10771085
target_link_options_gc_sections(executor_runner)

backends/arm/scripts/build_executor_runner_vkml.sh

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,43 @@
66

77
set -eu
88

9-
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
9+
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})
1212
setup_path_script=${et_root_dir}/examples/arm/ethos-u-scratch/setup_path.sh
1313
_setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly install necessary tools."
14-
source "${script_dir}/utils.sh"
15-
1614
build_type="Release"
1715
build_with_etdump=false
1816
extra_build_flags=""
1917
output_folder="cmake-out-vkml"
18+
build_with_etdump_flags="-DEXECUTORCH_ENABLE_EVENT_TRACER=OFF"
19+
build_with_bundleio_flags="-DEXECUTORCH_ENABLE_BUNDLE_IO=OFF"
20+
21+
source "${script_dir}/utils.sh"
22+
2023

21-
build_with_etdump_flags="-DEXECUTORCH_ENABLE_EVENT_TRACER=OFF -DEXECUTORCH_BUILD_DEVTOOLS=OFF"
2224
help() {
2325
echo "Usage: $(basename $0) [options]"
2426
echo "Options:"
25-
echo " --build_type=<TYPE> Build with Release, Debug or RelWithDebInfo, default is ${build_type}"
26-
echo " --etdump Adds Devtools etdump support to track timing, etdump area will be base64 encoded in the log"
27-
echo " --extra_build_flags=<FLAGS> Extra flags to pass to cmake. Default: none "
28-
echo " --output=<FOLDER> Output folder Default: $(output_folder)"
27+
echo " --build_type=<TYPE> Build with Release, Debug or RelWithDebInfo, default is ${build_type}"
28+
echo " --etdump Adds Devtools etdump support to track timing, etdump area will be base64 encoded in the log"
29+
echo " --extra_build_flags=<FLAGS> Extra flags to pass to cmake. Default: none "
30+
echo " --output=<FOLDER> Output folder Default: $(output_folder)"
31+
echo " --bundleio Support BundleIO using Devtools with Input/RefOutput included"
2932
exit 0
3033
}
3134

3235
for arg in "$@"; do
3336
case $arg in
34-
-h|--help) help ;;
35-
--build_type=*) build_type="${arg#*=}";;
36-
--etdump) build_with_etdump=true ;;
37-
--extra_build_flags=*) extra_build_flags="${arg#*=}";;
38-
--output=*) output_folder="${arg#*=}";;
39-
--select_ops_list=*) select_ops_list="${arg#*=}";;
40-
*)
41-
;;
37+
-h|--help) help ;;
38+
--build_type=*) build_type="${arg#*=}";;
39+
--etdump) build_with_etdump=true ;;
40+
--extra_build_flags=*) extra_build_flags="${arg#*=}";;
41+
--output=*) output_folder="${arg#*=}";;
42+
--select_ops_list=*) select_ops_list="${arg#*=}";;
43+
--bundleio) build_with_bundleio_flags="-DEXECUTORCH_ENABLE_BUNDLE_IO=ON" ;;
44+
*)
45+
;;
4246
esac
4347
done
4448

@@ -52,23 +56,24 @@ source ${setup_path_script}
5256
mkdir -p "${output_folder}"
5357
output_folder=$(realpath "${output_folder}")
5458

55-
echo "--------------------------------------------------------------------------------"
56-
echo "Build Arm VKML executor runner: '${output_folder}' with extra build flags: ${extra_build_flags}"
57-
echo "--------------------------------------------------------------------------------"
58-
5959
cd ${et_root_dir}/examples/arm/executor_runner
6060

6161
if [ "$build_with_etdump" = true ] ; then
62-
build_with_etdump_flags="-DEXECUTORCH_ENABLE_EVENT_TRACER=ON -DEXECUTORCH_BUILD_DEVTOOLS=ON"
62+
build_with_etdump_flags="-DEXECUTORCH_ENABLE_EVENT_TRACER=ON"
6363
fi
6464

65-
echo "Building with extra flags: ${build_with_etdump_flags} ${extra_build_flags}"
65+
echo "-----------------------------------------------------------------------------------------------"
66+
echo "Build Arm VKML executor runner: '${output_folder}' with extra build flags: "
67+
echo "${build_with_etdump_flags} ${build_with_bundleio_flags} ${extra_build_flags}"
68+
echo "-----------------------------------------------------------------------------------------------"
69+
6670
cmake \
6771
-S "${et_root_dir}" \
6872
-B "${output_folder}" \
6973
-Wall \
7074
-Werror \
7175
-DCMAKE_BUILD_TYPE=${build_type} \
76+
-DCMAKE_CXX_FLAGS="${extra_build_flags} ${CMAKE_CXX_FLAGS:-}" \
7277
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
7378
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
7479
-DEXECUTORCH_BUILD_EXTENSION_NAMED_DATA_MAP=ON \
@@ -80,9 +85,10 @@ cmake \
8085
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
8186
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT=ON \
8287
-DEXECUTORCH_ENABLE_LOGGING=ON \
88+
-DEXECUTORCH_BUILD_DEVTOOLS=ON \
8389
-DPYTHON_EXECUTABLE="$(which python3)" \
84-
${build_with_etdump_flags} \
85-
${extra_build_flags}
90+
${build_with_etdump_flags} \
91+
${build_with_bundleio_flags}
8692

8793
echo "[${BASH_SOURCE[0]}] Configured CMAKE"
8894

backends/arm/scripts/run_vkml.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ hash ${converter} \
5555
|| { echo "Could not find ${converter} on PATH, ${_setup_msg}"; exit 1; }
5656

5757

58+
runner=$(find ${build_path} -name executor_runner -type f)
5859

59-
runner="${build_path}/executor_runner"
6060

6161
echo "--------------------------------------------------------------------------------"
6262
echo "Running ${model} with ${runner}"

backends/arm/test/test_arm_baremetal.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ test_run_vkml() { # End to End model tests using run.sh
190190

191191
echo "${TEST_SUITE_NAME}: Test VKML"
192192
out_folder="arm_test/test_run"
193-
examples/arm/run.sh --et_build_root=${out_folder} --target=vgf --model_name=add --output=${out_folder}/runner
194-
examples/arm/run.sh --et_build_root=${out_folder} --target=vgf --model_name=mul --output=${out_folder}/runner
193+
examples/arm/run.sh --et_build_root=${out_folder} --target=vgf --model_name=add --output=${out_folder}/runner --bundleio
194+
examples/arm/run.sh --et_build_root=${out_folder} --target=vgf --model_name=mul --output=${out_folder}/runner --bundleio
195195

196-
examples/arm/run.sh --et_build_root=${out_folder} --target=vgf --model_name=qadd --output=${out_folder}/runner
197-
examples/arm/run.sh --et_build_root=${out_folder} --target=vgf --model_name=qops --output=${out_folder}/runner
196+
examples/arm/run.sh --et_build_root=${out_folder} --target=vgf --model_name=qadd --output=${out_folder}/runner --bundleio
197+
examples/arm/run.sh --et_build_root=${out_folder} --target=vgf --model_name=qops --output=${out_folder}/runner --bundleio
198198

199199
echo "${TEST_SUITE_NAME}: PASS"
200200
}
@@ -254,8 +254,8 @@ test_models_vkml() { # End to End model tests using model_test.py
254254

255255
# VKML
256256
echo "${TEST_SUITE_NAME}: Test target VKML"
257-
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=vgf --model=mv2
258-
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=vgf --no_quantize --model=mv2
257+
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=vgf --model=resnet18 --extra_flags="-DET_BUNDLE_IO_ATOL=0.2 -DET_BUNDLE_IO_RTOL=0.2"
258+
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=vgf --model=resnet50 --extra_flags="-DET_BUNDLE_IO_ATOL=0.2 -DET_BUNDLE_IO_RTOL=0.2"
259259

260260
echo "${TEST_SUITE_NAME}: PASS"
261261
}

backends/arm/test/test_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,18 @@ def build_pte(
129129
no_intermediate: bool,
130130
no_quantize: bool,
131131
):
132-
pte_file_ending = "pte"
133132
command_list = [
134133
"python3",
135134
"-m",
136135
"examples.arm.aot_arm_compiler",
137136
"--delegate",
137+
"--bundleio",
138138
f"--model_name={model_name}",
139139
f"--target={target}",
140140
f"--output={build_output}",
141141
]
142142

143143
if "vgf" != target:
144-
pte_file_ending = "bpte"
145-
command_list.append("--bundleio")
146144
command_list.append(f"--system_config={system_config}")
147145
command_list.append(f"--memory_mode={memory_mode}")
148146

@@ -154,6 +152,7 @@ def build_pte(
154152

155153
run_external_cmd(command_list)
156154

155+
pte_file_ending = "bpte"
157156
pte_file = os.path.join(
158157
output, f"{model_name}_arm_delegate_{args.target}.{pte_file_ending}"
159158
)
@@ -217,6 +216,7 @@ def build_vkml_runtime(
217216
os.path.join(script_path, "build_executor_runner_vkml.sh"),
218217
f"--et_build_root={et_build_root}",
219218
"--etdump",
219+
"--bundleio",
220220
"--build_type=Release",
221221
f"--extra_build_flags=-DET_DUMP_OUTPUT=OFF {extra_flags}",
222222
f"--output={build_path}",

examples/arm/executor_runner/pte_to_header.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def input_file_path(path):
5959
if __name__ == "__main__":
6060
args = parser.parse_args()
6161
outfile = os.path.join(args.outdir, args.outfile)
62-
attr = f'__attribute__((section("{args.section}"), aligned(16))) char '
62+
attr = f'__attribute__((section("{args.section}"), aligned(16))) unsigned char '
6363

6464
with open(args.pte, "rb") as fr, open(outfile, "w") as fw:
6565
data = fr.read()

examples/arm/run.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ for i in "${!test_model[@]}"; do
307307
set -x
308308
backends/arm/scripts/build_executor_runner_vkml.sh --build_type=${build_type} \
309309
--extra_build_flags="${extra_build_flags}" \
310-
--output="${output_folder}"
310+
--output="${output_folder}" \
311+
${bundleio_flag}
311312
if [ "$build_only" = false ] ; then
312313
backends/arm/scripts/run_vkml.sh --model=${pte_file} --build_path=${output_folder}
313314
fi

examples/devtools/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22
# All rights reserved.
3+
# Copyright 2025 Arm Limited and/or its affiliates.
34
#
45
# This source code is licensed under the BSD-style license found in the
56
# LICENSE file in the root directory of this source tree.
@@ -47,7 +48,9 @@ find_package(
4748
)
4849

4950
add_executable(example_runner example_runner/example_runner.cpp)
50-
target_compile_options(executorch INTERFACE -DET_EVENT_TRACER_ENABLED)
51+
target_compile_options(
52+
executorch INTERFACE -DET_EVENT_TRACER_ENABLED -DET_BUNDLE_IO_ENABLED
53+
)
5154

5255
target_include_directories(
5356
etdump INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/../../devtools/include

0 commit comments

Comments
 (0)