Skip to content

Commit 007f97e

Browse files
committed
Arm backend: Move zephyr example to zephyr/samples folder
Move zephyr example from examples/arm/zephyr to zephyr/samples folder Signed-off-by: Zingo Andersen <Zingo.Andersen@arm.com> Change-Id: Ic16cb567ddbd0fbddb3906fb002a4bac5631b847
1 parent e3d2afc commit 007f97e

10 files changed

Lines changed: 45 additions & 14 deletions

File tree

.lintrunner.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ exclude_patterns = [
265265
'kernels/portable/cpu/op_lt.cpp',
266266
'kernels/portable/cpu/op_ne.cpp',
267267
'runtime/kernel/thread_parallel_interface.h',
268+
# Zephyr sample application can use std::vector in the sample code
269+
'zephyr/samples/**',
268270
'scripts/**',
269271
'third-party/**',
270272
'util/**',

zephyr/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**ExecuTorch** is PyTorch's unified solution for deploying AI models on-device—from smartphones to microcontrollers—built for privacy, performance, and portability. It powers Meta's on-device AI across **Instagram, WhatsApp, Quest 3, Ray-Ban Meta Smart Glasses**, and [more](https://docs.pytorch.org/executorch/main/success-stories.html).
44

5-
This folder adds ExecuTorch so it can be build and run in the Zephyr project as a external module. This includes an example under examples/arm/zephyr of running executor runners with Arm&reg; Ethos&trade;-U backend on a Corstone&trade; FVP, targeting the Zephyr RTOS.
5+
This folder adds ExecuTorch so it can be build and run in the Zephyr project as a external module. This includes an example under zephyr/samples/hello-executorch of running executor runners with Arm&reg; Ethos&trade;-U backend on a Corstone&trade; FVP, targeting the Zephyr RTOS.
66

77
# Requirements
88

@@ -113,7 +113,7 @@ export ARMFVP_EXTRA_FLAGS="-C mps3_board.uart0.shutdown_on_eot=1 -C ethosu.num_m
113113
Prepare the Ethos-U55 PTE model
114114
<!-- RUN test_ethos-u55_generate_pte -->
115115
```
116-
python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modules/lib/executorch/examples/arm/example_modules/add.py --quantize --delegate -t ethos-u55-128 --output=add_u55_128.pte
116+
python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modules/lib/executorch/zephyr/samples/hello-executorch/models/add.py --quantize --delegate --target=ethos-u55-128 --output=add_u55_128.pte
117117
```
118118

119119
`--delegate` tells the aot_arm_compiler to use Ethos-U backend and `-t ethos-u55-128` specify the used Ethos-U variant and numbers of macs used, this must match you hardware or FVP config.
@@ -123,7 +123,7 @@ python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modu
123123
Run the Ethos-U55 PTE model
124124
<!-- RUN test_ethos-u55_build_and_run -->
125125
```
126-
west build -b mps3/corstone300/fvp modules/lib/executorch/examples/arm/zephyr -t run -- -DET_PTE_FILE_PATH=add_u55_128.pte
126+
west build -b mps3/corstone300/fvp modules/lib/executorch/zephyr/samples/hello-executorch -t run -- -DET_PTE_FILE_PATH=add_u55_128.pte
127127
```
128128

129129
### Cortex-M55
@@ -133,7 +133,7 @@ west build -b mps3/corstone300/fvp modules/lib/executorch/examples/arm/zephyr -t
133133
Prepare the Cortex-M55 PTE model
134134
<!-- RUN test_cortex-m55_generate_pte -->
135135
```
136-
python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modules/lib/executorch/examples/arm/example_modules/add.py --quantize --target=cortex-m55+int8 --output=add_m55.pte
136+
python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modules/lib/executorch/zephyr/samples/hello-executorch/models/add.py --quantize --target=cortex-m55+int8 --output=add_m55.pte
137137
```
138138

139139
`--target=cortex-m55+int8` selects the Cortex-M/CMSIS-NN portable kernel path (no NPU delegation). This produces a `.pte` optimised for Cortex-M55 with INT8 quantisation.
@@ -143,7 +143,7 @@ python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modu
143143
Run the Cortex-M55 PTE model
144144
<!-- RUN test_cortex-m55_build_and_run -->
145145
```
146-
west build -b mps3/corstone300/fvp modules/lib/executorch/examples/arm/zephyr -t run -- -DET_PTE_FILE_PATH=add_m55.pte
146+
west build -b mps3/corstone300/fvp modules/lib/executorch/zephyr/samples/hello-executorch -t run -- -DET_PTE_FILE_PATH=add_m55.pte
147147
```
148148

149149
## Corstone&trade; 320 FVP (Ethos&trade;-U85)
@@ -168,7 +168,7 @@ export ARMFVP_EXTRA_FLAGS="-C mps4_board.uart0.shutdown_on_eot=1 -C mps4_board.s
168168
Prepare the Ethos-U85 PTE model
169169
<!-- RUN test_ethos-u85_generate_pte -->
170170
```
171-
python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modules/lib/executorch/examples/arm/example_modules/add.py --quantize --delegate -t ethos-u85-256 --output=add_u85_256.pte
171+
python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modules/lib/executorch/zephyr/samples/hello-executorch/models/add.py --quantize --delegate --target=ethos-u85-256 --output=add_u85_256.pte
172172
```
173173

174174
`--delegate` tells the aot_arm_compiler to use Ethos-U backend and `-t ethos-u85-256` specify the used Ethos-U variant and numbers of macs used, this must match you hardware or FVP config.
@@ -178,7 +178,7 @@ python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modu
178178
Run the Ethos-U85 PTE model
179179
<!-- RUN test_ethos-u85_build_and_run -->
180180
```
181-
west build -b mps4/corstone320/fvp modules/lib/executorch/examples/arm/zephyr -t run -- -DET_PTE_FILE_PATH=add_u85_256.pte
181+
west build -b mps4/corstone320/fvp modules/lib/executorch/zephyr/samples/hello-executorch -t run -- -DET_PTE_FILE_PATH=add_u85_256.pte
182182
```
183183

184184
## STM Nucleo n657x0_q
@@ -210,7 +210,7 @@ export PATH=$PATH:~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin
210210

211211
Prepare the Cortex-M55 PTE model
212212
```
213-
python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modules/lib/executorch/examples/arm/example_modules/add.py --quantize --target=cortex-m55+int8 --output=add_m55.pte
213+
python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modules/lib/executorch/zephyr/samples/hello-executorch/models/add.py --quantize --target=cortex-m55+int8 --output=add_m55.pte
214214
```
215215

216216
`--target=cortex-m55+int8` selects the Cortex-M/CMSIS-NN portable kernel path (no NPU delegation).
@@ -219,7 +219,7 @@ python -m modules.lib.executorch.examples.arm.aot_arm_compiler --model_name=modu
219219

220220
Run the Cortex-M55 PTE model
221221
```
222-
west build -b nucleo_n657x0_q modules/lib/executorch/examples/arm/zephyr -- -DET_PTE_FILE_PATH=add_m55.pte
222+
west build -b nucleo_n657x0_q modules/lib/executorch/zephyr/samples/hello-executorch -- -DET_PTE_FILE_PATH=add_m55.pte
223223
west flash
224224
```
225225
This will run the simple add model on your hardware one and print the output on the serial consol.
File renamed without changes.

examples/arm/zephyr/boards/mps3_corstone300_fvp.conf renamed to zephyr/samples/hello-executorch/boards/mps3_corstone300_fvp.conf

File renamed without changes.

examples/arm/zephyr/boards/mps3_corstone300_fvp.overlay renamed to zephyr/samples/hello-executorch/boards/mps3_corstone300_fvp.overlay

File renamed without changes.

examples/arm/zephyr/boards/mps4_corstone320_fvp.conf renamed to zephyr/samples/hello-executorch/boards/mps4_corstone320_fvp.conf

File renamed without changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2026 Arm Limited and/or its affiliates.
2+
#
3+
# This source code is licensed under the BSD-style license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
#
6+
# Example of an external model for the Arm AOT Compiler
7+
#
8+
# Example of an external Python file to be used as a module by the `run.sh`
9+
# (and the `aot_arm_compiler.py`) scripts in `examples/arm` directory.
10+
#
11+
# Just pass the path of the `add.py` file as `--model_name`
12+
#
13+
# These two variables are picked up by the `aot_arm_compiler.py` and used:
14+
# `ModelUnderTest` should be a `torch.nn.module` instance.
15+
# `ModelInputs` should be a tuple of inputs to the forward function.
16+
#
17+
18+
import torch
19+
20+
21+
class myModelAdd(torch.nn.Module):
22+
def __init__(self):
23+
super().__init__()
24+
25+
def forward(self, x):
26+
return x + x
27+
28+
29+
ModelUnderTest = myModelAdd()
30+
ModelInputs = (torch.ones(5),)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ CONFIG_EXECUTORCH_BUILD_PORTABLE_OPS=n
2828
# and use the hardware instance exposed by the board DTS is controlled with
2929
# CONFIG_ETHOS_U=y
3030
# This is handled in board specific .conf files, e.g.:
31-
# examples/arm/zephyr/boards/mps4_corstone320_fvp.conf
31+
# zephyr/samples/hello-executorch/boards/mps4_corstone320_fvp.conf
3232
# To be able to build the example for different HW, in your own project you can
3333
# copy the relevant lines from those files into your own prj.conf
3434

examples/arm/zephyr/src/arm_executor_runner.cpp renamed to zephyr/samples/hello-executorch/src/arm_executor_runner.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <zephyr/sys/printk.h>
2323
#include <cstring>
2424
#include <memory>
25-
#include <vector>
25+
#include <vector> /* @lint-ignore NOSTDINC */
2626

2727
/**
2828
* This header file is generated by the build process based on the .pte file
@@ -84,9 +84,8 @@ unsigned char __attribute__((
8484
* For Shared_Sram, ET_ARM_BAREMETAL_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE is
8585
* 2MB and the linker script places the .bss.tensor_arena symbol in the SRAM.
8686
* For Dedicated_Sram, the .bss.tensor_arena symbol is placed in the DDR in the
87-
* linker script. The examples/arm/zephyr/prj.conf contains the logic for the
88-
* sizes of:
89-
* CONFIG_EXECUTORCH_METHOD_ALLOCATOR_POOL_SIZE and
87+
* linker script. The zephyr/samples/hello-executorch/prj.conf contains the
88+
* logic for the sizes of: CONFIG_EXECUTORCH_METHOD_ALLOCATOR_POOL_SIZE and
9089
* CONFIG_EXECUTORCH_TEMP_ALLOCATOR_POOL_SIZE
9190
*/
9291

0 commit comments

Comments
 (0)