Skip to content

Commit bced6fe

Browse files
authored
Merge branch 'ArmDeveloperEcosystem:main' into main
2 parents 1755692 + 1fc167b commit bced6fe

File tree

11 files changed

+546
-0
lines changed

11 files changed

+546
-0
lines changed

assets/contributors.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,4 @@ Gian Marco Iodice,Arm,,,,
9191
Aude Vuilliomenet,Arm,,,,
9292
Andrew Kilroy,Arm,,,,
9393
Peter Harris,Arm,,,,
94+
Waheed Brown,Arm,https://github.com/armwaheed,https://www.linkedin.com/in/waheedbrown/,,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
title: Overview
3+
weight: 2
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Visualizing ML on Embedded Devices
10+
11+
Selecting the best hardware for machine learning (ML) models depends on effective tools. You can visualize ML performance early in the development cycle by using Arm [Fixed Virtual Platforms](https://developer.arm.com/Tools%20and%20Software/Fixed%20Virtual%20Platforms) (FVPs).
12+
13+
## TinyML
14+
15+
This Learning Path uses TinyML. TinyML is machine learning tailored to function on devices with limited resources, constrained memory, low power, and fewer processing capabilities.
16+
17+
For a learning path focused on creating and deploying your own TinyML models, please see [Introduction to TinyML on Arm using PyTorch and ExecuTorch](/learning-paths/embedded-and-microcontrollers/introduction-to-tinyml-on-arm/)
18+
19+
## Benefits and applications
20+
21+
New products, like Arm's [Ethos-U85](https://www.arm.com/products/silicon-ip-cpu/ethos/ethos-u85) NPU are available on FVPs earlier than on physical devices. FVPs also have a graphical user iterface (GUI), which is useful for for ML performance visualization due to:
22+
- visual confirmation that your ML model is running on the desired device,
23+
- clearly indicated instruction counts,
24+
- confirmation of total execution time and
25+
- visually appealing output for prototypes and demos.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
# User change
3+
title: "Install ExecuTorch"
4+
5+
weight: 3
6+
7+
# Do not modify these elements
8+
layout: "learningpathall"
9+
---
10+
11+
In this section, you will prepare a development environment to compile a machine learning model.
12+
13+
## Introduction to ExecuTorch
14+
15+
ExecuTorch is a lightweight runtime designed for efficient execution of PyTorch models on resource-constrained devices. It enables machine learning inference on embedded and edge platforms, making it well-suited for Arm-based hardware. Since Arm processors are widely used in mobile, IoT, and embedded applications, ExecuTorch leverages Arm's efficient CPU architectures to deliver optimized performance while maintaining low power consumption. By integrating with Arm's compute libraries, it ensures smooth execution of AI workloads on Arm-powered devices, from Cortex-M microcontrollers to Cortex-A application processors.
16+
17+
## Install dependencies
18+
19+
These instructions have been tested on Ubuntu 22.04, 24.04, and on Windows Subsystem for Linux (WSL).
20+
21+
Python3 is required and comes installed with Ubuntu, but some additional packages are needed:
22+
23+
```bash
24+
sudo apt update
25+
sudo apt install python-is-python3 python3-dev python3-venv gcc g++ make -y
26+
```
27+
28+
## Create a virtual environment
29+
30+
Create a Python virtual environment using `python venv`:
31+
32+
```console
33+
python3 -m venv $HOME/executorch-venv
34+
source $HOME/executorch-venv/bin/activate
35+
```
36+
The prompt of your terminal now has `(executorch)` as a prefix to indicate the virtual environment is active.
37+
38+
39+
## Install Executorch
40+
41+
From within the Python virtual environment, run the commands below to download the ExecuTorch repository and install the required packages:
42+
43+
``` bash
44+
cd $HOME
45+
git clone https://github.com/pytorch/executorch.git
46+
cd executorch
47+
```
48+
49+
Run the commands below to set up the ExecuTorch internal dependencies:
50+
51+
```bash
52+
git submodule sync
53+
git submodule update --init
54+
./install_executorch.sh
55+
```
56+
57+
{{% notice Note %}}
58+
If you run into an issue of `buck` running in a stale environment, reset it by running the following instructions:
59+
60+
```bash
61+
ps aux | grep buck
62+
pkill -f buck
63+
```
64+
{{% /notice %}}
65+
66+
After running the commands, `executorch` should be listed upon running `pip list`:
67+
68+
```bash
69+
pip list | grep executorch
70+
```
71+
72+
```output
73+
executorch 0.6.0a0+3eea1f1
74+
```
75+
76+
## Next Steps
77+
78+
Proceed to the next section to learn about and set up the virtualized hardware.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
# User change
3+
title: "Set up the Corstone-320 FVP on Linux"
4+
5+
weight: 4 # 1 is first, 2 is second, etc.
6+
7+
# Do not modify these elements
8+
layout: "learningpathall"
9+
---
10+
11+
In this section, you will run scripts to set up the Corstone-320 reference package.
12+
13+
The Corstone-320 Fixed Virtual Platform (FVP) is a pre-silicon software development environment for Arm-based microcontrollers. It provides a virtual representation of hardware, allowing developers to test and optimize software before actual hardware is available. Designed for AI and machine learning workloads, it includes support for Arm's Ethos-U NPU and Cortex-M processors, making it ideal for embedded AI applications. The FVP accelerates development by enabling early software validation and performance tuning in a flexible, simulation-based environment.
14+
15+
The Corstone reference system is provided free of charge, although you will have to accept the license in the next step. For more information on Corstone-320, check out the [official documentation](https://developer.arm.com/documentation/109761/0000?lang=en).
16+
17+
## Corstone-320 FVP Setup for ExecuTorch
18+
19+
{{% notice macOS %}}
20+
21+
Setting up FVPs on MacOS requires some extra steps, outlined in GitHub repo [VPs-on-Mac](https://github.com/Arm-Examples/FVPs-on-Mac/). macOS users must do this first, before setting up the Corestone-320 FVP.
22+
23+
{{% /notice %}}
24+
25+
Navigate to the Arm examples directory in the ExecuTorch repository. Run the following command.
26+
27+
```bash
28+
cd $HOME/executorch/examples/arm
29+
./setup.sh --i-agree-to-the-contained-eula
30+
```
31+
32+
After the script has finished running, it prints a command to run to finalize the installation. This step adds the FVP executables to your system path.
33+
34+
```bash
35+
source $HOME/executorch/examples/arm/ethos-u-scratch/setup_path.sh
36+
```
37+
38+
Test that the setup was successful by running the `run.sh` script for Ethos-U85, which is the target device for Corstone-320:
39+
40+
{{% notice macOS %}}
41+
42+
**Start Docker:** on macOS, FVPs run inside a Docker container.
43+
44+
{{% /notice %}}
45+
46+
```bash
47+
./examples/arm/run.sh --target=ethos-u85-256
48+
```
49+
50+
You will see a number of examples run on the FVP.
51+
52+
This confirms the installation, so you can now proceed to the Learning Path [Build a Simple PyTorch Model](/learning-paths/embedded-and-microcontrollers/introduction-to-tinyml-on-arm/4-build-model/).
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
# User change
3+
title: "How ExecuTorch Works"
4+
5+
weight: 5 # 1 is first, 2 is second, etc.
6+
7+
# Do not modify these elements
8+
layout: "learningpathall"
9+
---
10+
11+
Source: [How ExecuTorch Works](https://docs.pytorch.org/executorch/stable/intro-how-it-works.html) (official PyTorch Documentation)
12+
1. **Export the model:**
13+
* Generate a Graph
14+
* A graph is series of operators (ReLU, quantize, etc.) eligible for delegation to an accelerator
15+
* Your goal is to identify operators for acceleration on the Ethos-U NPU
16+
2. **Compile to ExecuTorch:**
17+
* This is the ahead-of-time compiler
18+
* This is why ExecuTorch inference is faster than PyTorch inference
19+
* Delegate operators to an accelerator, like the Ethos-U NPU
20+
3. **Run on targeted device:**
21+
* Deploy the ML model to the Fixed Virtual Platform (FVP) or physical device
22+
* Execute operators on the CPU and delegated operators on the Ethos-U NPU
23+
24+
**Diagram of How ExecuTorch Works**
25+
![How ExecuTorch works](./how-executorch-works-high-level.png)
26+
27+
## Deploy a TinyML Model
28+
29+
With your development environment set up, you can deploy a simple PyTorch model.
30+
31+
This example deploys the [MobileNet V2](https://pytorch.org/hub/pytorch_vision_mobilenet_v2/) computer vision model. The model is a convolutional neural network (CNN) that extracts visual features from an image. It is used for image classification and object detection.
32+
33+
The actual Python code for the MobileNet V2 model is in your local `executorch` repo: [executorch/examples/models/mobilenet_v2/model.py](https://github.com/pytorch/executorch/blob/main/examples/models/mobilenet_v2/model.py). You can deploy it using [run.sh](https://github.com/pytorch/executorch/blob/main/examples/arm/run.sh), just like you did in the previous step, with some extra parameters:
34+
35+
{{% notice macOS %}}
36+
37+
**Start Docker:** on macOS, FVPs run inside a Docker container.
38+
39+
{{% /notice %}}
40+
41+
```bash
42+
./examples/arm/run.sh \
43+
--aot_arm_compiler_flags="--delegate --quantize --intermediates mv2_u85/ --debug --evaluate" \
44+
--output=mv2_u85 \
45+
--target=ethos-u85-128 \
46+
--model_name=mv2
47+
```
48+
49+
**Explanation of run.sh Parameters**
50+
|run.sh Parameter|Meaning / Context|
51+
|--------------|-----------------|
52+
|--aot_arm_compiler_flags|Passes a string of compiler options to the ExecuTorch Ahead-of-Time (AOT) compiler|
53+
|--delegate|Enables backend delegation|
54+
|--quantize|Converts the floating-point model to int8 quantized format using post-training quantization<br>**Essential for running on NPUs**|
55+
|--intermediates mv2_u85/|Directory where intermediate files (e.g., TOSA, YAMLs, debug graphs) will be saved<br>Useful output files for **manual debugging**|
56+
|--debug|Verbose debugging logging|
57+
|--evaluate|Validates model output, provides timing estimates|
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
# User change
3+
title: "Configure the FVP GUI (optional)"
4+
5+
weight: 6 # 1 is first, 2 is second, etc.
6+
7+
# Do not modify these elements
8+
layout: "learningpathall"
9+
---
10+
11+
## Find your IP address
12+
13+
Note down your computer's IP address:
14+
```bash
15+
ip addr show <YOUR_INTERFACE_NAME>
16+
```
17+
To help you, here are some common WiFi interface names on Linux:
18+
|Interface Name|Meaning / Context|
19+
|--------------|-----------------|
20+
|wlan0|Legacy name (common on older systems)|
21+
|wlp2s0, wlp3s0|Predictable network naming scheme (modern systems)|
22+
|wlx<MAC>|Some systems name interfaces after MAC addresses|
23+
|wifi0, ath0|Very rare, specific to certain drivers (e.g., Atheros)|
24+
25+
{{% notice macOS %}}
26+
27+
Note down your `en0` IP address (or whichever network adapter is active):
28+
29+
```bash
30+
ipconfig getifaddr en0 # Returns your Mac's WiFi IP address
31+
```
32+
33+
{{% /notice %}}
34+
35+
## Enable the FVP's GUI
36+
37+
Edit the following parameters in [run_fvp.sh](https://github.com/pytorch/executorch/blob/d5fe5faadb8a46375d925b18827493cd65ec84ce/backends/arm/scripts/run_fvp.sh#L97-L102), to enable the Mobilenet V2 output on the FVP's GUI:
38+
39+
```bash
40+
-C mps4_board.subsystem.ethosu.num_macs=${num_macs} \
41+
-C mps4_board.visualisation.disable-visualisation=1 \
42+
-C vis_hdlcd.disable_visualisation=1 \
43+
-C mps4_board.telnetterminal0.start_telnet=0 \
44+
-C mps4_board.uart0.out_file='-' \
45+
-C mps4_board.uart0.shutdown_on_eot=1 \
46+
```
47+
48+
- Change `mps4_board.visualisation.disable-visualisation` to equal `0`
49+
- Change `vis_hdlcd.disable_visualisation` to equal `0`
50+
- Enter a `--display-ip` parameter and set it to your computer's IP address
51+
52+
```bash
53+
-C mps4_board.subsystem.ethosu.num_macs=${num_macs} \
54+
-C mps4_board.visualisation.disable-visualisation=0 \
55+
-C vis_hdlcd.disable_visualisation=0 \
56+
-C mps4_board.telnetterminal0.start_telnet=0 \
57+
-C mps4_board.uart0.out_file='-' \
58+
-C mps4_board.uart0.shutdown_on_eot=1 \
59+
--display-ip <YOUR_IP_ADDRESS> \
60+
```
61+
62+
## Deploy the model
63+
64+
{{% notice macOS %}}
65+
66+
- **Start Docker:** on macOS, FVPs run inside a Docker container.
67+
68+
**Do not use Colima Docker!**
69+
70+
- Make sure to use an [official version of Docker](https://www.docker.com/products/docker-desktop/) and not a free version like the [Colima](https://github.com/abiosoft/colima?tab=readme-ov-file) Docker container runtime
71+
- `run.sh` assumes Docker Desktop style networking (`host.docker.internal`) which breaks with Colima
72+
- Colima then breaks the FVP GUI
73+
74+
- **Start XQuartz:** on macOS, the FVP GUI runs using XQuartz.
75+
76+
Start the xquartz.app and then configure XQuartz so that the FVP will accept connections from your Mac and localhost:
77+
```bash
78+
xhost + <YOUR_IP_ADDRESS>
79+
xhost + 127.0.0.1 # The Docker container seems to proxy through localhost
80+
```
81+
{{% /notice %}}
82+
83+
Now run the Mobilenet V2 computer vision model, using [executorch/examples/arm/run.sh](https://github.com/pytorch/executorch/blob/main/examples/arm/run.sh):
84+
```bash
85+
./examples/arm/run.sh \
86+
--aot_arm_compiler_flags="--delegate --quantize --intermediates mv2_u85/ --debug --evaluate" \
87+
--output=mv2_u85 \
88+
--target=ethos-u85-128 \
89+
--model_name=mv2
90+
```
91+
92+
Observe that the FVP loads the model file, compiles the PyTorch model to ExecuTorch `.pte` format and then shows an instruction count in the top right of the GUI:
93+
94+
![Terminal and FVP output](./Terminal%20and%20FVP%20Output.jpg)

0 commit comments

Comments
 (0)