Skip to content

Commit c598c35

Browse files
authored
Arm backend: Generate ETRecord from arm_aot_compiler (#13273)
An ETRecord file is generated if ETDump or BundleIO is used. This also adds tests for --bundleio and --etdump to make sure it works. Signed-off-by: Zingo Andersen <[email protected]>
1 parent 9cfb684 commit c598c35

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

backends/arm/test/test_arm_baremetal.sh

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ _setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly ins
1717

1818

1919
TEST_SUITE=$1
20-
TOSA_VERSION="${2:-TOSA-1.0+INT}"
2120

2221
# Source the tools
2322
# This should be prepared by the setup.sh
@@ -157,17 +156,23 @@ test_run_ethosu_fvp() { # End to End model tests using run.sh
157156

158157
# TOSA quantized
159158
echo "${TEST_SUITE_NAME}: Test ethos-u target TOSA"
160-
examples/arm/run.sh --et_build_root=arm_test/test_run --target=${TOSA_VERSION} --model_name=add
161-
examples/arm/run.sh --et_build_root=arm_test/test_run --target=${TOSA_VERSION} --model_name=mul
159+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=TOSA-1.0+INT --model_name=add
160+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=TOSA-1.0+INT --model_name=mul
162161

163162
# Ethos-U55
164163
echo "${TEST_SUITE_NAME}: Test ethos-u target Ethos-U55"
165164
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=add
165+
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
167+
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=add --etdump
166168
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u55-128 --model_name=mul
167169

168170
# Ethos-U85
169171
echo "${TEST_SUITE_NAME}: Test ethos-u target Ethos-U85"
170172
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
171176
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-128 --model_name=mul
172177

173178
# Cortex-M op tests
@@ -187,17 +192,17 @@ test_models_tosa() { # End to End model tests using model_test.py
187192

188193
# TOSA quantized
189194
echo "${TEST_SUITE_NAME}: Test ethos-u target TOSA"
190-
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=${TOSA_VERSION} --model=mv2
191-
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=${TOSA_VERSION} --model=mv3
192-
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=${TOSA_VERSION} --model=lstm
193-
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=${TOSA_VERSION} --model=edsr
194-
# python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=${TOSA_VERSION} --model=emformer_transcribe # Takes long time to run
195-
# python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=${TOSA_VERSION} --model=emformer_join # Takes long time to run
196-
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=${TOSA_VERSION} --model=w2l
197-
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=${TOSA_VERSION} --model=ic3
198-
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=${TOSA_VERSION} --model=ic4
199-
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=${TOSA_VERSION} --model=resnet18
200-
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=${TOSA_VERSION} --model=resnet50
195+
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=TOSA-1.0+INT --model=mv2
196+
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=TOSA-1.0+INT --model=mv3
197+
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=TOSA-1.0+INT --model=lstm
198+
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=TOSA-1.0+INT --model=edsr
199+
# python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=TOSA-1.0+INT --model=emformer_transcribe # Takes long time to run
200+
# python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=TOSA-1.0+INT --model=emformer_join # Takes long time to run
201+
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=TOSA-1.0+INT --model=w2l
202+
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=TOSA-1.0+INT --model=ic3
203+
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=TOSA-1.0+INT --model=ic4
204+
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=TOSA-1.0+INT --model=resnet18
205+
python3 backends/arm/test/test_model.py --test_output=arm_test/test_model --target=TOSA-1.0+INT --model=resnet50
201206

202207
echo "${TEST_SUITE_NAME}: PASS"
203208
}

examples/arm/aot_arm_compiler.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# Example script for exporting simple models to flatbuffer
99

1010
import argparse
11+
import copy
1112
import json
1213
import logging
1314
import os
@@ -44,6 +45,7 @@
4445
from executorch.backends.cortex_m.passes.replace_quant_nodes_pass import (
4546
ReplaceQuantNodesPass,
4647
)
48+
from executorch.devtools import generate_etrecord
4749
from executorch.devtools.backend_debug import get_delegation_info
4850
from executorch.devtools.bundled_program.config import MethodTestCase, MethodTestSuite
4951

@@ -504,6 +506,13 @@ def get_args():
504506
default=False,
505507
help="Flag for producing BundleIO bpte file with input/output test/ref data.",
506508
)
509+
parser.add_argument(
510+
"--etrecord",
511+
action="store_true",
512+
required=False,
513+
default=False,
514+
help="Flag for producing a etrecord file.",
515+
)
507516
parser.add_argument(
508517
"-t",
509518
"--target",
@@ -821,6 +830,8 @@ def transform_for_cortex_m_backend(edge):
821830

822831
dump_delegation_info(edge, args.intermediates)
823832

833+
edge_program_manager_copy = copy.deepcopy(edge)
834+
824835
try:
825836
exec_prog = edge.to_executorch(
826837
config=ExecutorchBackendConfig(extract_delegate_segments=False)
@@ -842,9 +853,9 @@ def transform_for_cortex_m_backend(edge):
842853
)
843854

844855
if args.bundleio:
845-
output_name = f"{output_name}.bpte"
856+
output_file_name = f"{output_name}.bpte"
846857
else:
847-
output_name = f"{output_name}.pte"
858+
output_file_name = f"{output_name}.pte"
848859

849860
if args.output is not None:
850861
if args.output.endswith(".pte") or args.output.endswith(".bpte"):
@@ -857,19 +868,25 @@ def transform_for_cortex_m_backend(edge):
857868
raise RuntimeError(
858869
f"When not using --bundleio a .bpte file should not be use as --output {args.output}"
859870
)
860-
output_name = args.output
871+
output_file_name = args.output
861872
else:
862873
# --output is a folder
863-
output_name = os.path.join(args.output, output_name)
874+
output_file_name = os.path.join(args.output, output_file_name)
875+
876+
if args.bundleio or args.etrecord:
877+
etrecord_file_name = os.path.splitext(output_file_name)[0] + "_etrecord.bin"
878+
# Generate ETRecord
879+
generate_etrecord(etrecord_file_name, edge_program_manager_copy, exec_prog)
880+
print(f"ETRecord saved as {etrecord_file_name}")
864881

865882
if args.bundleio:
866883
# Realize the quantization impact on numerics when generating reference output
867884
reference_model = original_model if not model_int8 else model_int8
868-
save_bpte_program(exec_prog, reference_model, output_name)
869-
print(f"Bundle PTE file saved as {output_name}")
885+
save_bpte_program(exec_prog, reference_model, output_file_name)
886+
print(f"Bundle PTE file saved as {output_file_name}")
870887
else:
871-
save_pte_program(exec_prog, output_name)
872-
print(f"PTE file saved as {output_name}")
888+
save_pte_program(exec_prog, output_file_name)
889+
print(f"PTE file saved as {output_file_name}")
873890

874891
if args.evaluate:
875892
evaluate_model(

examples/arm/run.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,11 @@ fi
185185
cd $et_root_dir
186186
devtools_flag=""
187187
bundleio_flag=""
188+
etrecord_flag=""
188189
et_dump_flag=""
189190
if [ "$build_with_etdump" = true ] ; then
190191
et_dump_flag="--etdump"
192+
etrecord_flag="--etrecord"
191193
fi
192194

193195
if [ "$bundleio" = true ] ; then
@@ -264,7 +266,7 @@ for i in "${!test_model[@]}"; do
264266
model_compiler_flags="${model_compiler_flags} --model_input=${model_input}"
265267
fi
266268

267-
ARM_AOT_CMD="python3 -m examples.arm.aot_arm_compiler --model_name=${model} --target=${target} ${model_compiler_flags} --intermediate=${output_folder} --output=${pte_file} --system_config=${system_config} --memory_mode=${memory_mode} $bundleio_flag --config=${config}"
269+
ARM_AOT_CMD="python3 -m examples.arm.aot_arm_compiler --model_name=${model} --target=${target} ${model_compiler_flags} --intermediate=${output_folder} --output=${pte_file} --system_config=${system_config} --memory_mode=${memory_mode} $bundleio_flag ${etrecord_flag} --config=${config}"
268270
echo "CALL ${ARM_AOT_CMD}" >&2
269271
${ARM_AOT_CMD} 1>&2
270272

0 commit comments

Comments
 (0)