mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Summary: * add custom ninja install * minimal build for nnpack * force -fPIC for nnpack Closes https://github.com/caffe2/caffe2/pull/207 Differential Revision: D4729265 Pulled By: Yangqing fbshipit-source-id: 2ed345a4fda6b4811af03cd1898e2402dda58701
83 lines
2.8 KiB
CMake
83 lines
2.8 KiB
CMake
if (__NNPACK_INCLUDED)
|
|
return()
|
|
endif()
|
|
set(__NNPACK_INCLUDED TRUE)
|
|
|
|
if (NOT USE_NNPACK)
|
|
return()
|
|
endif()
|
|
|
|
# try any external nnpack first
|
|
find_package(NNPACK)
|
|
|
|
if (NNPACK_FOUND)
|
|
message(INFO "Found external NNPACK installation.")
|
|
return()
|
|
endif()
|
|
|
|
##############################################################################
|
|
# Custom build rules to build nnpack, if external dependency is not found
|
|
##############################################################################
|
|
|
|
set(NNPACK_PREFIX ${PROJECT_SOURCE_DIR}/third_party/NNPACK)
|
|
|
|
##############################################################################
|
|
# (1) MSVC - unsupported
|
|
##############################################################################
|
|
|
|
if (MSVC)
|
|
message(WARNING "NNPACK not supported on MSVC yet. Turn this warning off by USE_NNPACK=OFF.")
|
|
set(USE_NNPACK OFF)
|
|
return()
|
|
endif()
|
|
|
|
##############################################################################
|
|
# (2) Mobile platform - direct build
|
|
##############################################################################
|
|
|
|
if (ANDROID OR IOS)
|
|
message(WARNING "NNPACK for mobile cmake support is wip")
|
|
set(USE_NNPACK OFF)
|
|
return()
|
|
endif()
|
|
|
|
##############################################################################
|
|
# (3) Linux/Mac: use PeachPy
|
|
##############################################################################
|
|
|
|
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
message(STATUS "Will try to build NNPACK from source. If anything fails, "
|
|
"follow the NNPACK prerequisite installation steps.")
|
|
# Note: per Marat, there is no support for fPIC right now so we will need to
|
|
# manually change it in build.ninja
|
|
ExternalProject_Add(nnpack_external
|
|
SOURCE_DIR ${NNPACK_PREFIX}
|
|
BUILD_IN_SOURCE 1
|
|
CONFIGURE_COMMAND ""
|
|
BUILD_COMMAND confu setup
|
|
COMMAND python ./configure.py
|
|
COMMAND sed -ibuild.ninja.bak "s/cflags = /cflags = -fPIC /" build.ninja
|
|
COMMAND sed -ibuild.ninja.bak "s/cxxflags = /cxxflags = -fPIC /" build.ninja
|
|
COMMAND ninja nnpack
|
|
INSTALL_COMMAND ""
|
|
)
|
|
|
|
set(NNPACK_FOUND TRUE)
|
|
set(NNPACK_INCLUDE_DIRS
|
|
${NNPACK_PREFIX}/include
|
|
${NNPACK_PREFIX}/deps/pthreadpool/include)
|
|
set(NNPACK_LIBRARIES ${NNPACK_PREFIX}/lib/libnnpack.a ${NNPACK_PREFIX}/lib/libpthreadpool.a)
|
|
set(NNPACK_LIBRARY_DIRS ${NNPACK_PREFIX}/lib)
|
|
|
|
list(APPEND external_project_dependencies nnpack_external)
|
|
return()
|
|
endif()
|
|
|
|
##############################################################################
|
|
# (3) Catch-all: not supported.
|
|
##############################################################################
|
|
|
|
message(WARNING "Unknown platform - I don't know how to build NNPACK. "
|
|
"See cmake/External/nnpack.cmake for details.")
|
|
set(USE_NNPACK OFF)
|