Skip to content

Commit 8f569e5

Browse files
committed
Arm backend: Generate ETRecord from arm_aot_compiler
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]> Change-Id: If4e1fabba207905eaea1e8381e4d23476512c33b
1 parent 72580d2 commit 8f569e5

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
@@ -45,6 +46,7 @@
4546
from executorch.backends.cortex_m.passes.replace_quant_nodes_pass import (
4647
ReplaceQuantNodesPass,
4748
)
49+
from executorch.devtools import generate_etrecord
4850
from executorch.devtools.backend_debug import get_delegation_info
4951
from executorch.devtools.bundled_program.config import MethodTestCase, MethodTestSuite
5052

@@ -505,6 +507,13 @@ def get_args():
505507
default=False,
506508
help="Flag for producing BundleIO bpte file with input/output test/ref data.",
507509
)
510+
parser.add_argument(
511+
"--etrecord",
512+
action="store_true",
513+
required=False,
514+
default=False,
515+
help="Flag for producing a etrecord file.",
516+
)
508517
parser.add_argument(
509518
"-t",
510519
"--target",
@@ -822,6 +831,8 @@ def transform_for_cortex_m_backend(edge):
822831

823832
dump_delegation_info(edge, args.intermediates)
824833

834+
edge_program_manager_copy = copy.deepcopy(edge)
835+
825836
try:
826837
exec_prog = edge.to_executorch(
827838
config=ExecutorchBackendConfig(extract_delegate_segments=False)
@@ -843,9 +854,9 @@ def transform_for_cortex_m_backend(edge):
843854
)
844855

845856
if args.bundleio:
846-
output_name = f"{output_name}.bpte"
857+
output_file_name = f"{output_name}.bpte"
847858
else:
848-
output_name = f"{output_name}.pte"
859+
output_file_name = f"{output_name}.pte"
849860

850861
if args.output is not None:
851862
if args.output.endswith(".pte") or args.output.endswith(".bpte"):
@@ -858,19 +869,25 @@ def transform_for_cortex_m_backend(edge):
858869
raise RuntimeError(
859870
f"When not using --bundleio a .bpte file should not be use as --output {args.output}"
860871
)
861-
output_name = args.output
872+
output_file_name = args.output
862873
else:
863874
# --output is a folder
864-
output_name = os.path.join(args.output, output_name)
875+
output_file_name = os.path.join(args.output, output_file_name)
876+
877+
if args.bundleio or args.etrecord:
878+
etrecord_file_name = os.path.splitext(output_file_name)[0] + "_etrecord.bin"
879+
# Generate ETRecord
880+
generate_etrecord(etrecord_file_name, edge_program_manager_copy, exec_prog)
881+
print(f"ETRecord saved as {etrecord_file_name}")
865882

866883
if args.bundleio:
867884
# Realize the quantization impact on numerics when generating reference output
868885
reference_model = original_model if not model_int8 else model_int8
869-
save_bpte_program(exec_prog, reference_model, output_name)
870-
print(f"Bundle PTE file saved as {output_name}")
886+
save_bpte_program(exec_prog, reference_model, output_file_name)
887+
print(f"Bundle PTE file saved as {output_file_name}")
871888
else:
872-
save_pte_program(exec_prog, output_name)
873-
print(f"PTE file saved as {output_name}")
889+
save_pte_program(exec_prog, output_file_name)
890+
print(f"PTE file saved as {output_file_name}")
874891

875892
if args.evaluate:
876893
evaluate_model(

examples/arm/run.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,11 @@ fi
184184
cd $et_root_dir
185185
devtools_flag=""
186186
bundleio_flag=""
187+
etrecord_flag=""
187188
et_dump_flag=""
188189
if [ "$build_with_etdump" = true ] ; then
189190
et_dump_flag="--etdump"
191+
etrecord_flag="--etrecord"
190192
fi
191193

192194
if [ "$bundleio" = true ] ; then
@@ -263,7 +265,7 @@ for i in "${!test_model[@]}"; do
263265
model_compiler_flags="${model_compiler_flags} --model_input=${model_input}"
264266
fi
265267

266-
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}"
268+
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}"
267269
echo "CALL ${ARM_AOT_CMD}" >&2
268270
${ARM_AOT_CMD} 1>&2
269271

0 commit comments

Comments
 (0)