Skip to content

Commit fcfbe5c

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 fcfbe5c

7 files changed

Lines changed: 69 additions & 1 deletion

File tree

zephyr/samples/mv2-ethosu/CMakeLists.txt

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

9999
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
100+
101+
if(CONFIG_ET_ARM_MODEL_PTE_DMA_ACCESSIBLE)
102+
zephyr_linker_sources(SECTIONS model_section.ld)
103+
endif()
104+
100105
project(executorch_mv2_ethosu)
101106

102107
set(CMAKE_CXX_FLAGS
@@ -224,6 +229,9 @@ if(DEFINED CONFIG_EXECUTORCH_TEMP_ALLOCATOR_POOL_SIZE)
224229
ET_ARM_BAREMETAL_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE=${CONFIG_EXECUTORCH_TEMP_ALLOCATOR_POOL_SIZE}
225230
)
226231
endif()
232+
if(CONFIG_ET_ARM_MODEL_PTE_DMA_ACCESSIBLE)
233+
target_compile_definitions(app PRIVATE ET_ARM_MODEL_PTE_DMA_ACCESSIBLE)
234+
endif()
227235

228236
target_link_libraries(app PRIVATE libexecutorch)
229237
if(EXECUTORCH_OPS_LIB)

zephyr/samples/mv2-ethosu/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ 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. Enable
16+
this when the model blob is placed in memory that the Ethos-U NPU
17+
can DMA from directly (e.g. DDR on Corstone FVP, MRAM on Alif).
18+
This significantly reduces SRAM usage for large models.
19+
1120
config EXECUTORCH_METHOD_ALLOCATOR_POOL_SIZE
1221
int "Method allocator pool size in bytes"
1322
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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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_DATA_PROLOGUE(network_model_sec,,)
6+
{
7+
. = ALIGN(16);
8+
*(.network_model_sec)
9+
*(.network_model_sec.*)
10+
} GROUP_DATA_LINK_IN(MODEL_DDR, MODEL_DDR)

0 commit comments

Comments
 (0)