Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b9e9bf

Browse files
authored
Arm backend: Add Ethos-U65 path to testing (pytorch#20141)
- Build semihosting runner in setup_testing - Add testing compile-spec - Use correct FVP in runner_utils - Add test pipeline - Add smoke test using the new pipeline to Add - Update default memory mode in Ethos-U65 compile spec. --------- Signed-off-by: Erik Lundell <[email protected]>
1 parent 0b13b6a commit 2b9e9bf

10 files changed

Lines changed: 218 additions & 15 deletions

File tree

backends/arm/ethosu/compile_spec.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def _default_system_config_and_memory_mode(
5050
resolved_system_config = (
5151
"Ethos_U65_High_End" if system_config is None else system_config
5252
)
53-
resolved_memory_mode = "Sram_Only" if memory_mode is None else memory_mode
53+
resolved_memory_mode = (
54+
"Dedicated_Sram_384KB" if memory_mode is None else memory_mode
55+
)
5456
return resolved_system_config, resolved_memory_mode
5557
if "ethos-u85" in target_lower:
5658
resolved_system_config = (

backends/arm/scripts/build_executor_runner.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ help() {
4343
echo " --target=<TARGET> Target to build and run for Default: ${target}"
4444
echo " --build_type=<TYPE> Build with Release, Debug or RelWithDebInfo, default is ${build_type}"
4545
echo " --bundleio Support both pte and Bundle IO bpte using Devtools BundelIO with Input/RefOutput included"
46-
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."
46+
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_U65_High_End for EthosU65 targets, Ethos_U85_SYS_DRAM_Mid for EthosU85 targets."
4747
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."
4848
echo " --memory_mode=<CONFIG> Vela memory mode, used for setting the Timing Adapter parameters of the Corstone platforms."
4949
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)."
50-
echo " Default: Shared_Sram for the Ethos-U55 and Sram_Only for the Ethos-U85"
50+
echo " Default: Shared_Sram for the Ethos-U55, Sram_Only for the Ethos-U65 and Dedicated_Sram_384KB for the Ethos-U85"
5151
echo " --etdump Adds Devtools etdump support to track timing and output, etdump area will be base64 encoded in the log"
5252
echo " --extra_build_flags=<FLAGS> Extra flags to pass to cmake like -DET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE=60000 Default: none "
5353
echo " --output=<FOLDER> Output folder Default: <MODEL>/<MODEL>_<TARGET INFO>.pte"
@@ -139,6 +139,10 @@ fi
139139
if [[ ${system_config} == "" ]]
140140
then
141141
system_config="Ethos_U55_High_End_Embedded"
142+
if [[ ${target} =~ "ethos-u65" ]]
143+
then
144+
system_config="Ethos_U65_High_End"
145+
fi
142146
if [[ ${target} =~ "ethos-u85" ]]
143147
then
144148
system_config="Ethos_U85_SYS_DRAM_Mid"
@@ -148,6 +152,10 @@ fi
148152
if [[ ${memory_mode} == "" ]]
149153
then
150154
memory_mode="Shared_Sram"
155+
if [[ ${target} =~ "ethos-u65" ]]
156+
then
157+
memory_mode="Sram_Only"
158+
fi
151159
if [[ ${target} =~ "ethos-u85" ]]
152160
then
153161
memory_mode="Dedicated_Sram_384KB"
@@ -165,6 +173,9 @@ if [[ ${target} =~ ^cortex-m([0-9]+(plus|p)?)(\+|$) ]]; then
165173
elif [[ ${target} == *"ethos-u55"* ]]; then
166174
target_cpu=cortex-m55
167175
npu_target_config="${target}"
176+
elif [[ ${target} == *"ethos-u65"* ]]; then
177+
target_cpu=cortex-m55
178+
npu_target_config="${target}"
168179
else
169180
target_cpu=cortex-m85
170181
npu_target_config="${target}"

backends/arm/scripts/corstone_utils.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,40 @@ function(configure_timing_adapters SYSTEM_CONFIG MEMORY_MODE)
341341
ETHOSU_TA_HISTBIN_1=0
342342
ETHOSU_TA_HISTCNT_1=0
343343
)
344+
elseif(MEMORY_MODE MATCHES "Dedicated_Sram")
345+
target_compile_definitions(
346+
ethosu_target_common
347+
INTERFACE # Configure NPU architecture timing adapters This is just
348+
# example numbers and you should make this match your hardware
349+
# SRAM
350+
ETHOSU_TA_MAXR_0=8
351+
ETHOSU_TA_MAXW_0=8
352+
ETHOSU_TA_MAXRW_0=0
353+
ETHOSU_TA_RLATENCY_0=32
354+
ETHOSU_TA_WLATENCY_0=32
355+
ETHOSU_TA_PULSE_ON_0=3999
356+
ETHOSU_TA_PULSE_OFF_0=1
357+
ETHOSU_TA_BWCAP_0=4000
358+
ETHOSU_TA_PERFCTRL_0=0
359+
ETHOSU_TA_PERFCNT_0=0
360+
ETHOSU_TA_MODE_0=1
361+
ETHOSU_TA_HISTBIN_0=0
362+
ETHOSU_TA_HISTCNT_0=0
363+
# DRAM
364+
ETHOSU_TA_MAXR_1=64
365+
ETHOSU_TA_MAXW_1=32
366+
ETHOSU_TA_MAXRW_1=0
367+
ETHOSU_TA_RLATENCY_1=500
368+
ETHOSU_TA_WLATENCY_1=250
369+
ETHOSU_TA_PULSE_ON_1=4000
370+
ETHOSU_TA_PULSE_OFF_1=1000
371+
ETHOSU_TA_BWCAP_1=3750
372+
ETHOSU_TA_PERFCTRL_1=0
373+
ETHOSU_TA_PERFCNT_1=0
374+
ETHOSU_TA_MODE_1=1
375+
ETHOSU_TA_HISTBIN_1=0
376+
ETHOSU_TA_HISTCNT_1=0
377+
)
344378
else()
345379
message(
346380
FATAL_ERROR

backends/arm/test/common.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from executorch.backends.arm.test.runner_utils import (
1818
arm_executor_runner_exists,
1919
corstone300_installed,
20+
corstone300_u65_installed,
2021
corstone320_installed,
2122
model_converter_installed,
2223
vkml_emulation_layer_installed,
@@ -155,6 +156,42 @@ def get_u85_compile_spec(
155156
return compile_spec # type: ignore[return-value]
156157

157158

159+
def get_u65_compile_spec(
160+
macs: int = 256,
161+
system_config: str = "Ethos_U65_High_End",
162+
memory_mode: str = "Dedicated_Sram_384KB",
163+
extra_flags: str = "--arena-cache-size=393216",
164+
custom_path: Optional[str] = None,
165+
config: Optional[str] = None,
166+
tosa_debug_mode: EthosUCompileSpec.DebugMode | None = None,
167+
) -> EthosUCompileSpec:
168+
"""Default compile spec for Ethos-U65 tests."""
169+
if not custom_path:
170+
custom_path = maybe_get_tosa_collate_path()
171+
if custom_path is not None:
172+
os.makedirs(custom_path, exist_ok=True)
173+
174+
assert macs in [256, 512], "Unsupported MACs value"
175+
176+
if extra_flags is not None:
177+
extra_flags_list = extra_flags.split(" ")
178+
else:
179+
extra_flags_list = []
180+
181+
compile_spec = (
182+
EthosUCompileSpec(
183+
f"ethos-u65-{macs}",
184+
system_config=system_config,
185+
memory_mode=memory_mode,
186+
extra_flags=extra_flags_list,
187+
config_ini=config,
188+
)
189+
.dump_intermediate_artifacts_to(custom_path)
190+
.dump_debug_info(tosa_debug_mode)
191+
)
192+
return compile_spec
193+
194+
158195
def get_vgf_compile_spec(
159196
tosa_spec: str | TosaSpecification,
160197
compiler_flags: Optional[str] = "",
@@ -206,6 +243,19 @@ def get_vgf_compile_spec(
206243
is not built.
207244
"""
208245

246+
247+
XfailIfNoCorstone300_u65 = pytest.mark.xfail(
248+
condition=not (
249+
corstone300_u65_installed() and arm_executor_runner_exists("corstone-300-u65")
250+
),
251+
raises=FileNotFoundError,
252+
reason="Did not find Corstone-300-u65 FVP or executor_runner on path",
253+
)
254+
"""Xfails a test if Corsone300-u65 FVP is not installed, or if the executor
255+
runner is not built.
256+
"""
257+
258+
209259
XfailIfNoCorstone320 = pytest.mark.xfail(
210260
condition=not (
211261
corstone320_installed() and arm_executor_runner_exists("corstone-320")

backends/arm/test/misc/test_compile_spec.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ def test_ethos_u55_defaults_to_stable_softmax_u55_INT():
3838
assert pipeline_config.softmax == SoftmaxDecompositionConfig.STABLE
3939

4040

41+
def test_ethos_u65_defaults_to_high_end_dedicated_sram_u65_INT():
42+
compile_spec = EthosUCompileSpec("ethos-u65-256")
43+
44+
assert "--accelerator-config=ethos-u65-256" in compile_spec.compiler_flags
45+
assert "--system-config=Ethos_U65_High_End" in compile_spec.compiler_flags
46+
assert "--memory-mode=Dedicated_Sram_384KB" in compile_spec.compiler_flags
47+
assert compile_spec.tosa_spec.is_U55_subset
48+
49+
4150
def test_ethos_u85_defaults_to_masked_softmax_u85_INT():
4251
"""Test that EthosUCompileSpec for U85 defaults to MASKED softmax config."""
4352
compile_spec = EthosUCompileSpec("ethos-u85-256")

backends/arm/test/ops/test_add.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from executorch.backends.arm.test import common
1616
from executorch.backends.arm.test.tester.test_pipeline import (
1717
EthosU55PipelineINT,
18+
EthosU65PipelineINT,
1819
EthosU85PipelineINT,
1920
TosaPipelineFP,
2021
TosaPipelineINT,
@@ -182,6 +183,18 @@ def test_add_tensor_u55_INT(test_data: input_t1):
182183
pipeline.run()
183184

184185

186+
@common.parametrize("test_data", Add.test_data)
187+
@common.XfailIfNoCorstone300
188+
def test_add_tensor_u65_INT(test_data: input_t1):
189+
pipeline = EthosU65PipelineINT[input_t1](
190+
Add(),
191+
test_data(),
192+
aten_op,
193+
exir_op,
194+
)
195+
pipeline.run()
196+
197+
185198
@common.parametrize("test_data", Add.test_data)
186199
@common.XfailIfNoCorstone320
187200
def test_add_tensor_u85_INT(test_data: input_t1):

backends/arm/test/runner_utils.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@
7373
torch.complex128: np.complex128,
7474
}
7575

76-
VALID_TARGET = {"corstone-300", "corstone-320", "vkml_emulation_layer"}
76+
VALID_TARGET = {
77+
"corstone-300",
78+
"corstone-300-u65",
79+
"corstone-320",
80+
"vkml_emulation_layer",
81+
}
7782

7883

7984
class QuantizationParams:
@@ -450,11 +455,17 @@ def run_corstone(
450455
)
451456

452457
match target_board:
453-
case "corstone-300":
458+
case "corstone-300" | "corstone-300-u65":
459+
if target_board == "corstone-300":
460+
fvp = "FVP_Corstone_SSE-300_Ethos-U55"
461+
num_macs = 128
462+
else:
463+
fvp = "FVP_Corstone_SSE-300_Ethos-U65"
464+
num_macs = 256
454465
command_args = [
455-
"FVP_Corstone_SSE-300_Ethos-U55",
466+
fvp,
456467
"-C",
457-
"ethosu.num_macs=128",
468+
f"ethosu.num_macs={num_macs}",
458469
"-C",
459470
"mps3_board.visualisation.disable-visualisation=1",
460471
"-C",
@@ -805,10 +816,19 @@ def _tosa_refmodel_loglevel(loglevel: int) -> str:
805816

806817

807818
def corstone300_installed() -> bool:
808-
cmd = ["FVP_Corstone_SSE-300_Ethos-U55", "--version"]
819+
cmd_u55 = ["FVP_Corstone_SSE-300_Ethos-U55", "--version"]
809820
try:
810-
_run_cmd(cmd, check=True)
811-
except:
821+
_run_cmd(cmd_u55, check=True)
822+
except Exception:
823+
return False
824+
return True
825+
826+
827+
def corstone300_u65_installed() -> bool:
828+
cmd_u65 = ["FVP_Corstone_SSE-300_Ethos-U65", "--version"]
829+
try:
830+
_run_cmd(cmd_u65, check=True)
831+
except Exception:
812832
return False
813833
return True
814834

@@ -817,7 +837,7 @@ def corstone320_installed() -> bool:
817837
cmd = ["FVP_Corstone_SSE-320", "--version"]
818838
try:
819839
_run_cmd(cmd, check=True)
820-
except:
840+
except Exception:
821841
return False
822842
return True
823843

@@ -898,7 +918,7 @@ def _elf_path_candidates(
898918
raise ValueError(f"Unsupported target: {target_board}")
899919

900920
portable_ops_str = "portable-ops_" if use_portable_ops else ""
901-
if target_board in ("corstone-300", "corstone-320"):
921+
if target_board in ("corstone-300", "corstone-300-u65", "corstone-320"):
902922
build_dir = Path(
903923
"arm_test",
904924
f"arm_semihosting_executor_runner_"
@@ -969,7 +989,7 @@ def get_elf_path(
969989
def arm_executor_runner_exists(target_board: str, use_portable_ops: bool = False):
970990
try:
971991
get_elf_path(target_board, use_portable_ops=use_portable_ops)
972-
except:
992+
except Exception:
973993
return False
974994
else:
975995
return True
@@ -1021,6 +1041,8 @@ def get_target_board(compile_spec: ArmCompileSpec) -> str | None:
10211041
if isinstance(compile_spec, EthosUCompileSpec):
10221042
if "u55" in compile_spec.target:
10231043
return "corstone-300"
1044+
if "u65" in compile_spec.target:
1045+
return "corstone-300-u65"
10241046
if "u85" in compile_spec.target:
10251047
return "corstone-320"
10261048
return None

backends/arm/test/setup_testing.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ extraflags="-DET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE=83886080"
1919
#--target --system_config --memory_mode should match the ArmTester used setup see backends/arm/test/common.py
2020

2121
${build_executor_runner} --pte=semihosting --target=ethos-u55-128 --system_config=Ethos_U55_High_End_Embedded --memory_mode=Shared_Sram --output="${build_root_test_dir}_corstone-300" --extra_build_flags=${extraflags}
22+
${build_executor_runner} --pte=semihosting --target=ethos-u65-256 --system_config=Ethos_U65_High_End --memory_mode=Dedicated_Sram_384KB --output="${build_root_test_dir}_corstone-300-u65" --extra_build_flags=${extraflags}
2223
${build_executor_runner} --pte=semihosting --target=ethos-u85-128 --system_config=Ethos_U85_SYS_DRAM_Mid --memory_mode=Dedicated_Sram_384KB --output="${build_root_test_dir}_corstone-320" --extra_build_flags=${extraflags}
2324

2425
# List of portable ops used by testing, this is mainly used to test models in the flow
2526
# test setup to make sure models that are not fully delegated can still be tested and run OK
2627
# To use this you can set use_portable_ops=True when creating ArmTester()
2728

2829
portable_ops_list_u55="aten::permute_copy.out,aten::convolution.out,aten::relu.out,aten::_native_batch_norm_legit_no_training.out,aten::as_strided_copy.out,aten::mean.out,aten::squeeze_copy.dims,dim_order_ops::_clone_dim_order.out"
30+
portable_ops_list_u65="${portable_ops_list_u55}"
2931
portable_ops_list_u85="aten::permute_copy.out,aten::convolution.out,aten::relu.out,aten::_native_batch_norm_legit_no_training.out,aten::as_strided_copy.out,aten::mean.out,aten::full_like.out,aten::bmm.out,aten::scalar_tensor.out,aten::index.Tensor_out,aten::where.self_out,dim_order_ops::_to_dim_order_copy.out"
3032

3133
${build_executor_runner} --pte=semihosting --target=ethos-u55-128 --system_config=Ethos_U55_High_End_Embedded --memory_mode=Shared_Sram --select_ops_list="${portable_ops_list_u55}" --output="${build_root_test_dir}_portable-ops_corstone-300" --extra_build_flags=${extraflags}
34+
${build_executor_runner} --pte=semihosting --target=ethos-u65-256 --system_config=Ethos_U65_High_End --memory_mode=Dedicated_Sram_384KB --select_ops_list="${portable_ops_list_u65}" --output="${build_root_test_dir}_portable-ops_corstone-300-u65" --extra_build_flags=${extraflags}
3235
${build_executor_runner} --pte=semihosting --target=ethos-u85-128 --system_config=Ethos_U85_SYS_DRAM_Mid --memory_mode=Dedicated_Sram_384KB --select_ops_list="${portable_ops_list_u85}" --output="${build_root_test_dir}_portable-ops_corstone-320" --extra_build_flags=${extraflags}

backends/arm/test/test_arm_backend.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fi
4545

4646
TEST_SUITE_NAME="$(basename "$0") ${TEST_SUITE}"
4747

48-
EXCLUDE_TARGET_EXPR="(not u55) and (not u85) and (not tosa) and (not _vgf_)"
48+
EXCLUDE_TARGET_EXPR="(not u55) and (not u65) and (not u85) and (not tosa) and (not _vgf_)"
4949
PYTEST_RETRY_ARGS=(--reruns 2 --reruns-delay 1)
5050

5151
all() { # Run all tests
@@ -133,7 +133,7 @@ test_pytest_ops_ethos_u55() {
133133
backends/arm/scripts/build_executorch.sh
134134
backends/arm/test/setup_testing.sh
135135

136-
pytest "${PYTEST_RETRY_ARGS[@]}" --verbose --color=yes --numprocesses=auto --durations=10 backends/arm/test/ --ignore=backends/arm/test/models -k u55
136+
pytest "${PYTEST_RETRY_ARGS[@]}" --verbose --color=yes --numprocesses=auto --durations=10 backends/arm/test/ --ignore=backends/arm/test/models -k "u55 or u65"
137137
echo "${TEST_SUITE_NAME}: PASS"
138138
}
139139

0 commit comments

Comments
 (0)