mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Fix iOS simulator build (#25633)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/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
This commit is contained in:
committed by
Facebook Github Bot
parent
47cee2dd22
commit
14c2492fb5
@ -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")
|
||||
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()
|
||||
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()
|
||||
|
||||
# ---[ Check if the compiler has AVX512 support.
|
||||
cmake_push_check_state(RESET)
|
||||
if (MSVC)
|
||||
|
@ -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)
|
||||
|
||||
@ -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 ()
|
||||
|
Reference in New Issue
Block a user