Skip to content

Commit b6366da

Browse files
psiddhclaude
andcommitted
Place model PTE in DDR to fix FVP link-time memory overflow
The MV2 model PTE (~3.5 MB) overflows both the 512 KiB ITCM (FLASH) and 2 MiB ISRAM (RAM) regions on Corstone-300 FVP, and similarly on Corstone-320. Fix: declare a DDR memory region (0x7000_0000, 16 MiB) via DTS overlay on both FVP boards and route the network_model_sec linker section there via a Zephyr linker snippet. A new Kconfig option ET_ARM_MODEL_PTE_DMA_ACCESSIBLE (enabled for FVP boards) tells main.cpp to use the model blob in-place instead of memcpy-ing it into a second SRAM buffer, since the Ethos-U can DMA from DDR on the FVP. Also adds pool-size overrides for Corstone-320 (previously only had CONFIG_ETHOS_U=y). Co-authored-by: Claude <noreply@anthropic.com>
1 parent 321c029 commit b6366da

7 files changed

Lines changed: 78 additions & 1 deletion

File tree

zephyr/samples/mv2-ethosu/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ else()
9797
endif()
9898

9999
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
100+
101+
dt_nodelabel(model_ddr_path NODELABEL "model_ddr")
102+
if(model_ddr_path)
103+
configure_file(
104+
model_section.ld.in ${CMAKE_CURRENT_BINARY_DIR}/model_section.ld @ONLY
105+
)
106+
zephyr_linker_sources(SECTIONS ${CMAKE_CURRENT_BINARY_DIR}/model_section.ld)
107+
endif()
108+
100109
project(executorch_mv2_ethosu)
101110

102111
set(CMAKE_CXX_FLAGS
@@ -224,6 +233,9 @@ if(DEFINED CONFIG_EXECUTORCH_TEMP_ALLOCATOR_POOL_SIZE)
224233
ET_ARM_BAREMETAL_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE=${CONFIG_EXECUTORCH_TEMP_ALLOCATOR_POOL_SIZE}
225234
)
226235
endif()
236+
if(CONFIG_ET_ARM_MODEL_PTE_DMA_ACCESSIBLE)
237+
target_compile_definitions(app PRIVATE ET_ARM_MODEL_PTE_DMA_ACCESSIBLE)
238+
endif()
227239

228240
target_link_libraries(app PRIVATE libexecutorch)
229241
if(EXECUTORCH_OPS_LIB)

zephyr/samples/mv2-ethosu/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ source "Kconfig.zephyr"
88

99
menu "ExecuTorch MobileNetV2 sample configuration"
1010

11+
config ET_ARM_MODEL_PTE_DMA_ACCESSIBLE
12+
bool "Model PTE is in DMA-accessible memory"
13+
default n
14+
help
15+
Skip copying the model PTE blob to a separate SRAM buffer at
16+
runtime. Enable this when the embedded model blob already resides
17+
in memory the Ethos-U NPU can DMA from (e.g. DDR on Corstone FVP,
18+
MRAM on Alif). This is independent of where the linker places the
19+
model section; DDR placement is controlled by the model_ddr DTS
20+
node in the board overlay.
21+
1122
config EXECUTORCH_METHOD_ALLOCATOR_POOL_SIZE
1223
int "Method allocator pool size in bytes"
1324
default 1572864

zephyr/samples/mv2-ethosu/boards/mps3_corstone300_fvp.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
# and use the hardware instance exposed by the board DTS.
99
CONFIG_ETHOS_U=y
1010

11+
# Model PTE is placed in DDR via linker snippet; the Ethos-U can DMA from
12+
# DDR on the FVP so no SRAM copy is needed.
13+
CONFIG_ET_ARM_MODEL_PTE_DMA_ACCESSIBLE=y
14+
1115
# Corstone-300 has 2 MiB ISRAM. Reduce pool sizes to fit within budget
12-
# alongside stack, heap, model data, and runtime buffers.
16+
# alongside stack, heap, and runtime buffers.
1317
CONFIG_EXECUTORCH_METHOD_ALLOCATOR_POOL_SIZE=786432
1418
CONFIG_EXECUTORCH_TEMP_ALLOCATOR_POOL_SIZE=786432

zephyr/samples/mv2-ethosu/boards/mps3_corstone300_fvp.overlay

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,19 @@
99
* DMA can access. The default board DTS routes Zephyr's general-purpose
1010
* SRAM to DTCM, which the NPU cannot reach. Override the choice so that
1111
* .data/.bss land in ISRAM (0x3100_0000) instead.
12+
*
13+
* The model PTE blob is placed in DDR (0x7000_0000) via a linker snippet
14+
* to avoid overflowing the 2 MiB ISRAM and 512 KiB ITCM regions.
15+
* The Ethos-U can DMA from DDR on the Corstone-300 FVP.
1216
*/
1317
/ {
1418
chosen {
1519
zephyr,sram = &isram;
1620
};
21+
22+
model_ddr: memory@70000000 {
23+
compatible = "zephyr,memory-region", "mmio-sram";
24+
reg = <0x70000000 DT_SIZE_M(16)>;
25+
zephyr,memory-region = "MODEL_DDR";
26+
};
1727
};

zephyr/samples/mv2-ethosu/boards/mps4_corstone320_fvp.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@
77
# Enable the Zephyr Ethos-U driver so executorch_delegate_ethos_u can reserve
88
# and use the hardware instance exposed by the board DTS.
99
CONFIG_ETHOS_U=y
10+
11+
# Model PTE is placed in DDR via linker snippet; the Ethos-U can DMA from
12+
# DDR on the FVP so no SRAM copy is needed.
13+
CONFIG_ET_ARM_MODEL_PTE_DMA_ACCESSIBLE=y
14+
15+
# Corstone-320 has 4 MiB SRAM. Reduce pool sizes from the 1.5 MiB defaults
16+
# to leave headroom for stack, heap, and runtime buffers.
17+
CONFIG_EXECUTORCH_METHOD_ALLOCATOR_POOL_SIZE=786432
18+
CONFIG_EXECUTORCH_TEMP_ALLOCATOR_POOL_SIZE=786432
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Copyright (c) Meta Platforms, Inc. and affiliates.
2+
*
3+
* Copyright 2026 Arm Limited and/or its affiliates.
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
/* The model PTE blob is placed in DDR (0x7000_0000) via a linker snippet
9+
* to avoid overflowing SRAM with the full MobileNetV2 model.
10+
* The Ethos-U can DMA from DDR on the Corstone-320 FVP.
11+
*/
12+
/ {
13+
model_ddr: memory@70000000 {
14+
compatible = "zephyr,memory-region", "mmio-sram";
15+
reg = <0x70000000 DT_SIZE_M(16)>;
16+
zephyr,memory-region = "MODEL_DDR";
17+
};
18+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* Place the model PTE blob in DDR so it does not overflow the small
2+
* ITCM (FLASH) and ISRAM (RAM) regions on Corstone FVP boards.
3+
* The Ethos-U NPU can DMA from DDR on these platforms.
4+
*
5+
* Section name is substituted from the ET_PTE_SECTION CMake variable
6+
* so this stays in sync with pte_to_header.py --section.
7+
*/
8+
SECTION_DATA_PROLOGUE(@ET_PTE_SECTION@,,)
9+
{
10+
. = ALIGN(16);
11+
*(.@ET_PTE_SECTION@)
12+
*(.@ET_PTE_SECTION@.*)
13+
} GROUP_DATA_LINK_IN(MODEL_DDR, MODEL_DDR)

0 commit comments

Comments
 (0)