Skip to content
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

[RELEASE ONLY] Generate and upload android prebuilt #3255

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
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
48 changes: 46 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ on:
- .ci/docker/**
- .github/workflows/android.yml
- install_requirements.sh
- examples/demo-apps/**
- examples/demo-apps/android/**
- extension/android/**
- extension/module/**
workflow_dispatch:

Expand All @@ -21,7 +22,7 @@ concurrency:
jobs:
test-demo-android:
name: test-demo-android
uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.3
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
strategy:
matrix:
include:
Expand All @@ -33,6 +34,7 @@ jobs:
submodules: 'true'
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
timeout: 90
upload-artifact: android-apps
script: |
set -eux

Expand All @@ -45,3 +47,45 @@ jobs:
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "${BUILD_TOOL}"
# Build Android demo app
bash build/test_android_ci.sh

mkdir -p artifacts-to-be-uploaded
mkdir -p artifacts-to-be-uploaded/arm64-v8a/
mkdir -p artifacts-to-be-uploaded/x86_64/
# Copy the jar to S3
cp extension/android/build/libs/executorch.jar artifacts-to-be-uploaded/
# Copy the app and its test suite to S3
cp examples/demo-apps/android/LlamaDemo/app/build/outputs/apk/debug/*.apk artifacts-to-be-uploaded/
cp examples/demo-apps/android/LlamaDemo/app/build/outputs/apk/androidTest/debug/*.apk artifacts-to-be-uploaded/
# Also copy the libraries
cp cmake-out-android-arm64-v8a/lib/*.a artifacts-to-be-uploaded/arm64-v8a/
cp cmake-out-android-arm64-v8a/extension/android/*.so artifacts-to-be-uploaded/arm64-v8a/
cp cmake-out-android-x86_64/lib/*.a artifacts-to-be-uploaded/x86_64/
cp cmake-out-android-x86_64/extension/android/*.so artifacts-to-be-uploaded/x86_64/

# Upload the app and its test suite to S3 so that they can be downloaded by the test job
upload-artifacts:
needs: test-demo-android
runs-on: linux.2xlarge
steps:
- name: Download the artifacts
uses: actions/download-artifact@v3
with:
# The name here needs to match the name of the upload-artifact parameter
name: android-apps
path: ${{ runner.temp }}/artifacts/

- name: Verify the artifacts
shell: bash
working-directory: ${{ runner.temp }}/artifacts/
run: |
ls -lah ./

- name: Upload the artifacts to S3
uses: seemethere/upload-artifact-s3@v5
with:
s3-bucket: gha-artifacts
s3-prefix: |
${{ github.repository }}/${{ github.run_id }}/artifact
retention-days: 14
if-no-files-found: ignore
path: ${{ runner.temp }}/artifacts/
16 changes: 10 additions & 6 deletions build/test_android_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
set -ex

# https://github.com/pytorch/executorch/tree/main/examples/demo-apps/android/ExecuTorchDemo
build_executorch() {
export_model() {
MODEL_NAME=dl3
# Delegating DeepLab v3 to XNNPACK backend
python -m examples.xnnpack.aot_compiler --model_name="${MODEL_NAME}" --delegate

ASSETS_DIR=examples/demo-apps/android/ExecuTorchDemo/app/src/main/assets/
mkdir -p "${ASSETS_DIR}"
cp "${MODEL_NAME}_xnnpack_fp32.pte" "${ASSETS_DIR}"
}

rm -rf cmake-out && mkdir cmake-out
ANDROID_NDK=/opt/ndk BUCK2=$(which buck2) FLATC=$(which flatc) ANDROID_ABI=arm64-v8a \
bash examples/demo-apps/android/ExecuTorchDemo/setup.sh
build_android_native_library() {
pushd examples/demo-apps/android/LlamaDemo
CMAKE_OUT="cmake-out-android-$1" ANDROID_NDK=/opt/ndk ANDROID_ABI="$1" ./gradlew setup
popd
}

build_android_demo_app() {
Expand All @@ -30,11 +32,13 @@ build_android_demo_app() {

build_android_llama_demo_app() {
pushd examples/demo-apps/android/LlamaDemo
ANDROID_NDK=/opt/ndk ANDROID_ABI=arm64-v8a ./gradlew setup
ANDROID_HOME=/opt/android/sdk ./gradlew build
ANDROID_HOME=/opt/android/sdk ./gradlew assembleAndroidTest
popd
}

build_executorch
build_android_native_library arm64-v8a
build_android_native_library x86_64
export_model
build_android_demo_app
build_android_llama_demo_app
Loading