From 9c0625b0045ad0a304cde52027b40dffc690ecd0 Mon Sep 17 00:00:00 2001 From: Tao Xu Date: Fri, 14 Feb 2020 13:59:38 -0800 Subject: [PATCH] [iOS] Add watchOS support (#33318) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/33318 ### Summary Recently, we have a [discussion](https://discuss.pytorch.org/t/libtorch-on-watchos/69073/14) in the forum about watchOS. This PR adds the support for building watchOS libraries. ### Test Plan - `BUILD_PYTORCH_MOBILE=1 IOS_PLATFORM=WATCHOS ./scripts/build_ios.sh` Test Plan: Imported from OSS Differential Revision: D19896534 Pulled By: xta0 fbshipit-source-id: 7b9286475e895d9fefd998246e7090ac92c4c9b6 --- CMakeLists.txt | 1 - cmake/Summary.cmake | 1 + cmake/iOS.cmake | 2 +- scripts/build_ios.sh | 6 ++++++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8904ad153f6..1667d7be518 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -343,7 +343,6 @@ if (INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE) set(FEATURE_TORCH_MOBILE ON) set(NO_API ON) set(USE_FBGEMM OFF) - set(USE_PYTORCH_QNNPACK ON) set(USE_QNNPACK OFF) set(INTERN_DISABLE_ONNX ON) set(INTERN_DISABLE_AUTOGRAD ON) diff --git a/cmake/Summary.cmake b/cmake/Summary.cmake index 537ac473278..83fa7bdd371 100644 --- a/cmake/Summary.cmake +++ b/cmake/Summary.cmake @@ -122,6 +122,7 @@ function (caffe2_print_configuration_summary) message(STATUS " USE_TBB : ${USE_TBB}") message(STATUS " USE_PROF : ${USE_PROF}") message(STATUS " USE_QNNPACK : ${USE_QNNPACK}") + message(STATUS " USE_PYTORCH_QNNPACK : ${USE_PYTORCH_QNNPACK}") message(STATUS " USE_REDIS : ${USE_REDIS}") message(STATUS " USE_ROCKSDB : ${USE_ROCKSDB}") message(STATUS " USE_ZMQ : ${USE_ZMQ}") diff --git a/cmake/iOS.cmake b/cmake/iOS.cmake index b838a918ef7..c97eaba903a 100644 --- a/cmake/iOS.cmake +++ b/cmake/iOS.cmake @@ -162,7 +162,7 @@ if (IOS_PLATFORM STREQUAL "OS") elseif (IOS_PLATFORM STREQUAL "SIMULATOR") set (DEFAULT_IOS_ARCH "x86_64") elseif (IOS_PLATFORM STREQUAL "WATCHOS") - set (DEFAULT_IOS_ARCH "armv7k") + set (DEFAULT_IOS_ARCH "armv7k;arm64_32") endif () set (IOS_ARCH ${DEFAULT_IOS_ARCH} CACHE string "Build architecture for iOS") diff --git a/scripts/build_ios.sh b/scripts/build_ios.sh index 6edccfbf8ae..f40988822f6 100755 --- a/scripts/build_ios.sh +++ b/scripts/build_ios.sh @@ -64,6 +64,12 @@ if [ -n "${IOS_PLATFORM:-}" ]; then if [ "${IOS_PLATFORM}" == "SIMULATOR" ]; then # iOS Simulator build is not supported by NNPACK CMAKE_ARGS+=("-DUSE_NNPACK=OFF") + elif [ "${IOS_PLATFORM}" == "WATCHOS" ]; then + # enable bitcode by default for watchos + CMAKE_ARGS+=("-DCMAKE_C_FLAGS=-fembed-bitcode") + CMAKE_ARGS+=("-DCMAKE_CXX_FLAGS=-fembed-bitcode") + # disable the QNNPACK + CMAKE_ARGS+=("-DUSE_PYTORCH_QNNPACK=OFF") fi else # IOS_PLATFORM is not set, default to OS, which builds iOS.