Summary: Currently, build_mobile.sh doesn't allow lite interpreter builds or tracing based selective builds. build_mobile.sh is used for host builds of PyTorch for Mobile deployment. Additionally, certain flags such as `USE_BLAS` were not being respected as they should be. This change addresses that as well. Test Plan: Build using: ``` cat /tmp/selected_ops.yaml - aten::add - aten::sub ``` ``` BUILD_PYTORCH_MOBILE_WITH_HOST_TOOLCHAIN=1 USE_LIGHTWEIGHT_DISPATCH=0 BUILD_LITE_INTERPRETER=1 SELECTED_OP_LIST=/tmp/selected_ops.yaml ./scripts/build_mobile.sh ``` ``` cat /tmp/main.cpp int main() { auto m = torch::jit::_load_for_mobile("/tmp/path_to_model.ptl"); auto res = m.forward({}); return 0; } ``` Test using: ``` g++ /tmp/main.cpp -L build_mobile/lib/ -I build_mobile/install/include/ -lpthread -lc10 -ltorch_cpu -ltorch -lXNNPACK -lpytorch_qnnpack -lcpuinfo -lclog -lpthreadpool -lgloo -lkineto -lfmt -ldl -lc10 ``` Reviewers: Subscribers: Tasks: Tags: Pull Request resolved: https://github.com/pytorch/pytorch/pull/84647 Approved by: https://github.com/JacobSzwejbka, https://github.com/cccclai
This directory contains the useful tools.
build_android.sh
This script is to build PyTorch/Caffe2 library for Android. Take the following steps to start the build:
- set ANDROID_NDK to the location of ndk
export ANDROID_NDK=YOUR_NDK_PATH
- run build_android.sh
#in your PyTorch root directory
bash scripts/build_android.sh
If succeeded, the libraries and headers would be generated to build_android/install directory. You can then copy these files from build_android/install to your Android project for further usage.
You can also override the cmake flags via command line, e.g., following command will also compile the executable binary files:
bash scripts/build_android.sh -DBUILD_BINARY=ON
build_ios.sh
This script is to build PyTorch/Caffe2 library for iOS, and can only be performed on macOS. Take the following steps to start the build:
- Install Xcode from App Store, and configure "Command Line Tools" properly on Xcode.
- Install the dependencies:
brew install cmake automake libtool
- run build_ios.sh
#in your PyTorch root directory
bash scripts/build_ios.sh
If succeeded, the libraries and headers would be generated to build_ios/install directory. You can then copy these files to your Xcode project for further usage.