• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2###############################################################################
3# This script tests the custom selective build flow for PyTorch Android, which
4# optimizes library size by only including ops used by a specific model.
5###############################################################################
6
7set -eux
8
9PYTORCH_DIR="$(cd $(dirname $0)/..; pwd -P)"
10PYTORCH_ANDROID_DIR="${PYTORCH_DIR}/android"
11BUILD_ROOT="${PYTORCH_DIR}/build_pytorch_android_custom"
12
13source "${PYTORCH_ANDROID_DIR}/common.sh"
14
15prepare_model_and_dump_root_ops() {
16  cd "${BUILD_ROOT}"
17  MODEL="${BUILD_ROOT}/MobileNetV2.pt"
18  ROOT_OPS="${BUILD_ROOT}/MobileNetV2.yaml"
19  python "${PYTORCH_ANDROID_DIR}/test_app/make_assets_custom.py"
20  cp "${MODEL}" "${PYTORCH_ANDROID_DIR}/test_app/app/src/main/assets/mobilenet2.pt"
21}
22
23# Start building
24mkdir -p "${BUILD_ROOT}"
25check_android_sdk
26check_gradle
27parse_abis_list "$@"
28prepare_model_and_dump_root_ops
29SELECTED_OP_LIST="${ROOT_OPS}" build_android
30
31# TODO: change this to build test_app instead
32$GRADLE_PATH -PABI_FILTERS=$ABIS_LIST -p $PYTORCH_ANDROID_DIR clean assembleRelease
33