Skip to content

Commit 7e3c1f4

Browse files
shoumikhinfacebook-github-bot
authored andcommitted
Update the readme file. (#713)
Summary: Pull Request resolved: #713 Simpler build instructions due to the new helper scripts. Reviewed By: kimishpatel Differential Revision: D50071422 fbshipit-source-id: 550aacdb1a20b7513461ba31368ebaaf2111cdd2
1 parent 4dbcdb7 commit 7e3c1f4

File tree

1 file changed

+57
-137
lines changed

1 file changed

+57
-137
lines changed
Lines changed: 57 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,176 +1,96 @@
1-
# iOS Demo App: ExecuTorch Setup
1+
# ExecuTorch: iOS Demo App Setup
22

3-
This guide explains how to setup ExecuTorch for iOS using a demo app. The app
4-
employs a MobileNet v3 model (exported to ExecuTorch) to process live camera
5-
images.
3+
This README guides you through the setup of ExecuTorch on iOS using a demo app.
4+
This app utilizes the MobileNet v3 model to process live camera images.
65

7-
## Pre-setup
6+
## Prerequisites
87

9-
1. Install Xcode and Command Line Tools:
8+
1. **Install Xcode 15 and Command Line Tools**
109

1110
```bash
1211
xcode-select --install
1312
```
1413

15-
2. Install `buck2` binary (using MacOS Apple Silicon build as example):
14+
2. **Python 3.10+ and `pip`** (Pre-installed from MacOS 13.5+)
1615

17-
```bash
18-
curl -L -O https://github.com/facebook/buck2/releases/download/2023-07-18/buck2-aarch64-apple-darwin.zst
19-
pip3 install zstd
20-
zstd -cdq buck2-aarch64-apple-darwin.zst > /tmp/buck2 && chmod +x /tmp/buck2
21-
```
22-
23-
3. Install [Cmake](cmake.org/download) and link it in a system directory or
24-
`$PATH`:
16+
[Download](https://www.python.org/downloads/macos/) and install Python 3.10
17+
or 3.11, if needed, and verify the versions:
2518

2619
```bash
27-
ln -s /Applications/CMake.app/Contents/bin/cmake /usr/bin/cmake
20+
which python3 pip
21+
python3 --version
22+
pip --version
2823
```
2924

30-
4. Clone ExecuTorch repository and update submodules:
25+
3. **Follow the [Getting Started](../../../docs/source/getting-started-setup.md)
26+
Tutorial**
3127

32-
```bash
33-
git clone https://github.com/pytorch/executorch.git
34-
cd executorch
35-
git submodule sync
36-
git submodule update --init
37-
```
28+
4. **Backend Dependency Installation**
3829

39-
5. Verify Python 3.10+ (standard since MacOS 13.5) and `pip3` installation:
30+
Install additional dependencies for **CoreML**:
4031

4132
```bash
42-
which python3 pip
43-
python3 --version
33+
./backends/apple/coreml/scripts/install_requirements.sh
4434
```
4535

46-
6. Install PyTorch dependencies:
36+
And **Metal Performance Shaders**:
4737

4838
```bash
49-
./install_requirements.sh
39+
./backends/apple/mps/install_requirements.sh
5040
```
5141

52-
## Flatbuffers Compiler Setup
53-
54-
Run the following in the `flatbuffers` directory:
55-
56-
```bash
57-
cd third-party/flatbuffers
58-
rm -rf cmake-out && mkdir cmake-out && cd cmake-out
59-
cmake .. && cmake --build . --target flatc
60-
cd ../../..
61-
```
62-
63-
## ExecuTorch Configuration
64-
65-
Configure the libraries for iOS:
66-
67-
```bash
68-
rm -rf cmake-out && mkdir cmake-out && cd cmake-out
69-
cmake .. -G Xcode \
70-
-DCMAKE_TOOLCHAIN_FILE=../third-party/pytorch/cmake/iOS.cmake \
71-
-DBUCK2=/tmp/buck2 \
72-
-DPYTHON_EXECUTABLE=$(which python3) \
73-
-DFLATC_EXECUTABLE=$(realpath ../third-party/flatbuffers/cmake-out/flatc) \
74-
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
75-
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=$(pwd)
76-
```
77-
78-
Append `-DIOS_PLATFORM=SIMULATOR` for Simulator configuration to build libraries
79-
for `x86` architecture instead of `arm64`, which is the default.
80-
81-
Append `-DEXECUTORCH_BUILD_COREML_DELGATE=ON` to build CoreML backend libraries.
82-
83-
Append `-DEXECUTORCH_BUILD_XNNPACK=ON` to build XNNPACK backend libraries.
84-
85-
## Building and Copying Libraries
86-
87-
1. Build the libraries:
88-
89-
```bash
90-
cmake --build . --config Release
91-
```
92-
93-
2. Copy the libraries to the appropriate location to link against them:
42+
## Model Export & Bundling
9443

95-
Navigate to the build artifacts directory:
44+
1. **Export MobileNet v3 model with CoreML, MPS and XNNPACK delegates**
9645

97-
```bash
98-
cd Release
99-
```
100-
101-
Copy the core libraries:
102-
103-
```bash
104-
mkdir -p ../../examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Frameworks/executorch/
105-
cp libexecutorch.a \
106-
libextension_data_loader.a \
107-
../../examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Frameworks/executorch/
108-
```
109-
110-
For Portable CPU operators, copy additional libraries:
111-
112-
```bash
113-
mkdir -p ../../examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Frameworks/portable/
114-
cp libportable_kernels.a \
115-
libportable_ops_lib.a \
116-
../../examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Frameworks/portable/
117-
```
118-
119-
For CoreML delegate backend, copy additional libraries:
120-
121-
```bash
122-
mkdir -p ../../examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Frameworks/coreml/
123-
cp libcoremldelegate.a \
124-
../../examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Frameworks/coreml/
125-
```
126-
127-
For XNNPACK delegate backend, copy additional libraries:
46+
```bash
47+
python3 -m examples.portable.scripts.export --model_name="mv3"
48+
python3 -m examples.xnnpack.aot_compiler --delegate --model_name="mv3"
49+
python3 -m examples.apple.coreml.scripts.export_and_delegate --model_name="mv3"
50+
python3 -m examples.apple.mps.scripts.mps_example --model_name="mv3"
12851

129-
```bash
130-
mkdir -p ../../examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Frameworks/xnnpack/
131-
cp libclog.a \
132-
libcpuinfo.a \
133-
libpthreadpool.a \
134-
libxnnpack_backend.a \
135-
libXNNPACK.a \
136-
../../examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Frameworks/xnnpack/
137-
```
52+
mkdir -p examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet/
53+
mv mv3*.pte examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet/
54+
```
13855

139-
Then return to the `executorch` directory:
56+
2. **Download MobileNet model labels**
14057

141-
```bash
142-
cd ../..
143-
```
58+
```bash
59+
curl https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt \
60+
-o examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet/imagenet_classes.txt
61+
```
14462

145-
## Model Download and Bundling
63+
## ExecuTorch & Backend Building
14664

147-
1. Download MobileNet model labels and bundle them with the app:
65+
1. **Build frameworks**
14866

149-
```bash
150-
mkdir -p examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet/
151-
curl https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt -o examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet/imagenet_classes.txt
152-
```
67+
```bash
68+
./build/build_apple_frameworks.sh --Release --coreml --mps --xnnpack
69+
```
15370

154-
2. Export a MobileNet v3 model backed with XNNPACK delegate and bundle it with
155-
the app:
71+
2. **Move frameworks for app linking**
15672

157-
```bash
158-
export FLATC_EXECUTABLE=$(realpath third-party/flatbuffers/cmake-out/flatc)
159-
python3 -m examples.portable.scripts.export --model_name="mv3"
160-
python3 -m examples.xnnpack.aot_compiler --model_name="mv3" --delegate
161-
python3 -m examples.export.coreml_export_and_delegate -m "mv3"
162-
cp mv3.pte mv3_coreml.pte mv3_xnnpack_fp32.pte examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet/
163-
```
73+
```bash
74+
mv cmake-out examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Frameworks
75+
```
16476

16577
## Final Steps
16678

167-
1. Open the project with Xcode:
79+
1. **Open project in Xcode**
16880

169-
```bash
170-
open executorch/examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo.xcodeproj
171-
```
81+
```bash
82+
open examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo.xcodeproj
83+
```
84+
85+
2. **Run tests in Xcode** (Cmd + U) or command line:
17286

173-
2. Set the Header Search Paths for `MobileNetClassifier` target to the directory
174-
containing the `executorch` folder.
87+
```bash
88+
xcrun simctl create executorch "iPhone 15"
89+
xcodebuild clean test \
90+
-project examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo.xcodeproj \
91+
-scheme App \
92+
-destination name=executorch
93+
xcrun simctl delete executorch
94+
```
17595

176-
3. Run the app (Cmd + R) and tests (Cmd + U).
96+
3. **Setup Code Signing and run app** (Cmd + R).

0 commit comments

Comments
 (0)