Skip to content

Fix the android demo app tutorial #649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions examples/demo-apps/android/ExecuTorchDemo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ cmake .. \
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON
```

2. Configure a library with XNNPACK and Qualcomm HTP backend
When we set `EXECUTORCH_BUILD_XNNPACK=ON`, we will build the target [`xnn_executor_runner_lib`](../../../../backends/xnnpack/CMakeLists.txt) which in turn is built into in [CMake](../jni/CMakeLists.txt).

`libexecutorchdemo.so` wraps up the required XNNPACK Backend runtime library from `xnn_executor_runner_lib`, and adds an additional JNI layer using fbjni. This is later exposed to Java app.

2. *Optional:* Configure a library with XNNPACK and [Qualcomm HTP backend](../../../../backends/qualcomm/README.md)

Qualcomm SDK is required for this step.

```bash
rm -rf cmake-out && mkdir cmake-out && cd cmake-out
Expand All @@ -92,6 +98,8 @@ cmake .. \
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON
```

Similar to the previous XNNPACK library, with this setup, `libexecutorchdemo.so` wraps up the XNNPACK Backend and Qualcomm HTP runtime library and fbjni. This is later exposed to Java app.

## Building and Copying Libraries

1. Build the libraries:
Expand All @@ -115,6 +123,15 @@ cp ./examples/demo-apps/android/jni/libexecutorchdemo.so \
../examples/demo-apps/android/ExecuTorchDemo/app/src/main/jniLibs/arm64-v8a
```

3. *Qualcomm HTP Only:* Copy Qualcomm HTP runtime library

If Qualcomm HTP backend is used, then we need to copy additional libraries from Qualcomm SDK artifacts:

```bash
cp libQnnHtp.so libQnnHtpV69Skel.so libQnnHtpStub.so libQnnSystem.so \
../examples/demo-apps/android/ExecuTorchDemo/app/src/main/jniLibs/arm64-v8a
```

Later, this shared library will be loaded by `NativePeer.java` in Java code.

Then return to the `executorch` directory:
Expand All @@ -134,11 +151,18 @@ Note: Please refer to [XNNPACK backend](../../../backend/README.md) and [Qualcom
export FLATC_EXECUTABLE=$(realpath third-party/flatbuffers/cmake-out/flatc)
python3 -m examples.backend.xnnpack_examples --model_name="dl3" --delegate
python3 -m examples.backend.xnnpack_examples --model_name="ic4" --delegate
cp dl3_xnnpack_fp32.pte ic4_xnnpack_fp32.pte examples/android_demo_apps/ExecuTorchDemo/app/src/main/assets/
mkdir -p examples/demo-apps/android/ExecuTorchDemo/app/src/main/assets/
cp dl3_xnnpack_fp32.pte ic4_xnnpack_fp32.pte examples/demo-apps/android/ExecuTorchDemo/app/src/main/assets/
```

2. *Qualcomm HTP Only:* Copy HTP delegation models to the app:

```bash
cp dlv3_qnn.pte ic4_qnn.pte examples/demo-apps/android/ExecuTorchDemo/app/src/main/assets/
```

## Final Steps

1. Open the project `examples/android_demo_apps/ExecuTorchDemo` with Android Studio.
1. Open the project `examples/demo-apps/android/ExecuTorchDemo` with Android Studio.

2. [Run](https://developer.android.com/studio/run) the app (^R)