Skip to content

Commit 4dac48d

Browse files
committed
Update ExecuTorch build instructions for Ethos-U65
1 parent 2c1a72f commit 4dac48d

2 files changed

Lines changed: 249 additions & 114 deletions

File tree

content/learning-paths/embedded-and-microcontrollers/observing-ethos-u-on-nxp/6-build-executorch.md

Lines changed: 111 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,123 @@ weight: 7 # 1 is first, 2 is second, etc.
88
layout: "learningpathall"
99
---
1010

11-
For a full tutorial on building ExecuTorch please see learning path [Introduction to TinyML on Arm using PyTorch and ExecuTorch](/learning-paths/embedded-and-microcontrollers/introduction-to-tinyml-on-arm/)
11+
For a full tutorial on building ExecuTorch please see learning path [Introduction to TinyML on Arm using PyTorch and ExecuTorch](/learning-paths/embedded-and-microcontrollers/introduction-to-tinyml-on-arm/).
1212

13-
1. Build and install the `executorch` pip package from Source:
13+
## Install ExecuTorch
1414

15-
```bash
16-
git submodule sync
17-
git submodule update --init --recursive
18-
./install_executorch.sh
19-
```
15+
1. Upgrade pip and install build tools:
2016

21-
# Troubleshooting
17+
```bash
18+
pip install --upgrade pip setuptools wheel
19+
```
20+
21+
2. Build and install the `executorch` pip package:
22+
23+
```bash
24+
./install_executorch.sh
25+
```
26+
27+
## Build troubleshooting
28+
29+
If the `install_executorch.sh` script fails, manually install the dependencies using the following commands:
30+
31+
```bash
32+
pip install torch torchvision
33+
pip install --no-build-isolation .
34+
pip install --no-build-isolation third-party/ao
35+
```
36+
37+
## Set up the Arm toolchain
38+
39+
Initialize the Arm-specific environment and accept the EULA:
40+
41+
1. Run the setup script:
42+
43+
```bash
44+
./examples/arm/setup.sh --i-agree-to-the-contained-eula
45+
```
46+
47+
2. Source the environment variables:
48+
49+
```bash
50+
source ./examples/arm/arm-scratch/setup_path.sh
51+
```
52+
53+
## Apply the Ethos-U65 patch
54+
55+
As of this writing, ExecuTorch does not officially support the Ethos-U65. You must patch the `compile_spec.py` file to enable U65 compilation targets within the build system.
56+
57+
1. Create and apply the patch by running the following command block:
58+
59+
```bash
60+
cat > /tmp/patch_u65.py << 'PATCH'
61+
import os
62+
63+
# Locate the file within the virtual environment
64+
filepath = "/root/executorch/.venv/lib/python3.12/site-packages/executorch/backends/arm/ethosu/compile_spec.py"
65+
66+
with open(filepath, 'r') as f:
67+
content = f.read()
68+
69+
# 1. Inject U65 Configuration Support
70+
old_code = ' elif "ethos-u85" in target_lower:'
71+
new_code = ''' elif "ethos-u65" in target_lower:
72+
self.tosa_spec = TosaSpecification.create_from_string("TOSA-1.0+INT")
73+
default_system_config = "Ethos_U65_High_End"
74+
default_memory_mode = "Shared_Sram"
75+
elif "ethos-u85" in target_lower:'''
76+
77+
content = content.replace(old_code, new_code)
78+
79+
# 2. Inject U65 Compile Spec Builder Logic
80+
old_check = ''' if "u55" in target_lower:
81+
return CompileSpecBuilder(
82+
TosaSpecification.create_from_string("TOSA-0.80+BI+u55")
83+
)
84+
if "u85" in self.target:'''
85+
86+
new_check = ''' if "u55" in target_lower:
87+
return CompileSpecBuilder(
88+
TosaSpecification.create_from_string("TOSA-0.80+BI+u55")
89+
)
90+
if "u65" in target_lower:
91+
return CompileSpecBuilder(
92+
TosaSpecification.create_from_string("TOSA-1.0+INT")
93+
)
94+
if "u85" in self.target:'''
95+
96+
content = content.replace(old_check, new_check)
97+
98+
with open(filepath, 'w') as f:
99+
f.write(content)
100+
101+
print(f"Patched {filepath}! U65 support added.")
102+
PATCH
103+
104+
python3 /tmp/patch_u65.py
105+
```
106+
107+
2. Verify the patch by running:
108+
109+
```bash
110+
python3 -c "from executorch.backends.arm.ethosu import EthosUCompileSpec; EthosUCompileSpec(target='ethos-u65-256'); print('U65 OK')"
111+
```
112+
113+
If successful, you see the output `U65 OK`.
114+
115+
## Additional troubleshooting
22116
23117
1. Allocate at least 4 GB of swap space:
118+
24119
```bash
25120
fallocate -l 4G /swapfile
26121
chmod 600 /swapfile
27122
mkswap /swapfile
28123
swapon /swapfile
29124
```
30-
[optional] Deallocate the swap space after you complete this learning path:
125+
126+
Deallocate the swap space after you complete this learning path (optional):
127+
31128
```bash
32129
swapoff /swapfile
33130
rm /swapfile
@@ -40,20 +137,23 @@ For a full tutorial on building ExecuTorch please see learning path [Introductio
40137
41138
{{% /notice %}}
42139
43-
2. Kill the `buck2` process:
140+
2. Kill the `buck2` process if it hangs:
141+
44142
```bash
45143
ps aux | grep buck
46144
pkill -f buck
47145
```
48146
49147
3. Clean the build environment and reinitialize all submodules:
148+
50149
```bash
51150
./install_executorch.sh --clean
52151
git submodule sync
53152
git submodule update --init --recursive
54153
```
55154
56-
4. Try `install_executorch.sh` again, in development mode:
155+
4. Try `install_executorch.sh` again:
156+
57157
```bash
58158
./install_executorch.sh
59159
```

0 commit comments

Comments
 (0)