mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
CMakeLists changes to enable libtorch for Android (#19762)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/19762 ghimport-source-id: 287aa7fea4efd38994e14d794123eb2046b91fc0 Differential Revision: D15087653 Pulled By: ljk53 fbshipit-source-id: 4498ff9f7f7903c3e25541184302b811267958e9
This commit is contained in:
committed by
Facebook Github Bot
parent
0e77c0f5de
commit
c7c02724cd
@ -65,10 +65,9 @@ fi
|
||||
if [[ "${BUILD_ENVIRONMENT}" == *-android* ]]; then
|
||||
export ANDROID_NDK=/opt/ndk
|
||||
build_args=()
|
||||
build_args+=("-DBUILD_BINARY=ON")
|
||||
build_args+=("-DBUILD_TEST=ON")
|
||||
build_args+=("-DUSE_OBSERVERS=ON")
|
||||
build_args+=("-DUSE_ZSTD=ON")
|
||||
build_args+=("-DBUILD_CAFFE2_MOBILE=OFF")
|
||||
build_args+=("-DCMAKE_PREFIX_PATH=$(python -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')")
|
||||
build_args+=("-DPYTHON_EXECUTABLE=$(python -c 'import sys; print(sys.executable)')")
|
||||
exec ./scripts/build_android.sh "${build_args[@]}" "$@"
|
||||
fi
|
||||
|
||||
|
@ -70,6 +70,7 @@ option(BUILD_CUSTOM_PROTOBUF "Build and use Caffe2's own protobuf under third_pa
|
||||
option(BUILD_PYTHON "Build Python binaries" ON)
|
||||
option(BUILD_CAFFE2_OPS "Build Caffe2 operators" ON)
|
||||
option(BUILD_SHARED_LIBS "Build libcaffe2.so" ON)
|
||||
option(BUILD_CAFFE2_MOBILE "Build libcaffe2 for mobile (deprecating)" ON)
|
||||
cmake_dependent_option(
|
||||
CAFFE2_LINK_LOCAL_PROTOBUF "If set, build protobuf inside libcaffe2.so." ON
|
||||
"BUILD_SHARED_LIBS AND BUILD_CUSTOM_PROTOBUF" OFF)
|
||||
@ -170,6 +171,26 @@ if (ANDROID OR IOS)
|
||||
set(INTERN_BUILD_MOBILE ON)
|
||||
endif()
|
||||
|
||||
# INTERN_BUILD_ATEN_OPS is used to control whether to build ATen/TH operators.
|
||||
# It's disabled for caffe2 mobile library.
|
||||
if (INTERN_BUILD_MOBILE AND BUILD_CAFFE2_MOBILE)
|
||||
set(INTERN_BUILD_ATEN_OPS OFF)
|
||||
else()
|
||||
set(INTERN_BUILD_ATEN_OPS ON)
|
||||
endif()
|
||||
|
||||
# BUILD_CAFFE2_MOBILE is the master switch to choose between libcaffe2 v.s. libtorch mobile build.
|
||||
# When it's enabled it builds original libcaffe2 mobile library without ATen/TH ops nor TorchScript support;
|
||||
# When it's disabled it builds libtorch mobile library, which contains ATen/TH ops and native support for
|
||||
# TorchScript model, but doesn't contain not-yet-unified caffe2 ops;
|
||||
if (INTERN_BUILD_MOBILE AND NOT BUILD_CAFFE2_MOBILE)
|
||||
set(BUILD_PYTHON OFF)
|
||||
set(BUILD_TORCH ON)
|
||||
set(BUILD_CAFFE2_OPS OFF)
|
||||
set(USE_DISTRIBUTED OFF)
|
||||
set(FEATURE_TORCH_MOBILE ON)
|
||||
endif()
|
||||
|
||||
if (BUILD_ATEN_ONLY)
|
||||
set(BUILD_CAFFE2_OPS OFF)
|
||||
set(BUILD_PYTHON OFF)
|
||||
|
@ -1,14 +1,17 @@
|
||||
if (INTERN_BUILD_MOBILE)
|
||||
if (NOT INTERN_BUILD_ATEN_OPS)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Find modules
|
||||
if (NOT INTERN_BUILD_MOBILE)
|
||||
list(APPEND CMAKE_MODULE_PATH /usr/lib/x86_64-linux-gnu/)
|
||||
list(APPEND CMAKE_LIBRARY_PATH /usr/lib/x86_64-linux-gnu/ /usr/lib/aarch64-linux-gnu/)
|
||||
endif()
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH
|
||||
/usr/lib/x86_64-linux-gnu/
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../cmake/public
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules_CUDA_fix)
|
||||
list(APPEND CMAKE_LIBRARY_PATH /usr/lib/x86_64-linux-gnu/ /usr/lib/aarch64-linux-gnu/)
|
||||
|
||||
cmake_policy(SET CMP0012 NEW)
|
||||
|
||||
|
@ -205,7 +205,7 @@ endif(MKLDNN_FOUND)
|
||||
|
||||
list(APPEND ATen_CPU_DEPENDENCY_LIBS cpuinfo)
|
||||
|
||||
if(NOT MSVC AND NOT EMSCRIPTEN)
|
||||
if(NOT MSVC AND NOT EMSCRIPTEN AND NOT INTERN_BUILD_MOBILE)
|
||||
# Preserve values for the main build
|
||||
set(__aten_sleef_build_shared_libs ${BUILD_SHARED_LIBS})
|
||||
set(__aten_sleef_build_tests ${BUILD_TESTS})
|
||||
|
@ -4,7 +4,7 @@ include(../cmake/Codegen.cmake)
|
||||
# ---[ Declare source file lists
|
||||
|
||||
# ---[ ATen build
|
||||
if (NOT INTERN_BUILD_MOBILE)
|
||||
if (INTERN_BUILD_ATEN_OPS)
|
||||
set(__caffe2_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE})
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
set(AT_LINK_STYLE INTERFACE)
|
||||
|
@ -19,7 +19,7 @@ list(APPEND Caffe2_CPU_SRCS
|
||||
# ---[ threadpool/pthreadpool* is a local modification of the NNPACK
|
||||
# pthreadpool with a very similar interface. Neither NNPACK, nor this
|
||||
# thread pool supports Windows.
|
||||
if (NOT MSVC)
|
||||
if (NOT MSVC AND (NOT INTERN_BUILD_MOBILE OR BUILD_CAFFE2_MOBILE))
|
||||
set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS}
|
||||
utils/threadpool/pthreadpool.cc
|
||||
utils/threadpool/pthreadpool_impl.cc
|
||||
|
@ -43,7 +43,7 @@ configure_file(
|
||||
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../caffe2
|
||||
DESTINATION include
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
if (INTERN_BUILD_MOBILE)
|
||||
if (NOT INTERN_BUILD_ATEN_OPS)
|
||||
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/core
|
||||
DESTINATION include/ATen
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
@ -52,7 +52,7 @@ install(FILES ${CMAKE_BINARY_DIR}/caffe2/core/macros.h
|
||||
DESTINATION include/caffe2/core)
|
||||
|
||||
# ---[ ATen specific
|
||||
if (NOT INTERN_BUILD_MOBILE)
|
||||
if (INTERN_BUILD_ATEN_OPS)
|
||||
SET(OPT_FLAG "-O3 ")
|
||||
IF(MSVC)
|
||||
SET(OPT_FLAG "/Ox /fp:strict ")
|
||||
|
@ -85,6 +85,8 @@ if(NOT INTERN_BUILD_MOBILE)
|
||||
set(BLAS "MKL" CACHE STRING "Selected BLAS library")
|
||||
else()
|
||||
set(BLAS "Eigen" CACHE STRING "Selected BLAS library")
|
||||
set(AT_MKLDNN_ENABLED 0)
|
||||
set(AT_MKL_ENABLED 0)
|
||||
endif()
|
||||
set_property(CACHE BLAS PROPERTY STRINGS "Eigen;ATLAS;OpenBLAS;MKL;vecLib")
|
||||
message(STATUS "Trying to find preferred BLAS backend of choice: " ${BLAS})
|
||||
|
@ -20,6 +20,7 @@ function (caffe2_print_configuration_summary)
|
||||
|
||||
message(STATUS " TORCH_VERSION : ${TORCH_VERSION}")
|
||||
message(STATUS " CAFFE2_VERSION : ${CAFFE2_VERSION}")
|
||||
message(STATUS " BUILD_CAFFE2_MOBILE : ${BUILD_CAFFE2_MOBILE}")
|
||||
message(STATUS " BUILD_ATEN_ONLY : ${BUILD_ATEN_ONLY}")
|
||||
message(STATUS " BUILD_BINARY : ${BUILD_BINARY}")
|
||||
message(STATUS " BUILD_CUSTOM_PROTOBUF : ${BUILD_CUSTOM_PROTOBUF}")
|
||||
@ -44,6 +45,8 @@ function (caffe2_print_configuration_summary)
|
||||
message(STATUS " BUILD_SHARED_LIBS : ${BUILD_SHARED_LIBS}")
|
||||
message(STATUS " BUILD_TEST : ${BUILD_TEST}")
|
||||
|
||||
message(STATUS " INTERN_BUILD_MOBILE : ${INTERN_BUILD_MOBILE}")
|
||||
|
||||
message(STATUS " USE_ASAN : ${USE_ASAN}")
|
||||
message(STATUS " USE_CUDA : ${USE_CUDA}")
|
||||
if(${USE_CUDA})
|
||||
|
@ -40,11 +40,19 @@ if (@BUILD_SHARED_LIBS@)
|
||||
find_package(Caffe2 REQUIRED PATHS ${CMAKE_CURRENT_LIST_DIR}/../Caffe2)
|
||||
endif()
|
||||
|
||||
if (NOT ANDROID)
|
||||
find_library(TORCH_LIBRARY torch PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
||||
else()
|
||||
find_library(TORCH_LIBRARY NO_CMAKE_FIND_ROOT_PATH torch PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
||||
endif()
|
||||
add_library(torch UNKNOWN IMPORTED)
|
||||
set(TORCH_LIBRARIES torch ${Caffe2_MAIN_LIBS})
|
||||
|
||||
if (NOT ANDROID)
|
||||
find_library(C10_LIBRARY c10 PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
||||
else()
|
||||
find_library(C10_LIBRARY c10 NO_CMAKE_FIND_ROOT_PATH PATHS "${TORCH_INSTALL_PREFIX}/lib")
|
||||
endif()
|
||||
list(APPEND TORCH_LIBRARIES ${C10_LIBRARY})
|
||||
|
||||
if (@USE_CUDA@)
|
||||
|
Reference in New Issue
Block a user