Skip to content

Commit

Permalink
Fix iOS simulator build (pytorch#25633)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#25633

The iOS simulator build (x86_64) is broken right now. To fix it:

1. Fix the bug in iOS.cmake
2. Disable avx2 for mobile x86_64 build

Test Plan:
1. The `build_ios.sh` can be run successfully for iOS x86 build. The build script I'm using:

	```shell
   	./scripts/build_ios.sh \
   	-DBUILD_CAFFE2_MOBILE=OFF \
	-DIOS_PLATFORM=SIMULATOR \
   	-DUSE_NNPACK=OFF \
   	-DCMAKE_PREFIX_PATH=$(python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())') \
   	-DPYTHON_EXECUTABLE=$(python -c 'import sys; print(sys.executable)')
   	```
2. All generated static libs are x86 libs as shown below

	```
	> lipo -i *.a
	Non-fat file: libasmjit.a is architecture: x86_64
	Non-fat file: libc10.a is architecture: x86_64
	Non-fat file: libcaffe2_protos.a is architecture: x86_64
	Non-fat file: libclog.a is architecture: x86_64
	Non-fat file: libcpuinfo.a is architecture: x86_64
	Non-fat file: libfbgemm.a is architecture: x86_64
	Non-fat file: libtorch.a is architecture: x86_64

Differential Revision: D17183803

Pulled By: xta0

fbshipit-source-id: 870d5433a3616b8e7ed9fb7dfab6aebbda26f723
  • Loading branch information
xta0 authored and facebook-github-bot committed Sep 4, 2019
1 parent 47cee2d commit 14c2492
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
49 changes: 25 additions & 24 deletions cmake/MiscCheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -154,31 +154,32 @@ endif()
cmake_pop_check_state()

# ---[ Check if the compiler has AVX/AVX2 support. We only check AVX2.
cmake_push_check_state(RESET)
if (MSVC)
set(CMAKE_REQUIRED_FLAGS "/arch:AVX2")
else()
set(CMAKE_REQUIRED_FLAGS "-mavx2")
endif()
CHECK_CXX_SOURCE_COMPILES(
"#include <immintrin.h>
int main() {
__m256i a, b;
a = _mm256_set1_epi8 (1);
b = a;
_mm256_add_epi8 (a,a);
__m256i x;
_mm256_extract_epi64(x, 0); // we rely on this in our AVX2 code
return 0;
}" CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS)
if (CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS)
message(STATUS "Current compiler supports avx2 extension. Will build perfkernels.")
# Also see CMakeLists.txt under caffe2/perfkernels.
set(CAFFE2_PERF_WITH_AVX 1)
set(CAFFE2_PERF_WITH_AVX2 1)
if (NOT INTERN_BUILD_MOBILE)
cmake_push_check_state(RESET)
if (MSVC)
set(CMAKE_REQUIRED_FLAGS "/arch:AVX2")
else()
set(CMAKE_REQUIRED_FLAGS "-mavx2")
endif()
CHECK_CXX_SOURCE_COMPILES(
"#include <immintrin.h>
int main() {
__m256i a, b;
a = _mm256_set1_epi8 (1);
b = a;
_mm256_add_epi8 (a,a);
__m256i x;
_mm256_extract_epi64(x, 0); // we rely on this in our AVX2 code
return 0;
}" CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS)
if (CAFFE2_COMPILER_SUPPORTS_AVX2_EXTENSIONS)
message(STATUS "Current compiler supports avx2 extension. Will build perfkernels.")
# Also see CMakeLists.txt under caffe2/perfkernels.
set(CAFFE2_PERF_WITH_AVX 1)
set(CAFFE2_PERF_WITH_AVX2 1)
endif()
cmake_pop_check_state()
endif()
cmake_pop_check_state()

# ---[ Check if the compiler has AVX512 support.
cmake_push_check_state(RESET)
if (MSVC)
Expand Down
3 changes: 1 addition & 2 deletions cmake/iOS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ if (${IOS_PLATFORM} STREQUAL "OS")
# This causes the installers to properly locate the output libraries
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
set (SIMULATOR true)
set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
set (XCODE_IOS_PLATFORM iphonesimulator)

Expand Down Expand Up @@ -161,7 +160,7 @@ set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS su
if (IOS_PLATFORM STREQUAL "OS")
set (DEFAULT_IOS_ARCH "armv7;armv7s;arm64")
elseif (IOS_PLATFORM STREQUAL "SIMULATOR")
set (DEFAULT_IOS_ARCH "i386;x86_64")
set (DEFAULT_IOS_ARCH "x86_64")
elseif (IOS_PLATFORM STREQUAL "WATCHOS")
set (DEFAULT_IOS_ARCH "armv7k")
endif ()
Expand Down

0 comments on commit 14c2492

Please sign in to comment.