From 0c3db1cb33cda1de61c754f14e7bfd2c53ea6d07 Mon Sep 17 00:00:00 2001 From: Chen Lai Date: Mon, 17 May 2021 14:11:46 -0700 Subject: [PATCH] [Pytorch] Build lite interpreter as default for Android Summary: Build lite interpreter as default for android, should wait until https://github.com/pytorch/pytorch/pull/56002 lands Mainly two changes: 1. Use lite interpreter as default for Android 2. Switch the lite interpreter build test to full jit build test Test Plan: Imported from OSS Differential Revision: D27695530 Reviewed By: IvanKobzarev Pulled By: cccclai fbshipit-source-id: e1b2c70fee6590accc22c7404b9dd52c7d7c36e2 --- .circleci/cimodel/data/simple/android_definitions.py | 4 ++-- .circleci/config.yml | 4 ++-- android/pytorch_android/CMakeLists.txt | 2 +- android/pytorch_android/build.gradle | 10 +++++----- .../src/main/java/org/pytorch/PyTorchAndroid.java | 2 +- scripts/build_android.sh | 11 ++++++----- tools/lite_interpreter/__init__.py | 0 7 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 tools/lite_interpreter/__init__.py diff --git a/.circleci/cimodel/data/simple/android_definitions.py b/.circleci/cimodel/data/simple/android_definitions.py index 2af680492b93..3c729ad6e7a6 100644 --- a/.circleci/cimodel/data/simple/android_definitions.py +++ b/.circleci/cimodel/data/simple/android_definitions.py @@ -97,13 +97,13 @@ WORKFLOW_DATA = [ is_master_only=False, is_pr_only=True), AndroidGradleJob( - "pytorch-linux-xenial-py3-clang5-android-ndk-r19c-gradle-custom-build-single_lite_interpreter", + "pytorch-linux-xenial-py3-clang5-android-ndk-r19c-gradle-custom-build-single-full-jit", "pytorch_android_gradle_custom_build_single", [DOCKER_REQUIREMENT_NDK], is_master_only=False, is_pr_only=True, extra_props=tuple({ - "lite_interpreter": miniutils.quote(str(int(True))) + "lite_interpreter": miniutils.quote(str(int(False))) }.items())), AndroidGradleJob( "pytorch-linux-xenial-py3-clang5-android-ndk-r19c-gradle-build", diff --git a/.circleci/config.yml b/.circleci/config.yml index 99073a330955..a3930d4103f1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6534,8 +6534,8 @@ workflows: only: - /gh\/.*\/head/ - /pull\/.*/ - lite_interpreter: "1" - name: pytorch-linux-xenial-py3-clang5-android-ndk-r19c-gradle-custom-build-single_lite_interpreter + lite_interpreter: "0" + name: pytorch-linux-xenial-py3-clang5-android-ndk-r19c-gradle-custom-build-single-full-jit requires: - docker-pytorch-linux-xenial-py3-clang5-android-ndk-r19c - pytorch_android_gradle_build: diff --git a/android/pytorch_android/CMakeLists.txt b/android/pytorch_android/CMakeLists.txt index e0d4876194d0..4d1bf714a45f 100644 --- a/android/pytorch_android/CMakeLists.txt +++ b/android/pytorch_android/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.4.1) -option(BUILD_LITE_INTERPRETER "Master flag to build pytorch_jni_lite" OFF) +option(BUILD_LITE_INTERPRETER "Master flag to build pytorch_jni_lite" ON) message( STATUS "BUILD_LITE_INTERPRETER (pytorch_jni_lite): ${BUILD_LITE_INTERPRETER}") diff --git a/android/pytorch_android/build.gradle b/android/pytorch_android/build.gradle index 202d16e65f7b..978389cbd242 100644 --- a/android/pytorch_android/build.gradle +++ b/android/pytorch_android/build.gradle @@ -17,8 +17,8 @@ android { } externalNativeBuild { cmake { - if(System.env.BUILD_LITE_INTERPRETER == '1') { - arguments "-DANDROID_STL=c++_shared", "-DBUILD_LITE_INTERPRETER=ON" + if(System.env.BUILD_LITE_INTERPRETER == '0') { + arguments "-DANDROID_STL=c++_shared", "-DBUILD_LITE_INTERPRETER=OFF" } else { arguments "-DANDROID_STL=c++_shared" } @@ -37,12 +37,12 @@ android { sourceSets { main { java { - if(System.env.BUILD_LITE_INTERPRETER == '1') { - println 'Build pytorch_jni_lite' - } else { + if(System.env.BUILD_LITE_INTERPRETER == '0') { println 'Build pytorch_jni' exclude 'org/pytorch/LiteModuleLoader.java' exclude 'org/pytorch/LiteNativePeer.java' + } else { + println 'Build pytorch_jni_lite' } } jniLibs.srcDirs = ['src/main/jniLibs'] diff --git a/android/pytorch_android/src/main/java/org/pytorch/PyTorchAndroid.java b/android/pytorch_android/src/main/java/org/pytorch/PyTorchAndroid.java index b775c2bb2e2c..becfbfbd0ba6 100644 --- a/android/pytorch_android/src/main/java/org/pytorch/PyTorchAndroid.java +++ b/android/pytorch_android/src/main/java/org/pytorch/PyTorchAndroid.java @@ -10,7 +10,7 @@ public final class PyTorchAndroid { if (!NativeLoader.isInitialized()) { NativeLoader.init(new SystemDelegate()); } - NativeLoader.loadLibrary("pytorch_jni"); + NativeLoader.loadLibrary("pytorch_jni_lite"); PyTorchCodegenLoader.loadNativeLibs(); } diff --git a/scripts/build_android.sh b/scripts/build_android.sh index 90f8f925dc8d..daad46e8fbbc 100755 --- a/scripts/build_android.sh +++ b/scripts/build_android.sh @@ -104,12 +104,13 @@ fi CMAKE_ARGS+=("-DBUILD_TEST=OFF") CMAKE_ARGS+=("-DBUILD_BINARY=OFF") -# If there exists env variable and it equals to 1, build lite interpreter. -# cmd: BUILD_LITE_INTERPRETER=1 ./scripts/build_android.sh -if [ "${BUILD_LITE_INTERPRETER}" == 1 ]; then - CMAKE_ARGS+=("-DBUILD_LITE_INTERPRETER=ON") -else +# If there exists env variable and it equals to 0, build full jit interpreter. +# Default behavior is to build lite interpreter +# cmd: BUILD_LITE_INTERPRETER=0 ./scripts/build_android.sh +if [ "${BUILD_LITE_INTERPRETER}" == 0 ]; then CMAKE_ARGS+=("-DBUILD_LITE_INTERPRETER=OFF") +else + CMAKE_ARGS+=("-DBUILD_LITE_INTERPRETER=ON") fi CMAKE_ARGS+=("-DBUILD_MOBILE_BENCHMARK=$BUILD_MOBILE_BENCHMARK") CMAKE_ARGS+=("-DBUILD_MOBILE_TEST=$BUILD_MOBILE_TEST") diff --git a/tools/lite_interpreter/__init__.py b/tools/lite_interpreter/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1