Commit Graph

33 Commits

Author SHA1 Message Date
Ivan Kobzarev
0891764e80 [android] ANDROID_STL=c++_shared (#39588)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39588

Before this diff we used c++_static linking.
Users will dynamically link to libpytorch_jni.so and have at least one more their own shared library that probably uses stl library.

We must have not more than one stl per app. ( https://developer.android.com/ndk/guides/cpp-support#one_stl_per_app )

To have only one stl per app changing ANDROID_STL way to  c++_shared, that will add libc++_shared.so to packaging.

Test Plan: Imported from OSS

Differential Revision: D22118031

Pulled By: IvanKobzarev

fbshipit-source-id: ea1e5085ae207a2f42d1fa9f6ab8ed0a21768e96
2020-06-18 13:50:05 -07:00
Ivan Kobzarev
928e99b9bb [vulkan] jni build support USE_VULKAN (#39188)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39188

Extracting Vulkan_LIBS and Vulkan_INCLUDES setup from `cmake/Dependencies.cmake` to `cmake/VulkanDependencies.cmake` and reuse it in android/pytorch_android/CMakeLists.txt

Adding control to build with Vulkan setting env variable `USE_VULKAN` for `scripts/build_android.sh` `scripts/build_pytorch_android.sh`

We do not use Vulkan backend in pytorch_android, but with this build option we can track android aar change with `USE_VULKAN` added.

Currently it is 88Kb.

Test Plan: Imported from OSS

Differential Revision: D21770892

Pulled By: IvanKobzarev

fbshipit-source-id: a39433505fdcf43d3b524e0fe08062d5ebe0d872
2020-05-28 15:39:02 -07:00
Gemfield
70f3298684 Fix SELECTED_OP_LIST file path issue (#33942)
Summary:
If SELECTED_OP_LIST is specified as a relative path in command line, CMake build will fail.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/33942

Differential Revision: D20392797

Pulled By: ljk53

fbshipit-source-id: dffeebc48050970e286cf263bdde8b26d8fe4bce
2020-03-11 13:19:31 -07:00
Jiakai Liu
9a5e9d8cec [pytorch][mobile] change mobile build scripts to build PyTorch by default (#34203)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/34203

Currently cmake and mobile build scripts still build libcaffe2 by
default. To build pytorch mobile users have to set environment variable
BUILD_PYTORCH_MOBILE=1 or set cmake option BUILD_CAFFE2_MOBILE=OFF.

PyTorch mobile has been released for a while. It's about time to change
CMake and build scripts to build libtorch by default.

Changed caffe2 CI job to build libcaffe2 by setting BUILD_CAFFE2_MOBILE=1
environment variable. Only found android CI for libcaffe2 - do we ever
have iOS CI for libcaffe2?

Test Plan: Imported from OSS

Differential Revision: D20267274

Pulled By: ljk53

fbshipit-source-id: 9d997032a599c874d62fbcfc4f5d4fbf8323a12e
2020-03-05 23:40:47 -08:00
Jiakai Liu
43fb0015db custom build script (#30144)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/30144

Create script to produce libtorch that only contains ops needed by specific
models. Developers can use this workflow to further optimize mobile build size.

Need keep a dummy stub for unused (stripped) ops because some JIT side
logic requires certain function schemas to be existed in the JIT op
registry.

Test Steps:
1. Build "dump_operator_names" binary and use it to dump root ops needed
by a specific model:
```
build/bin/dump_operator_names --model=mobilenetv2.pk --output=mobilenetv2.yaml
```

2. The MobileNetV2 model should use the following ops:
```
- aten::t
- aten::dropout
- aten::mean.dim
- aten::add.Tensor
- prim::ListConstruct
- aten::addmm
- aten::_convolution
- aten::batch_norm
- aten::hardtanh_
- aten::mm
```
NOTE that for some reason it outputs "aten::addmm" but actually uses "aten::mm".
You need fix it manually for now.

3. Run custom build script locally (use Android as an example):
```
SELECTED_OP_LIST=mobilenetv2.yaml scripts/build_pytorch_android.sh armeabi-v7a
```

4. Checkout demo app that uses locally built library instead of
downloading from jcenter repo:
```
git clone --single-branch --branch custom_build git@github.com:ljk53/android-demo-app.git
```

5. Copy locally built libraries to demo app folder:
```
find ${HOME}/src/pytorch/android -name '*.aar' -exec cp {} ${HOME}/src/android-demo-app/HelloWorldApp/app/libs/ \;
```

6. Build demo app with locally built libtorch:
```
cd ${HOME}/src/android-demo-app/HelloWorldApp
./gradlew clean && ./gradlew assembleDebug
```

7. Install and run the demo app.

In-APK arm-v7 libpytorch_jni.so build size reduced from 5.5M to 2.9M.

Test Plan: Imported from OSS

Differential Revision: D18612127

Pulled By: ljk53

fbshipit-source-id: fa8d5e1d3259143c7346abd1c862773be8c7e29a
2019-11-20 13:16:02 -08:00
Jiakai Liu
9371b31818 set USE_STATIC_DISPATCH outside cmake (#29715)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/29715

Previous we hard code it to enable static dispatch when building mobile
library. Since we are exploring approaches to deprecate static dispatch
we should make it optional. This PR moved the setting from cmake to bash
build scripts which can be overridden.

Test Plan: - verified it's still using static dispatch when building with these scripts.

Differential Revision: D18474640

Pulled By: ljk53

fbshipit-source-id: 7591acc22009bfba36302e3b2a330b1428d8e3f1
2019-11-14 20:41:29 -08:00
Ivan Kobzarev
92b9de1428 Test application for profiling, CMake params for debug symbols (#28406)
Summary:
Reason:
To have one-step build for test android application based on the current code state that is ready for profiling with simpleperf, systrace etc. to profile performance inside the application.

## Parameters to control debug symbols stripping
Introducing  /CMakeLists parameter `ANDROID_DEBUG_SYMBOLS` to be able not to strip symbols for pytorch (not add linker flag `-s`)
which is checked in `scripts/build_android.sh`

On gradle side stripping happens by default, and to prevent it we have to specify
```
android {
  packagingOptions {
       doNotStrip "**/*.so"
  }
}
```
which is now controlled by new gradle property `nativeLibsDoNotStrip `

## Test_App
`android/test_app` - android app with one MainActivity that does inference in cycle

`android/build_test_app.sh` - script to build libtorch with debug symbols for specified android abis and adds `NDK_DEBUG=1` and `-PnativeLibsDoNotStrip=true` to keep all debug symbols for profiling.
Script assembles all debug flavors:
```
└─ $ find . -type f -name *apk
./test_app/app/build/outputs/apk/mobilenetQuant/debug/test_app-mobilenetQuant-debug.apk
./test_app/app/build/outputs/apk/resnet/debug/test_app-resnet-debug.apk
```

## Different build configurations

Module for inference can be set in `android/test_app/app/build.gradle` as a BuildConfig parameters:
```
    productFlavors {
        mobilenetQuant {
            dimension "model"
            applicationIdSuffix ".mobilenetQuant"
            buildConfigField ("String", "MODULE_ASSET_NAME", buildConfigProps('MODULE_ASSET_NAME_MOBILENET_QUANT'))
            addManifestPlaceholders([APP_NAME: "PyMobileNetQuant"])
            buildConfigField ("String", "LOGCAT_TAG", "\"pytorch-mobilenet\"")
        }
        resnet {
            dimension "model"
            applicationIdSuffix ".resnet"
            buildConfigField ("String", "MODULE_ASSET_NAME", buildConfigProps('MODULE_ASSET_NAME_RESNET18'))
            addManifestPlaceholders([APP_NAME: "PyResnet"])
            buildConfigField ("String", "LOGCAT_TAG", "\"pytorch-resnet\"")
        }
```

In that case we can setup several apps on the same device for comparison, to separate packages `applicationIdSuffix`: 'org.pytorch.testapp.mobilenetQuant' and different application names and logcat tags as `manifestPlaceholder` and another BuildConfig parameter:
```
─ $ adb shell pm list packages | grep pytorch
package:org.pytorch.testapp.mobilenetQuant
package:org.pytorch.testapp.resnet
```

In future we can add another BuildConfig params e.g. single/multi threads and other configuration for profiling.

At the moment 2 flavors - for resnet18 and for mobilenetQuantized
which can be installed on connected device:

```
cd android
```
```
gradle test_app:installMobilenetQuantDebug
```
```
gradle test_app:installResnetDebug
```

## Testing:
```
cd android
sh build_test_app.sh
adb install -r test_app/app/build/outputs/apk/mobilenetQuant/debug/test_app-mobilenetQuant-debug.apk
```

```
cd $ANDROID_NDK
python simpleperf/run_simpleperf_on_device.py record --app org.pytorch.testapp.mobilenetQuant -g --duration 10 -o /data/local/tmp/perf.data
adb pull /data/local/tmp/perf.data
python simpleperf/report_html.py
```

Simpleperf report has all symbols:
![Screenshot 2019-10-22 11 06 21](https://user-images.githubusercontent.com/6638825/67315740-0bc50100-f4bc-11e9-8f9e-2499be13d63e.png)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28406

Differential Revision: D18386622

Pulled By: IvanKobzarev

fbshipit-source-id: 3a751192bbc4bc3c6d7f126b0b55086b4d586e7a
2019-11-08 14:19:04 -08:00
Jiakai Liu
16c1907830 update build_android.sh to not build host protoc for libtorch (#25896)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/25896

Similar change as PR #25822.

Test Plan:
- Updated CI to use the new script.
- Will check pytorch android CI output to make sure it builds libtorch
  instead of libcaffe2.

Reviewed By: dreiss

Differential Revision: D17279722

Pulled By: ljk53

fbshipit-source-id: 93abcef0dfb93df197fabff29e53d71db5674255
2019-09-10 15:19:43 -07:00
Thomas Viehmann
3ac4d92824 tweak scripts/build_android.sh for ABI and header install (#20152)
Summary:
We now can build libtorch for Android.
This patch aims to provide two improvements to the build
- Make the architecture overridable by providing an environment variable `ANDROID_ABI`.
- Use `--target install` when calling cmake to actually get the header files nicely in one place.

I ran the script without options to see if the caffe2 builds are affected (in particularly by the install), but they seem to run OK and probably only produce a few files in build_android/install.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/20152

Differential Revision: D15249020

Pulled By: pjh5

fbshipit-source-id: bc89f1dcadce36f63dc93f9249cba90a7fc9e93d
2019-05-07 17:44:07 -07:00
Jiakai Liu
0c5d444b28 change to use clang if NDK >= 18 (#18914)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18914
ghimport-source-id: 4d9d9322ee5559d96e13533ec37ff3be86a0227c

Reviewed By: ezyang

Differential Revision: D14794162

Pulled By: ljk53

fbshipit-source-id: caac55e12b1e62bf6ebcc6e2062d5ed122ad4e64
2019-04-05 10:02:03 -07:00
Gemfield
c3a23379ea add install step and docs for Android build (#17298)
Summary:
This commit did below enhancements:
1, add doc for build_android.sh;
2, add install step for build_android.sh, thus the headers and libraries can be collected together for further usage conveniently;
3, change the default INSTALL_PREFIX from $PYTORCH_ROOT/install to $PYTORCH_ROOT/build_android/install to make the project directory clean.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17298

Differential Revision: D14149709

Pulled By: soumith

fbshipit-source-id: a3a38cb41f26377e21aa89e49e57e8f21c9c1a39
2019-02-20 07:05:24 -08:00
Jerry Zhang
12cf5178aa caffe2 mobile opengl (#15322)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15322

caffe2 mobile opengl code is not used, deleting it to reduce complications when we perform other changes

Reviewed By: Maratyszcza

Differential Revision: D13499943

fbshipit-source-id: 6479f6b9f50f08b5ae28f8f0bc4a1c4fc3f3c3c2
2018-12-18 08:20:52 -08:00
Will Feng
c9e66351a7 Port all PyTorch and Caffe2 jobs to CircleCI (#11264)
Summary:
This PR adds all PyTorch and Caffe2 job configs to CircleCI.

Steps for the CircleCI mini-trial:
- [ ] Make sure this PR passes Jenkins CI and fbcode internal tests
- [x] Approve this PR
- [ ] Ask CircleCI to turn up the number of build machines
- [ ] Land this PR so that the new `.circleci/config.yml` will take effect

Several Caffe2 tests are flaky on CircleCI machines and hence skipped when running on CircleCI. A proper fix for them will be worked on after a successful mini-trial.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/11264

Differential Revision: D9656793

Pulled By: yf225

fbshipit-source-id: 7832e90018f3dff7651489c04a179d6742168fe1
2018-09-05 16:28:11 -07:00
Marat Dukhan
bbc2c642c9 Use Ninja build system when available
When Ninja is installed, use it instead of Make for native builds and for Android cross-builds.
2018-03-07 20:49:30 -05:00
Marat Dukhan
fc7ee0c941 Use NEON for Android build 2018-03-03 01:04:56 +01:00
Koan-Sin Tan
72d5d9016a move -s to CMakeLists.txt 2018-03-02 20:31:33 +01:00
Koan-Sin Tan
ca90d4c356 Add -s for Android back
Android libraries are statically linked, we'd better strip binaries
2018-03-02 20:31:33 +01:00
Marat Dukhan
e07083f00a Cleanup CMake files and build scripts for Android (#2067)
- Remove USE_ARM64 option because it doesn't do what is expected
- Disable ARM ComputeLibrary for non-ARM/ARM64 builds
- Remove analysis of CMake options from scripts/build_android.sh
- Add user-specified CMake options at the end of command line to allow overriding defaults
- Update README for ARM ComputeLibrary integration and do not require to disable NNPACK for ARM64 build with ARM ComputeLibrary
2018-02-27 16:05:21 -08:00
Jerry Zhang
c0866e45c7 Caffe2 ARM ComputeLibrary integration (#2015)
Caffe2 ARM Compute Library Integration
2018-02-23 18:09:05 -08:00
Zhiyong Dang
4d656842d9 enable USE_MOBILE_OPENGL by default
Summary:
iOS is also depend on USE_MOBILE_OPENGL, so I think we should only disable it for Android.
Closes https://github.com/caffe2/caffe2/pull/1835

Differential Revision: D6880522

Pulled By: Maratyszcza

fbshipit-source-id: b2c2fa052ad5948bc52fa49eb22c86eb08f59a39
2018-02-01 18:57:38 -08:00
Zhiyong Dang
c3596c2dfa remove "-s" compilation flag from clang when build for Android
Summary:
Now we use **clang** to build Caffe2 for Android with arm64-v8a ABI, but clang doesn't support "-s" compilation flag. If we append this flag to clang, it will report a warning:

> clang++: warning: argument unused during compilation: '-s' [-Wunused-command-line-argument]

This submit will check we use gcc or clang to build Caffe2 for Android.
Closes https://github.com/caffe2/caffe2/pull/1834

Differential Revision: D6833011

Pulled By: Yangqing

fbshipit-source-id: e4655d126fb3586e7af605a31a6b1c1ed66b9bcb
2018-01-29 00:03:02 -08:00
Yangqing Jia
73ed0d5ced Modernizing the gflags dependency in cmake.
Summary:
Historically, for interface dependent libraries (glog, gflags and protobuf), exposing them in Caffe2Config.cmake is usually difficult.

New versions of glog and gflags ship with new-style cmake targets, so one does not need to use variables. New-style targets also make it easier for people to depend on them in installed config files.

This diff modernizes the gflags library, and still provides a fallback path if the installed gflags does not have cmake config files coming with it.

It does change one behavior of the build process though - when one specifies -DUSE_GFLAGS=ON but gflags cannot be found, the old script automatically turns it off but the new script crashes, forcing the user to specify USE_GFLAGS=OFF.
Closes https://github.com/caffe2/caffe2/pull/1819

Differential Revision: D6826604

Pulled By: Yangqing

fbshipit-source-id: 210f3926f291c8bfeb24eb9671e5adfcbf8cf7fe
2018-01-27 19:31:14 -08:00
Marat Dukhan
a7ef4e4d46 Use android.cmake.toolchain from Android NDK
Summary:
The android.cmake.toolchain file we use from a submodule is unmaintained and not updated since 2015.
It causes numerous problems in Caffe2 build:
- Caffe2 can't be built for Android ARM64, because gcc toolchain for ARM64 doesn't support NEON-FP16 intrinsics, and the android.cmake.toolchain we use doesn't allow us specify clang-5.0 from NDK r15c
- Caffe2 can't be built with Android NDK r16 (the most recent NDK version)
- Caffe2 can't be built for Android with Ninja generator

This change updates the build script to use $ANDROID/build/cmake/android.cmake.toolchain instead, which is maintained by Android team, and synchronized with Android NDK version.
As this toolchain file doesn't support "armeabi-v7a with NEON FP16" ABI, I had to disable mobile OpenGL backend, which requires NEON-FP16 extension to build. With some work, it can be re-enabled in the future.
Closes https://github.com/caffe2/caffe2/pull/1740

Differential Revision: D6707099

Pulled By: Maratyszcza

fbshipit-source-id: 8488594c4225deed0323c1e54c8d71c804b328df
2018-01-23 11:32:41 -08:00
Fei Sun
47de6f47f3 Use GCC to compile Android Caffe2
Summary:
It seems GCC performs better. Always use it to compile.
Closes https://github.com/caffe2/caffe2/pull/1725

Reviewed By: Yangqing

Differential Revision: D6690581

Pulled By: sf-wind

fbshipit-source-id: 3fceb25fc081bd4f875e914a0465b959c7fd5eda
2018-01-10 13:09:14 -08:00
Pieter Noordhuis
b3e5166d4c Run build_android.sh in Jenkins
Summary: Closes https://github.com/caffe2/caffe2/pull/1479

Differential Revision: D6386248

Pulled By: pietern

fbshipit-source-id: ac4ce163c164a49aa83e2c7015003763bc2fd0e7
2017-11-21 15:53:38 -08:00
Junjie Bai
303ed8af44 Allow specifying cmake build directory in the build scripts
Summary: Closes https://github.com/caffe2/caffe2/pull/1496

Reviewed By: pietern

Differential Revision: D6379743

Pulled By: bddppq

fbshipit-source-id: 1cb2238e5708547767729de3ac1d3e1a76ed5ba1
2017-11-20 20:32:30 -08:00
Pieter Noordhuis
9575364d30 Update protobuf detection
Summary:
The scripts/build_local.sh script would always build protoc from the
third_party protobuf tree and override the PROTOBUF_PROTOC_EXECUTABLE
CMake variable. This variable is used by the protobuf CMake files, so
it doesn't let us detect whether the protoc was specified by the user
or by the protobuf CMake files (e.g. an existing installation). This
in turn led to a problem where system installed headers would be
picked up while using protoc built from third_party. This only works
if the system installed version matches the version included in the
Caffe2 tree. Therefore, this commit changes the variable to specify a
custom protoc executable to CAFFE2_CUSTOM_PROTOC_EXECUTABLE, and
forces the use of the bundled libprotobuf when it is specified.

The result is that we now EITHER specify a custom protoc (as required
for cross-compilation where protoc must be compiled for the host and
libprotobuf for the target architecture) and use libprotobuf from the
Caffe2 tree, OR use system protobuf.

If system protobuf cannot be found, we fall back to building protoc
and libprotobuf in tree and packaging it as part of the Caffe2 build
artifacts.
Closes https://github.com/caffe2/caffe2/pull/1328

Differential Revision: D6032836

Pulled By: pietern

fbshipit-source-id: b75f8dd88412f02c947dc81ca43f7b2788da51e5
2017-10-12 11:48:50 -07:00
Yangqing Jia
5e0d434b4b Add build support for opengl and latest nnpack.
Summary:
(1) Changed android-cmake to use Yangqing/android-cmake, which supports NEON fp16.
(2) Added cmake scripts to build opengl.
(3) Updated nnpack to master, and changed the corresponding build files.
Closes https://github.com/caffe2/caffe2/pull/1061

Differential Revision: D5591387

Pulled By: Yangqing

fbshipit-source-id: 1d3f28511d33c09df6ecef5041448ac9a3246601
2017-08-09 00:31:53 -07:00
Luke Yeager
fda35fd19d TravisCI Overhaul
Summary:
Uncached build: https://travis-ci.org/lukeyeager/caffe2/builds/239677224
Cached build: https://travis-ci.org/lukeyeager/caffe2/builds/239686725

* Parallel builds everywhere
* All builds use CCache for quick build times (help from https://github.com/pytorch/pytorch/pull/614, https://github.com/ccache/ccache/pull/145)
* Run ctests when available (continuation of https://github.com/caffe2/caffe2/pull/550)
* Upgraded from cuDNN v5 to v6
* Fixed MKL build (by updating pkg version)
* Fixed android builds (b6f905a67b (commitcomment-22404119))

* ~~Building NNPACK fails with no discernible error message (currently disabled entirely)~~
* ~~Android builds continue to fail with existing error:~~
* ~~OSX builds time-out:~~

| Before | After | Changes |
| --- | --- | --- |
| COMPILER=g++ | linux | without CUDA |
| COMPILER=g++-5 | linux-gcc5 | without CUDA |
| COMPILER=g++ | linux-cuda | updated to cuDNN v6 |
| BLAS=MKL | linux-mkl | updated pkg version |
| BUILD_TARGET=android | linux-android | |
| COMPILER=clang++ | osx | |
| BUILD_TARGET=ios | osx-ios | |
| BUILD_TARGET=android | osx-android | |
| QUICKTEST | **GONE** | |
| COMPILER=g++-4.8 | **GONE** | |
| COMPILER=g++-4.9 | **GONE** | |
Closes https://github.com/caffe2/caffe2/pull/735

Reviewed By: Yangqing

Differential Revision: D5228966

Pulled By: bwasti

fbshipit-source-id: 6cfa6f5ff05fbd5c2078beea79564f1f3b9812fe
2017-06-16 10:18:05 -07:00
Arron Cao
7c3add4408 better android ndk path
Summary:
use user defined android ndk path instead of hard code.
Closes https://github.com/caffe2/caffe2/pull/506

Differential Revision: D5162646

Pulled By: Yangqing

fbshipit-source-id: 5093888e15607b3bf6682e05eb91aa94c6206b01
2017-05-31 20:35:23 -07:00
Bram Wasti
c101856214 Disable openmp when building for android
Summary: Closes https://github.com/caffe2/caffe2/pull/256

Reviewed By: salexspb

Differential Revision: D4853865

Pulled By: bwasti

fbshipit-source-id: 57768d538281bec2b18d8c6af7ae58009bbc257e
2017-04-07 14:35:01 -07:00
Yangqing Jia
3a82b33f84 Use protobuf's own cmake scripts and add travis for ios
Summary: Closes https://github.com/caffe2/caffe2/pull/110

Differential Revision: D4475170

Pulled By: Yangqing

fbshipit-source-id: 5964db04186619ac563f516cb202c5e2ba543403
2017-01-28 13:29:32 -08:00
Yangqing Jia
01e860505b Cmake for android
Summary:
Added cmake for android script under scripts, and set up the travis contbuild target.
Closes https://github.com/caffe2/caffe2/pull/109

Reviewed By: bwasti

Differential Revision: D4468767

Pulled By: Yangqing

fbshipit-source-id: 709f3eb6be24727b0a989d0901dbf377871b122a
2017-01-26 18:14:30 -08:00