Skip to content

Commit c1e137b

Browse files
Add support for system_config/memory_mode in arm AOT flow (#7359)
Add support for system_config/memory_mode in arm AOT flow - Passes new args to Vela compileSpec - Selects correct Timing adapter values depending on system_config
1 parent 8e5f1c7 commit c1e137b

File tree

4 files changed

+160
-24
lines changed

4 files changed

+160
-24
lines changed

backends/arm/test/setup_testing.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ fvp_model=FVP_Corstone_SSE-300_Ethos-U55
2020
# Put in backends/arm/test/res to be used by unit tests.
2121
function build_semihosting_executorch_runner() {
2222
target_board=$1
23+
system_config=$2
2324
build_test_dir=${build_root_test_dir}_${target_board}
24-
echo "[${FUNCNAME[0]}] Configuring ${target_board}"
25+
echo "[${FUNCNAME[0]}] Configuring ${target_board} with system config ${system_config}"
2526
if [[ ${target_board} == "corstone-300" ]]; then
2627
local target_cpu=cortex-m55
2728
elif [[ ${target_board} == "corstone-320" ]]; then
@@ -36,15 +37,14 @@ function build_semihosting_executorch_runner() {
3637
cmake -DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} \
3738
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
3839
-DTARGET_CPU=${target_cpu} \
39-
-DTARGET_BOARD=${target_board} \
4040
-DSEMIHOSTING=ON \
4141
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${build_test_dir} \
4242
-B ${build_test_dir} \
4343
-DETHOS_SDK_PATH:PATH=${ethos_u_root_dir} \
4444
-DET_DIR_PATH:PATH=${et_root_dir} \
4545
-DET_BUILD_DIR_PATH:PATH=${et_build_dir} \
46-
-DPYTHON_EXECUTABLE=$(which python3)
47-
46+
-DPYTHON_EXECUTABLE=$(which python3) \
47+
-DSYSTEM_CONFIG=${system_config}
4848
echo "[${FUNCNAME[0]}] Configured CMAKE"
4949

5050
n=$(nproc)
@@ -53,6 +53,7 @@ function build_semihosting_executorch_runner() {
5353
find ${build_test_dir} -name "arm_executor_runner"
5454
}
5555

56-
build_semihosting_executorch_runner corstone-300
56+
# Use most optimal system_configs for testing
57+
build_semihosting_executorch_runner corstone-300 Ethos_U55_High_End_Embedded
5758

58-
build_semihosting_executorch_runner corstone-320
59+
build_semihosting_executorch_runner corstone-320 Ethos_U85_SYS_DRAM_Mid

examples/arm/aot_arm_compiler.py

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,21 +258,23 @@ def get_compile_spec(
258258
target: str,
259259
intermediates: Optional[str] = None,
260260
reorder_inputs: Optional[str] = None,
261+
system_config: Optional[str] = None,
262+
memory_mode: Optional[str] = None,
261263
) -> ArmCompileSpecBuilder:
262264
spec_builder = None
263265
if target == "TOSA":
264266
spec_builder = (
265267
ArmCompileSpecBuilder()
266-
.tosa_compile_spec("TOSA-0.80.0+BI")
268+
.tosa_compile_spec("TOSA-0.80+BI")
267269
.set_permute_memory_format(True)
268270
)
269271
elif "ethos-u55" in target:
270272
spec_builder = (
271273
ArmCompileSpecBuilder()
272274
.ethosu_compile_spec(
273275
target,
274-
system_config="Ethos_U55_High_End_Embedded",
275-
memory_mode="Shared_Sram",
276+
system_config=system_config,
277+
memory_mode=memory_mode,
276278
extra_flags="--debug-force-regor --output-format=raw --verbose-operators --verbose-cycle-estimate",
277279
)
278280
.set_permute_memory_format(True)
@@ -284,8 +286,8 @@ def get_compile_spec(
284286
ArmCompileSpecBuilder()
285287
.ethosu_compile_spec(
286288
target,
287-
system_config="Ethos_U85_SYS_DRAM_Mid",
288-
memory_mode="Shared_Sram",
289+
system_config=system_config,
290+
memory_mode=memory_mode,
289291
extra_flags="--output-format=raw --verbose-operators --verbose-cycle-estimate",
290292
)
291293
.set_permute_memory_format(True)
@@ -441,6 +443,18 @@ def get_args():
441443
default=None,
442444
help="Provide the order of the inputs. This can be required when inputs > 1.",
443445
)
446+
parser.add_argument(
447+
"--system_config",
448+
required=False,
449+
default=None,
450+
help="System configuration to select from the Vela configuration file (see vela.ini). This option must match the selected target, default is for an optimal system 'Ethos_U55_High_End_Embedded'/'Ethos_U85_SYS_DRAM_High'",
451+
)
452+
parser.add_argument(
453+
"--memory_mode",
454+
required=False,
455+
default=None,
456+
help="Memory mode to select from the Vela configuration file (see vela.ini). Default is 'Shared_Sram' for Ethos-U55 targets and 'Sram_Only' for Ethos-U85 targets",
457+
)
444458
args = parser.parse_args()
445459

446460
if args.evaluate and (
@@ -471,6 +485,22 @@ def get_args():
471485
):
472486
raise RuntimeError(f"Model {args.model_name} cannot be delegated.")
473487

488+
if args.system_config is None:
489+
if "u55" in args.target:
490+
args.system_config = "Ethos_U55_High_End_Embedded"
491+
elif "u85" in args.target:
492+
args.system_confg = "Ethos_U85_SYS_DRAM_Mid"
493+
else:
494+
raise RuntimeError(f"Invalid target name {args.target}")
495+
496+
if args.memory_mode is None:
497+
if "u55" in args.target:
498+
args.memory_mode = "Shared_Sram"
499+
elif "u85" in args.target:
500+
args.memory_mode = "Sram_Only"
501+
else:
502+
raise RuntimeError(f"Invalid target name {args.target}")
503+
474504
return args
475505

476506

@@ -504,7 +534,11 @@ def get_args():
504534
# As we can target multiple output encodings from ArmBackend, one must
505535
# be specified.
506536
compile_spec = get_compile_spec(
507-
args.target, args.intermediates, args.reorder_inputs
537+
args.target,
538+
args.intermediates,
539+
args.reorder_inputs,
540+
args.system_config,
541+
args.memory_mode,
508542
)
509543
edge = to_edge_transform_and_lower(
510544
exported_program,

examples/arm/executor_runner/CMakeLists.txt

Lines changed: 85 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ if(NOT DEFINED ET_PTE_FILE_PATH AND NOT ${SEMIHOSTING})
1818
)
1919
endif()
2020

21-
set(TARGET_BOARD "corstone-300" CACHE STRING "Target board")
22-
2321
# Example ExecuTorch demo for bare metal Cortex-M based systems
2422
set(ET_DIR_PATH
2523
"../../.."
@@ -46,6 +44,10 @@ set(PYTHON_EXECUTABLE
4644
CACHE PATH "Define to override python executable used"
4745
)
4846

47+
# Selects timing adapter values matching system_config.
48+
# Default is Ethos_U55_High_End_Embedded, simulating optimal hardware for the Corestone-300.
49+
set(SYSTEM_CONFIG "Ethos_U55_High_End_Embedded" CACHE STRING "System config")
50+
4951
get_filename_component(ET_BUILD_DIR_PATH ${ET_BUILD_DIR_PATH} REALPATH)
5052
get_filename_component(ET_DIR_PATH ${ET_DIR_PATH} REALPATH)
5153
get_filename_component(ET_INCLUDE_PATH ${ET_INCLUDE_PATH} REALPATH)
@@ -58,15 +60,14 @@ endif()
5860
# Corstone-300, that includes ethosu_core_driver and bare-metal bringup
5961
# libraries. We link against ethosu_target_init which includes all of these
6062
# dependencies.
61-
62-
if(TARGET_BOARD STREQUAL "corstone-300")
63+
if(SYSTEM_CONFIG STREQUAL "Ethos_U55_High_End_Embedded")
6364
add_subdirectory(${ETHOS_SDK_PATH}/core_platform/targets/corstone-300 target)
65+
set(TARGET_BOARD "corstone-300")
6466
target_compile_definitions(ethosu_target_common INTERFACE
6567
# ETHOSU_MODEL=0 place pte file/data in SRAM area
6668
# ETHOSU_MODEL=1 place pte file/data in DDR area
6769
ETHOSU_MODEL=1
6870
# Configure NPU architecture timing adapters
69-
# Ethos_U55_High_End_Embedded
7071
# This is just example numbers and you should make this match your hardware
7172
# SRAM
7273
ETHOSU_TA_MAXR_0=8
@@ -97,14 +98,90 @@ if(TARGET_BOARD STREQUAL "corstone-300")
9798
ETHOSU_TA_HISTBIN_1=0
9899
ETHOSU_TA_HISTCNT_1=0
99100
)
100-
elseif(TARGET_BOARD STREQUAL "corstone-320")
101+
elseif(SYSTEM_CONFIG STREQUAL "Ethos_U55_Deep_Embedded")
102+
add_subdirectory(${ETHOS_SDK_PATH}/core_platform/targets/corstone-300 target)
103+
set(TARGET_BOARD "corstone-300")
104+
target_compile_definitions(ethosu_target_common INTERFACE
105+
# ETHOSU_MODEL=0 place pte file/data in SRAM area
106+
# ETHOSU_MODEL=1 place pte file/data in DDR area
107+
ETHOSU_MODEL=1
108+
# Configure NPU architecture timing adapters
109+
# This is just example numbers and you should make this match your hardware
110+
# SRAM
111+
ETHOSU_TA_MAXR_0=4
112+
ETHOSU_TA_MAXW_0=4
113+
ETHOSU_TA_MAXRW_0=0
114+
ETHOSU_TA_RLATENCY_0=8
115+
ETHOSU_TA_WLATENCY_0=8
116+
ETHOSU_TA_PULSE_ON_0=3999
117+
ETHOSU_TA_PULSE_OFF_0=1
118+
ETHOSU_TA_BWCAP_0=4000
119+
ETHOSU_TA_PERFCTRL_0=0
120+
ETHOSU_TA_PERFCNT_0=0
121+
ETHOSU_TA_MODE_0=1
122+
ETHOSU_TA_HISTBIN_0=0
123+
ETHOSU_TA_HISTCNT_0=0
124+
# Flash
125+
ETHOSU_TA_MAXR_1=2
126+
ETHOSU_TA_MAXW_1=0
127+
ETHOSU_TA_MAXRW_1=0
128+
ETHOSU_TA_RLATENCY_1=32
129+
ETHOSU_TA_WLATENCY_1=0
130+
ETHOSU_TA_PULSE_ON_1=360
131+
ETHOSU_TA_PULSE_OFF_1=40
132+
ETHOSU_TA_BWCAP_1=25
133+
ETHOSU_TA_PERFCTRL_1=0
134+
ETHOSU_TA_PERFCNT_1=0
135+
ETHOSU_TA_MODE_1=1
136+
ETHOSU_TA_HISTBIN_1=0
137+
ETHOSU_TA_HISTCNT_1=0
138+
)
139+
elseif(SYSTEM_CONFIG STREQUAL "Ethos_U85_SYS_DRAM_Low")
140+
add_subdirectory(${ETHOS_SDK_PATH}/core_platform/targets/corstone-320 target)
141+
set(TARGET_BOARD "corstone-320")
142+
target_compile_definitions(ethosu_target_common INTERFACE
143+
# ETHOSU_MODEL=0 place pte file/data in SRAM area
144+
# ETHOSU_MODEL=1 place pte file/data in DDR area
145+
ETHOSU_MODEL=1
146+
# Configure NPU architecture timing adapters
147+
# This is just example numbers and you should make this match your hardware
148+
# SRAM
149+
ETHOSU_TA_MAXR_0=8
150+
ETHOSU_TA_MAXW_0=8
151+
ETHOSU_TA_MAXRW_0=0
152+
ETHOSU_TA_RLATENCY_0=16
153+
ETHOSU_TA_WLATENCY_0=16
154+
ETHOSU_TA_PULSE_ON_0=3999
155+
ETHOSU_TA_PULSE_OFF_0=1
156+
ETHOSU_TA_BWCAP_0=4000
157+
ETHOSU_TA_PERFCTRL_0=0
158+
ETHOSU_TA_PERFCNT_0=0
159+
ETHOSU_TA_MODE_0=1
160+
ETHOSU_TA_HISTBIN_0=0
161+
ETHOSU_TA_HISTCNT_0=0
162+
# DRAM
163+
ETHOSU_TA_MAXR_1=24
164+
ETHOSU_TA_MAXW_1=12
165+
ETHOSU_TA_MAXRW_1=0
166+
ETHOSU_TA_RLATENCY_1=250
167+
ETHOSU_TA_WLATENCY_1=125
168+
ETHOSU_TA_PULSE_ON_1=4000
169+
ETHOSU_TA_PULSE_OFF_1=1000
170+
ETHOSU_TA_BWCAP_1=2344
171+
ETHOSU_TA_PERFCTRL_1=0
172+
ETHOSU_TA_PERFCNT_1=0
173+
ETHOSU_TA_MODE_1=1
174+
ETHOSU_TA_HISTBIN_1=0
175+
ETHOSU_TA_HISTCNT_1=0
176+
)
177+
elseif(SYSTEM_CONFIG STREQUAL "Ethos_U85_SYS_DRAM_Mid" OR SYSTEM_CONFIG STREQUAL "Ethos_U85_SYS_DRAM_High")
101178
add_subdirectory(${ETHOS_SDK_PATH}/core_platform/targets/corstone-320 target)
179+
set(TARGET_BOARD "corstone-320")
102180
target_compile_definitions(ethosu_target_common INTERFACE
103181
# ETHOSU_MODEL=0 place pte file/data in SRAM area
104182
# ETHOSU_MODEL=1 place pte file/data in DDR area
105183
ETHOSU_MODEL=1
106184
# Configure NPU architecture timing adapters
107-
# Ethos_U85_SYS_DRAM_Mid
108185
# This is just example numbers and you should make this match your hardware
109186
# SRAM
110187
ETHOSU_TA_MAXR_0=8
@@ -136,7 +213,7 @@ elseif(TARGET_BOARD STREQUAL "corstone-320")
136213
ETHOSU_TA_HISTCNT_1=0
137214
)
138215
else()
139-
message(FATAL_ERROR "Unsupported TARGET_BOARD: ${TARGET_BOARD}")
216+
message(FATAL_ERROR "Unsupported SYSTEM_CONFIG: ${SYSTEM_CONFIG}")
140217
endif()
141218

142219
# Dependencies from the ExecuTorch build

examples/arm/run.sh

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ build_type="Release"
3030
extra_build_flags=""
3131
build_only=false
3232
reorder_inputs=""
33+
system_config=""
34+
memory_mode=""
3335

3436
help() {
3537
echo "Usage: $(basename $0) [options]"
@@ -45,6 +47,9 @@ help() {
4547
echo " --build_only Only build, don't run FVP"
4648
echo " --scratch-dir=<FOLDER> Path to your Ethos-U scrach dir if you not using default"
4749
echo " --reorder_inputs=<FLAGS> Reorder the inputs. This can be required when inputs > 1."
50+
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."
51+
echo " NOTE: If given, this option must match the given target. This option also sets timing adapter values customized for specific hardware, see ./executor_runner/CMakeLists.txt."
52+
echo " --memory_mode=<MODE> Memory mode to select from the Vela configuration file (see vela.ini), e.g. Shared_Sram/Sram_Only. Default: 'Shared_Sram' for Ethos-U55 targets, 'Sram_Only' for Ethos-U85 targets"
4853
exit 0
4954
}
5055

@@ -62,6 +67,8 @@ for arg in "$@"; do
6267
--build_only) build_only=true ;;
6368
--scratch-dir=*) root_dir="${arg#*=}";;
6469
--reorder_inputs=*) reorder_inputs="${arg#*=}";;
70+
--system_config=*) system_config="${arg#*=}";;
71+
--memory_mode=*) memory_mode="${arg#*=}";;
6572
*)
6673
;;
6774
esac
@@ -85,13 +92,32 @@ setup_path_script=${root_dir}/setup_path.sh
8592
et_root_dir=$(cd ${script_dir}/../.. && pwd)
8693
et_build_dir=${et_root_dir}/cmake-out
8794

