Skip to content

Commit fa07c0d

Browse files
kirklandsignkeyprocedure
authored andcommitted
Update LlamaDemo AAR build docs (pytorch#10086)
1 parent 2707f96 commit fa07c0d

File tree

3 files changed

+61
-30
lines changed

3 files changed

+61
-30
lines changed

examples/demo-apps/android/LlamaDemo/docs/delegates/mediatek_README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,31 @@ The Mediatek runner (`examples/mediatek/executor_runner/mtk_llama_runner.cpp`) c
126126

127127

128128
## Build AAR Library
129+
1. Open a terminal window and navigate to the root directory of the executorch
130+
2. Set the following environment variables:
131+
```sh
132+
export ANDROID_NDK=<path_to_android_ndk>
133+
export ANDROID_ABIS=arm64-v8a
134+
export NEURON_BUFFER_ALLOCATOR_LIB=<path_to_neuron_buffer_allocator_lib>
135+
```
136+
*Note: <path_to_android_ndk> is the root for the NDK, which is usually under ~/Library/Android/sdk/ndk/XX.Y.ZZZZZ for macOS, and contains NOTICE and README.md. We use <path_to_android_ndk>/build/cmake/android.toolchain.cmake for CMake to cross-compile.*
129137

130-
Next we need to build and compile the MediaTek backend and MediaTek Llama runner. By setting `NEURON_BUFFER_ALLOCATOR_LIB`, the script will build the MediaTek backend.
138+
3. Create a directory to hold the AAR
139+
```sh
140+
mkdir -p aar-out
141+
export BUILD_AAR_DIR=aar-out
131142
```
143+
144+
4. Run the following command to build the AAR:
145+
```sh
132146
sh scripts/build_android_library.sh
133147
```
134148

135-
**Output**: This will generate an .aar file that is already imported into the expected directory for the Android app. It will live in `examples/demo-apps/android/Llamademo/app/libs`.
149+
5. Copy the AAR to the app:
150+
```sh
151+
mkdir -p examples/demo-apps/android/LlamaDemo/app/libs
152+
cp aar-out/executorch.aar examples/demo-apps/android/LlamaDemo/app/libs/executorch.aar
153+
```
136154

137155
If you were to unzip the .aar file or open it in Android Studio, verify it contains the following related to MediaTek backend:
138156
* libneuron_buffer_allocator.so

examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -178,30 +178,38 @@ adb push tokenizer.bin /data/local/tmp/llama
178178

179179

180180
## Build AAR Library
181-
Open a terminal window and navigate to the root directory of the executorch.
181+
1. Open a terminal window and navigate to the root directory of the executorch
182182
Set the following environment variables:
183-
```
183+
```sh
184184
export ANDROID_NDK=<path_to_android_ndk>
185-
export ANDROID_ABI=arm64-v8a
186-
```
187-
Note: <path_to_android_ndk> is the root for the NDK, which is usually under ~/Library/Android/sdk/ndk/XX.Y.ZZZZZ for macOS, and contains NOTICE and README.md. We use <path_to_android_ndk>/build/cmake/android.toolchain.cmake for CMake to cross-compile.
188-
Build the Android Java extension code:
185+
export ANDROID_ABIS=arm64-v8a
186+
export QNN_SDK_ROOT=<path_to_qnn_sdk>
189187
```
190-
pushd extension/android
191-
./gradlew build
192-
popd
188+
189+
*Note: <path_to_android_ndk> is the root for the NDK, which is usually under ~/Library/Android/sdk/ndk/XX.Y.ZZZZZ for macOS, and contains NOTICE and README.md. We use <path_to_android_ndk>/build/cmake/android.toolchain.cmake for CMake to cross-compile.*
190+
191+
3. Create a directory to hold the AAR
192+
```sh
193+
mkdir -p aar-out
194+
export BUILD_AAR_DIR=aar-out
193195
```
194-
Run the following command set up the required JNI library:
196+
197+
4. Run the following command to build the AAR:
198+
```sh
199+
sh scripts/build_android_library.sh
195200
```
196-
pushd examples/demo-apps/android/LlamaDemo
197-
./gradlew :app:setupQnn
198-
popd
201+
202+
5. Copy the AAR to the app:
203+
```sh
204+
mkdir -p examples/demo-apps/android/LlamaDemo/app/libs
205+
cp aar-out/executorch.aar examples/demo-apps/android/LlamaDemo/app/libs/executorch.aar
199206
```
207+
200208
Alternative you can also just run the shell script directly as in the root directory:
201-
```
209+
```sh
202210
sh examples/demo-apps/android/LlamaDemo/setup-with-qnn.sh
203211
```
204-
This is running the shell script which configures the required core ExecuTorch, Llama2/3, and Android libraries, builds them, and copies them to jniLibs.
212+
This is running the shell script which configures the required core ExecuTorch, Llama2/3, and Android libraries, builds them into AAR, and copies it to the app.
205213
Note: If you are building the Android app mentioned in the next section on a separate machine (i.e. MacOS but building and exporting for QNN backend on Linux), make sure you copy the aar file generated from setup-with-qnn script to “examples/demo-apps/android/LlamaDemo/app/libs” before building the Android app.
206214

207215

examples/demo-apps/android/LlamaDemo/docs/delegates/xnnpack_README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,30 +132,35 @@ adb push tokenizer.bin /data/local/tmp/llama
132132
## Build AAR Library
133133
1. Open a terminal window and navigate to the root directory of the executorch
134134
2. Set the following environment variables:
135-
```
135+
```sh
136136
export ANDROID_NDK=<path_to_android_ndk>
137-
export ANDROID_ABI=arm64-v8a
137+
export ANDROID_ABIS=arm64-v8a
138138
```
139139
*Note: <path_to_android_ndk> is the root for the NDK, which is usually under ~/Library/Android/sdk/ndk/XX.Y.ZZZZZ for macOS, and contains NOTICE and README.md. We use <path_to_android_ndk>/build/cmake/android.toolchain.cmake for CMake to cross-compile.*
140140

141-
3. Build the Android Java extension code:
142-
```
143-
pushd extension/android
144-
./gradlew build
145-
popd
141+
3. Create a directory to hold the AAR
142+
```sh
143+
mkdir -p aar-out
144+
export BUILD_AAR_DIR=aar-out
146145
```
147-
4. Run the following command set up the required JNI library:
146+
147+
4. Run the following command to build the AAR:
148+
```sh
149+
sh scripts/build_android_library.sh
148150
```
149-
pushd examples/demo-apps/android/LlamaDemo
150-
./gradlew :app:setup
151-
popd
151+
152+
5. Copy the AAR to the app:
153+
```sh
154+
mkdir -p examples/demo-apps/android/LlamaDemo/app/libs
155+
cp aar-out/executorch.aar examples/demo-apps/android/LlamaDemo/app/libs/executorch.aar
152156
```
157+
153158
Alternative you can also just run the shell script directly as in the root directory:
154-
```
159+
```sh
155160
sh examples/demo-apps/android/LlamaDemo/setup.sh
156161
```
157162

158-
This is running the shell script which configures the required core ExecuTorch, Llama2/3, and Android libraries, builds them, and copies them to jniLibs.
163+
This is running the shell script which configures the required core ExecuTorch, Llama2/3, and Android libraries, builds them into AAR, and copies it to the app.
159164

160165
**Output**: The executorch.aar file will be generated in a newly created folder in the example/demo-apps/android/LlamaDemo/app/libs directory. This is the path that the Android app expects it to be in.
161166

0 commit comments

Comments
 (0)