Skip to content

Commit

Permalink
[Pytorch] Build lite interpreter as default for Android
Browse files Browse the repository at this point in the history
Summary:
Build lite interpreter as default for android, should wait until #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
  • Loading branch information
cccclai authored and facebook-github-bot committed May 17, 2021
1 parent d645088 commit 0c3db1c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .circleci/cimodel/data/simple/android_definitions.py
Expand Up @@ -97,13 +97,13 @@ def gen_tree(self):
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",
Expand Down
4 changes: 2 additions & 2 deletions .circleci/config.yml
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion 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}")
Expand Down
10 changes: 5 additions & 5 deletions android/pytorch_android/build.gradle
Expand Up @@ -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"
}
Expand All @@ -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']
Expand Down
Expand Up @@ -10,7 +10,7 @@ public final class PyTorchAndroid {
if (!NativeLoader.isInitialized()) {
NativeLoader.init(new SystemDelegate());
}
NativeLoader.loadLibrary("pytorch_jni");
NativeLoader.loadLibrary("pytorch_jni_lite");

This comment has been minimized.

Copy link
@H1Gdev

H1Gdev May 24, 2021

Contributor

@cccclai
Excuse me for interrupting.

By changing library to read, the following methods now throw an exception.

  • loadModuleFromAsset

NativePeer class expects pytorch_jni.

PyTorchCodegenLoader.loadNativeLibs();
}

Expand Down
11 changes: 6 additions & 5 deletions scripts/build_android.sh
Expand Up @@ -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")
Expand Down
Empty file.

0 comments on commit 0c3db1c

Please sign in to comment.