Skip to content

Commit 96b7d10

Browse files
committed
Tutorial for building and running a simple model on Xtensa
1 parent 0d7e81a commit 96b7d10

File tree

4 files changed

+144
-1
lines changed

4 files changed

+144
-1
lines changed
2.37 MB
Loading

docs/source/_templates/layout.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{% extends "!layout.html" %}
22

33
{% block extrahead %}
4-
{% if 'getting-started-setup' in pagename %}
4+
{% if 'getting-started-setup' in pagename%}
55
<link rel="stylesheet" href="_static/css/progress-bar.css">
66
<script src="_static/js/progress-bar.js" defer></script>
7+
{% elif 'xtensa' in pagename%}
8+
<link rel="stylesheet" href="../_static/css/progress-bar.css">
9+
<script src="../_static/js/progress-bar.js" defer></script>
710
{% endif %}
811
{{ super() }}
912
{% endblock %}
1013

14+
1115
{% block sidebartitle %}
1216
{% include "searchbox.html" %}
1317
{% endblock %}

docs/source/build-run-xtensa.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<!---- DO NOT MODIFY Progress Bar Start --->
2+
3+
<div class="progress-bar-wrapper">
4+
<div class="progress-bar-item">
5+
<div class="step-number" id="step-1">1</div>
6+
<span class="step-caption" id="caption-1"></span>
7+
</div>
8+
<div class="progress-bar-item">
9+
<div class="step-number" id="step-2">2</div>
10+
<span class="step-caption" id="caption-2"></span>
11+
</div>
12+
<div class="progress-bar-item">
13+
<div class="step-number" id="step-3">3</div>
14+
<span class="step-caption" id="caption-3"></span>
15+
</div>
16+
<div class="progress-bar-item">
17+
<div class="step-number" id="step-4">4</div>
18+
<span class="step-caption" id="caption-4"></span>
19+
</div>
20+
</div>
21+
22+
<!---- DO NOT MODIFY Progress Bar End--->
23+
24+
# Building and running ExecuTorch on Xtensa HiFi4 DSP
25+
26+
27+
In this tutorial we will walk you through the process of getting setup to
28+
build ExecuTorch for an Xtensa Hifi4 DSP and running a simple model on it.
29+
30+
::::{grid} 1
31+
:::{grid-item-card} Tutorials we recommend you complete before this:
32+
:class-card: card-prerequisites
33+
* [Introduction to ExecuTorch](intro-how-it-works.md)
34+
* [Setting up ExecuTorch](getting-started-setup.md)
35+
* [Building ExecuTorch with CMake](runtime-build-and-cross-compilation.md)
36+
:::
37+
::::
38+
39+
## Prerequsites (Hardware and Software)
40+
41+
In order to be able to succesfully build and run ExecuTorch on a Xtensa HiFi4 DSP
42+
you'll need the following hardware and software components.
43+
44+
### Hardware:
45+
- [i.MX RT600 Evaluation Kit](https://www.nxp.com/design/development-boards/i-mx-evaluation-and-development-boards/i-mx-rt600-evaluation-kit:MIMXRT685-EVK)
46+
47+
### Software:
48+
- x86-64 Linux system (For compiling the DSP binaries)
49+
- [MCUXpressoIDE](https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/mcuxpresso-integrated-development-environment-ide:MCUXpresso-IDE)
50+
- This IDE is supported on multiple platforms including MacOS. You can use it on any of the supported platforms as we'll only be using this to flash the board with the DSP images we'll be building later on in this tutorial.
51+
- [J-Link](https://www.segger.com/downloads/jlink/)
52+
- Needed to flash the board with the firmaware images. You can install this on the same platform that you installed the MCUXpresso IDE on.
53+
- [MCUXpressoSDK](https://mcuxpresso.nxp.com/en/select?device=EVK-MIMXRT685)
54+
- Download this SDK to your Linux machine, extract it and take a note of the path where you store it. We'll need this later.
55+
- [Xtensa compiler](https://tensilicatools.com/platform/i-mx-rt600/)
56+
- Download this to your Linux machine. Needed to build ExecuTorch for the HiFi4 DSP
57+
58+
## Setting up your developer environment
59+
60+
Step 1. In order to be able to succesfully install all the software components specified above users will need to go through the NXP tutorial linked below. Although the tutorial itself walks through a Windows setup, most of the steps translate over to a Linux installation too.
61+
62+
[NXP tutorial on setting up the board and dev environemnt](https://www.nxp.com/document/guide/getting-started-with-i-mx-rt600-evaluation-kit:GS-MIMXRT685-EVK?section=plug-it-in).
63+
64+
```{note}
65+
Before proceeding forward to the next section users should be able to succesfullly flash the **dsp_mu_polling_cm33** sample application from the tutorial above and notice output on the UART console indicating that the Cortex-M33 and HiFi4 DSP are talking to each other.
66+
```
67+
68+
Step 2. Make sure to have completed the ExecuTorch setup tutorials linked to at the top of this page.
69+
70+
## Build
71+
72+
### AOT (Ahead-of-time) components:
73+
74+
**ExecuTorch Program generation**:
75+
- In this step we'll be generating a simple ExecuTorch program that does an an add operation. We'll then use this Program(.pte file) during the runtime build step to bake this Program into the DSP image.
76+
77+
```bash
78+
cd executorch
79+
python3 -m examples.export.export_example --model_name="add"
80+
```
81+
82+
### Runtime:
83+
84+
**Building the DSP firmware image**
85+
- In this step we'll be building the DSP firmware image that consists of the sample ExecuTorch runner along with the Program generated from the previous step. This image when loaded onto the DSP will run through the simple add model that this Program consists of.
86+
87+
***Step 1***. Configure the environment variables needed to point to the Xtensa toolchain that you have installed in the previous stage. The three environment variables that need to be set are :
88+
```bash
89+
# Directory in which the Xtensa toolchain was installed
90+
export XTENSA_TOOLCHAIN=/home/user_name/xtensa/XtDevTools/install/tools
91+
# The version of the toolchain that was installed. This is essentially the name of the directory
92+
# that is present in the XTENSA_TOOLCHAIN directory from above.
93+
export TOOLCHAIN_VER=RI-2021.8-linux
94+
# The Xtensa core that we're targeting.
95+
export XTENSA_CORE=nxp_rt600_RI2021_8_newlib
96+
```
97+
98+
***Step 2***. Run the CMake build.
99+
In order to run the CMake build users will need the path to two things:
100+
- The Program generated in the previous step
101+
- Path to the NXP SDK root. This should have been installed already in the Setting up your developer environment section. (This is the directory that contains the folders such as boards, components, devices etc.)
102+
103+
```bash
104+
cd executorch
105+
mkdir cmake-xt
106+
cd cmake-xt
107+
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../examples/xtensa/xtensa.cmake -DMODEL_PATH=<path_to_program_file_generated_in_previous_step> -DNXP_SDK_ROOT_DIR=<path_to_nxp_sdk_root> -DEXECUTORCH_BUILD_FLATC=0 -DFLATC_EXECUTABLE="$(which flatc)" ..
108+
cd ..
109+
cmake --build cmake-xt -j9 -t xtensa_executorch_example
110+
```
111+
112+
After having succesfully run the above step users should see two binary files in their CMake output directory.
113+
```bash
114+
> ls cmake-xt/*.bin
115+
cmake-xt/dsp_data_release.bin cmake-xt/dsp_text_release.bin
116+
```
117+
118+
## Deploying and running on device
119+
120+
***Step 1***. We now take the DSP binary images generated from the previous step and copy them over into your NXP workspace created in the "Setting up your developer environment" section. Copy the DSP images into the "dsp_binary" section highlighted in the image below.
121+
122+
<img src="_static/img/dsp_binary.png" alt="MCUXpresso IDE" /><br>
123+
124+
***Step 2***. Clean your work space
125+
126+
***Step 3***. Click on the "Debug" your Project option which will flash the board with your binaries.
127+
128+
On the UART console connected to your board (at a default baud rate of 115200) you should see an output similar to this:
129+
130+
```bash
131+
> screen /dev/tty.usbmodem0007288234991 115200
132+
Booted up in DSP.
133+
ET: Model buffer loaded, has 1 methods
134+
ET: Running method forward
135+
Method loaded.
136+
Starting the model execution...
137+
Model executed successfully.
138+
```

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ Topics in this section will help you get started with ExecuTorch.
164164
:hidden:
165165

166166
tutorials/export-to-executorch-tutorial
167+
build-run-xtensa
167168

168169
Tutorials and Examples
169170
~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)