Skip to content

Commit 6785032

Browse files
Add bundled IO support to portable executor runner (#15368)
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]> Co-authored-by: Jacob Szwejbka <[email protected]>
1 parent 3ef13a3 commit 6785032

File tree

11 files changed

+300
-101
lines changed

11 files changed

+300
-101
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)
@@ -1083,6 +1087,10 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
10831087
list(APPEND _executor_runner_libs etdump flatccrt)
10841088
endif()
10851089

1090+
if(EXECUTORCH_ENABLE_BUNDLE_IO)
1091+
list(APPEND _executor_runner_libs bundled_program)
1092+
endif()
1093+
10861094
add_executable(executor_runner ${_executor_runner__srcs})
10871095
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
10881096
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ _setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly ins
1919

2020

2121
model=""
22+
opt_flags=""
2223
build_path="cmake-out-vkml"
2324
converter="model-converter"
2425

@@ -33,6 +34,7 @@ help() {
3334
for arg in "$@"; do
3435
case $arg in
3536
-h|--help) help ;;
37+
--optional_flags=*) opt_flags="${arg#*=}";;
3638
--model=*) model="${arg#*=}";;
3739
--build_path=*) build_path="${arg#*=}";;
3840
*)
@@ -60,11 +62,11 @@ command -v "${converter}" >/dev/null 2>&1 \
6062
|| { echo "Could not find a model converter executable (tried model-converter, model_converter). ${_setup_msg}"; exit 1; }
6163

6264

65+
runner=$(find ${build_path} -name executor_runner -type f)
6366

64-
runner="${build_path}/executor_runner"
6567

6668
echo "--------------------------------------------------------------------------------"
67-
echo "Running ${model} with ${runner}"
69+
echo "Running ${model} with ${runner} ${opt_flags}"
6870
echo "WARNING: The VK_ML layer driver will not provide accurate performance information"
6971
echo "--------------------------------------------------------------------------------"
7072

@@ -80,7 +82,7 @@ fi
8082
log_file=$(mktemp)
8183

8284

83-
${nobuf} ${runner} -model_path ${model} | tee ${log_file}
85+
${nobuf} ${runner} -model_path ${model} ${opt_flags} | tee ${log_file}
8486
echo "[${BASH_SOURCE[0]}] execution complete, $?"
8587

8688
# Most of these can happen for bare metal or linx executor_runner runs.

backends/arm/test/test_arm_baremetal.sh

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

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

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

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

254254
# VKML
255255
echo "${TEST_SUITE_NAME}: Test target VKML"
256-
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=vgf --model=mv2
257-
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=vgf --no_quantize --model=mv2
256+
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=vgf --model=resnet18 --extra_runtime_flags="--bundleio_atol=0.2 --bundleio_rtol=0.2"
257+
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=vgf --model=resnet50 --extra_runtime_flags="--bundleio_atol=0.2 --bundleio_rtol=0.2"
258258

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

backends/arm/test/test_model.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,15 @@ def get_args():
6767
parser.add_argument(
6868
"--extra_flags",
6969
required=False,
70-
default=None,
70+
default="",
7171
help="Extra cmake flags to pass the when building the executor_runner",
7272
)
73+
parser.add_argument(
74+
"--extra_runtime_flags",
75+
required=False,
76+
default="",
77+
help="Extra runtime flags to pass the final runner/executable",
78+
)
7379
parser.add_argument(
7480
"--timeout",
7581
required=False,
@@ -130,20 +136,18 @@ def build_pte(
130136
no_intermediate: bool,
131137
no_quantize: bool,
132138
):
133-
pte_file_ending = "pte"
134139
command_list = [
135140
"python3",
136141
"-m",
137142
"examples.arm.aot_arm_compiler",
138143
"--delegate",
144+
"--bundleio",
139145
f"--model_name={model_name}",
140146
f"--target={target}",
141147
f"--output={build_output}",
142148
]
143149

144150
if "vgf" != target:
145-
pte_file_ending = "bpte"
146-
command_list.append("--bundleio")
147151
command_list.append(f"--system_config={system_config}")
148152
command_list.append(f"--memory_mode={memory_mode}")
149153

@@ -155,6 +159,7 @@ def build_pte(
155159

156160
run_external_cmd(command_list)
157161

162+
pte_file_ending = "bpte"
158163
pte_file = os.path.join(
159164
output, f"{model_name}_arm_delegate_{args.target}.{pte_file_ending}"
160165
)
@@ -218,6 +223,7 @@ def build_vkml_runtime(
218223
os.path.join(script_path, "build_executor_runner_vkml.sh"),
219224
f"--et_build_root={et_build_root}",
220225
"--etdump",
226+
"--bundleio",
221227
"--build_type=Release",
222228
f"--extra_build_flags=-DET_DUMP_OUTPUT=OFF {extra_flags}",
223229
f"--output={build_path}",
@@ -228,13 +234,14 @@ def build_vkml_runtime(
228234
return runner
229235

230236

231-
def run_vkml(script_path: str, pte_file: str, runner_build_path: str):
237+
def run_vkml(script_path: str, pte_file: str, runner_build_path: str, extra_flags: str):
232238
run_external_cmd(
233239
[
234240
"bash",
235241
os.path.join(script_path, "run_vkml.sh"),
236242
f"--model={pte_file}",
237243
f"--build_path={runner_build_path}",
244+
f"--optional_flags={extra_flags}",
238245
]
239246
)
240247

@@ -297,7 +304,7 @@ def run_vkml(script_path: str, pte_file: str, runner_build_path: str):
297304
)
298305

299306
start_time = time.perf_counter()
300-
run_vkml(script_path, pte_file, build_path)
307+
run_vkml(script_path, pte_file, build_path, args.extra_runtime_flags)
301308
end_time = time.perf_counter()
302309
print(
303310
f"[Test model: {end_time - start_time:.2f} s] Tested VKML runner: {vkml_runner}"

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
@@ -321,7 +321,8 @@ for i in "${!test_model[@]}"; do
321321
set -x
322322
backends/arm/scripts/build_executor_runner_vkml.sh --build_type=${build_type} \
323323
--extra_build_flags="${extra_build_flags}" \
324-
--output="${output_folder}"
324+
--output="${output_folder}" \
325+
${bundleio_flag}
325326
if [ "$build_only" = false ] ; then
326327
backends/arm/scripts/run_vkml.sh --model=${pte_file} --build_path=${output_folder}
327328
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)