95+
# Set target based variables
8896
fvp_model=FVP_Corstone_SSE-300_Ethos-U55
8997
if [[ ${target} =~ "ethos-u85" ]]
9098
then
9199
echo "target is ethos-u85 variant so switching to CS320 FVP"
92100
fvp_model=FVP_Corstone_SSE-320
93101
fi
94102

103+
if [[ ${system_config} == "" ]]
104+
then
105+
system_config="Ethos_U55_High_End_Embedded"
106+
if [[ ${target} =~ "ethos-u85" ]]
107+
then
108+
system_config="Ethos_U85_SYS_DRAM_Mid"
109+
fi
110+
fi
111+
112+
if [[ ${memory_mode} == "" ]]
113+
then
114+
memory_mode="Shared_Sram"
115+
if [[ ${target} =~ "ethos-u85" ]]
116+
then
117+
system_config="Sram_Only"
118+
fi
119+
fi
120+
95121
toolchain_cmake=${script_dir}/ethos-u-setup/arm-none-eabi-gcc.cmake
96122
_setup_msg="please refer to ${script_dir}/ethos-u-setup/setup.sh to properly install necessary tools."
97123

@@ -125,7 +151,7 @@ function generate_pte_file() {
125151
# We are using the aot_lib from build_quantization_aot_lib below
126152
SO_LIB=$(find cmake-out-aot-lib -name libquantized_ops_aot_lib.${SO_EXT})
127153
128-
local ARM_AOT_CMD="python3 -m examples.arm.aot_arm_compiler --model_name=${model} --target=${target} ${model_compiler_flags} --reorder_inputs=${reorder_inputs} --output ${output_folder} --so_library=$SO_LIB"
154+
local ARM_AOT_CMD="python3 -m examples.arm.aot_arm_compiler --model_name=${model} --target=${target} ${model_compiler_flags} --reorder_inputs=${reorder_inputs} --output ${output_folder} --so_library=$SO_LIB --system_config=${system_config} --memory_mode=${memory_mode}"
129155
echo "CALL ${ARM_AOT_CMD}" >&2
130156
${ARM_AOT_CMD} 1>&2
131157
@@ -271,10 +297,8 @@ function build_executorch_runner() {
271297
local pte=${1}
272298
if [[ ${target} == *"ethos-u55"* ]]; then
273299
local target_cpu=cortex-m55
274-
local target_board=corstone-300
275300
else
276301
local target_cpu=cortex-m85
277-
local target_board=corstone-320
278302
fi
279303
echo "--------------------------------------------------------------------------------"
280304
echo "Build Arm Baremetal executor_runner for ${target} - '${executor_runner_path}/cmake-out'"
@@ -291,14 +315,14 @@ function build_executorch_runner() {
291315
-DCMAKE_BUILD_TYPE=${build_type} \
292316
-DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} \
293317
-DTARGET_CPU=${target_cpu} \
294-
-DTARGET_BOARD=${target_board} \
295318
-DET_DIR_PATH:PATH=${et_root_dir} \
296319
-DET_BUILD_DIR_PATH:PATH=${et_build_dir} \
297320
-DET_PTE_FILE_PATH:PATH="${pte}" \
298321
-DETHOS_SDK_PATH:PATH=${ethos_u_root_dir} \
299322
-DETHOSU_TARGET_NPU_CONFIG=${target} \
300323
${build_with_etdump_flags} \
301324
-DPYTHON_EXECUTABLE=$(which python3) \
325+
-DSYSTEM_CONFIG=${system_config} \
302326
${extra_build_flags} \
303327
-B ${executor_runner_path}/cmake-out
304328

0 commit comments

Comments
 (0)