Enable QNNPACK for iOS (#24030)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/24030

The cmake arg - `USE_QNNPACK` was disabled for iOS build due to its lack of support for building multiple archs(armv7;armv7s;arm64) simultaneously.To enable it, we need to specify the value of IOS_ARCH explicitly in the build command:

```
./scripts/build_ios.sh \
-DIOS_ARCH=arm64 \
-DBUILD_CAFFE2_MOBILE=OFF \
```
However,the iOS.cmake will overwirte this value according to the value of `IOS_PLATFORM`. This PR is a fix to this problem.

Test Plan:
- `USE_QNNPACK` should be turned on by cmake.
- `libqnnpack.a` can be generated successfully.
- `libortch.a` can be compiled and run successfully on iOS devices.

<img src="https://github.com/xta0/AICamera-ObjC/blob/master/aicamera.gif?raw=true" width="400">

Differential Revision: D16771014

Pulled By: xta0

fbshipit-source-id: 4cdfd502cb2bcd29611e4c22e2efdcdfe9c920d3
This commit is contained in:
Tao Xu
2019-08-13 21:08:02 -07:00
committed by Facebook Github Bot
parent e94ba742b0
commit 514285890c
2 changed files with 4 additions and 11 deletions

View File

@ -159,13 +159,14 @@ set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS su
# set the architecture for iOS
if (IOS_PLATFORM STREQUAL "OS")
set (IOS_ARCH "armv7;armv7s;arm64")
set (DEFAULT_IOS_ARCH "armv7;armv7s;arm64")
elseif (IOS_PLATFORM STREQUAL "SIMULATOR")
set (IOS_ARCH "i386;x86_64")
set (DEFAULT_IOS_ARCH "i386;x86_64")
elseif (IOS_PLATFORM STREQUAL "WATCHOS")
set (IOS_ARCH "armv7k")
set (DEFAULT_IOS_ARCH "armv7k")
endif ()
set (IOS_ARCH ${DEFAULT_IOS_ARCH} CACHE string "Build architecture for iOS")
set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS")
# Set the find root to the iOS developer roots and to user defined paths

View File

@ -45,14 +45,6 @@ else
CMAKE_ARGS+=("-DIOS_PLATFORM=OS")
fi
# IOS_ARCH controls type of iOS architecture (see ios-cmake)
if [ -n "${IOS_ARCH:-}" ]; then
CMAKE_ARGS+=("-DIOS_ARCH=${IOS_ARCH}")
else
# IOS_ARCH is not set, default to arm64
CMAKE_ARGS+=("-DIOS_ARCH=arm64")
fi
# Don't build binaries or tests (only the library)
CMAKE_ARGS+=("-DBUILD_TEST=OFF")
CMAKE_ARGS+=("-DBUILD_BINARY=OFF")