1*da0073e9SAndroid Build Coastguard Workerif(__NNPACK_INCLUDED) 2*da0073e9SAndroid Build Coastguard Worker return() 3*da0073e9SAndroid Build Coastguard Workerendif() 4*da0073e9SAndroid Build Coastguard Workerset(__NNPACK_INCLUDED TRUE) 5*da0073e9SAndroid Build Coastguard Worker 6*da0073e9SAndroid Build Coastguard Workerif(NOT USE_NNPACK) 7*da0073e9SAndroid Build Coastguard Worker return() 8*da0073e9SAndroid Build Coastguard Workerendif() 9*da0073e9SAndroid Build Coastguard Worker 10*da0073e9SAndroid Build Coastguard Worker############################################################################## 11*da0073e9SAndroid Build Coastguard Worker# NNPACK is built together with Caffe2 12*da0073e9SAndroid Build Coastguard Worker# By default, it builds code from third-party/NNPACK submodule. 13*da0073e9SAndroid Build Coastguard Worker# Define NNPACK_SOURCE_DIR to build with a different version. 14*da0073e9SAndroid Build Coastguard Worker############################################################################## 15*da0073e9SAndroid Build Coastguard Worker 16*da0073e9SAndroid Build Coastguard Worker############################################################################## 17*da0073e9SAndroid Build Coastguard Worker# (1) MSVC - unsupported 18*da0073e9SAndroid Build Coastguard Worker############################################################################## 19*da0073e9SAndroid Build Coastguard Worker 20*da0073e9SAndroid Build Coastguard Workerif(MSVC) 21*da0073e9SAndroid Build Coastguard Worker message(WARNING "NNPACK not supported on MSVC yet. Turn this warning off by USE_NNPACK=OFF.") 22*da0073e9SAndroid Build Coastguard Worker set(USE_NNPACK OFF) 23*da0073e9SAndroid Build Coastguard Worker return() 24*da0073e9SAndroid Build Coastguard Workerendif() 25*da0073e9SAndroid Build Coastguard Worker 26*da0073e9SAndroid Build Coastguard Worker############################################################################## 27*da0073e9SAndroid Build Coastguard Worker# (2) Anything but x86, x86-64, ARM, ARM64 - unsupported 28*da0073e9SAndroid Build Coastguard Worker############################################################################## 29*da0073e9SAndroid Build Coastguard Workerif(CMAKE_SYSTEM_PROCESSOR) 30*da0073e9SAndroid Build Coastguard Worker if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|x86_64|armv5te|armv7-a|armv7l|arm64|aarch64)$") 31*da0073e9SAndroid Build Coastguard Worker message(WARNING "NNPACK is not supported on ${CMAKE_SYSTEM_PROCESSOR} processors. " 32*da0073e9SAndroid Build Coastguard Worker "The only supported architectures are x86, x86-64, ARM, and ARM64. " 33*da0073e9SAndroid Build Coastguard Worker "Turn this warning off by USE_NNPACK=OFF.") 34*da0073e9SAndroid Build Coastguard Worker set(USE_NNPACK OFF) 35*da0073e9SAndroid Build Coastguard Worker return() 36*da0073e9SAndroid Build Coastguard Worker endif() 37*da0073e9SAndroid Build Coastguard Workerendif() 38*da0073e9SAndroid Build Coastguard Worker 39*da0073e9SAndroid Build Coastguard Worker############################################################################## 40*da0073e9SAndroid Build Coastguard Worker# (3) Android, iOS, Linux, macOS - supported 41*da0073e9SAndroid Build Coastguard Worker############################################################################## 42*da0073e9SAndroid Build Coastguard Worker 43*da0073e9SAndroid Build Coastguard Workerif(ANDROID OR IOS OR ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") 44*da0073e9SAndroid Build Coastguard Worker message(STATUS "Brace yourself, we are building NNPACK") 45*da0073e9SAndroid Build Coastguard Worker set(CAFFE2_THIRD_PARTY_ROOT ${PROJECT_SOURCE_DIR}/third_party) 46*da0073e9SAndroid Build Coastguard Worker 47*da0073e9SAndroid Build Coastguard Worker # Directories for NNPACK dependencies submoduled in Caffe2 48*da0073e9SAndroid Build Coastguard Worker set(PYTHON_PEACHPY_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/python-peachpy" CACHE STRING "PeachPy (Python package) source directory") 49*da0073e9SAndroid Build Coastguard Worker if(NOT DEFINED CPUINFO_SOURCE_DIR) 50*da0073e9SAndroid Build Coastguard Worker set(CPUINFO_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/cpuinfo" CACHE STRING "cpuinfo source directory") 51*da0073e9SAndroid Build Coastguard Worker endif() 52*da0073e9SAndroid Build Coastguard Worker set(NNPACK_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/NNPACK" CACHE STRING "NNPACK source directory") 53*da0073e9SAndroid Build Coastguard Worker set(FP16_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/FP16" CACHE STRING "FP16 source directory") 54*da0073e9SAndroid Build Coastguard Worker set(FXDIV_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/FXdiv" CACHE STRING "FXdiv source directory") 55*da0073e9SAndroid Build Coastguard Worker set(PSIMD_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/psimd" CACHE STRING "PSimd source directory") 56*da0073e9SAndroid Build Coastguard Worker set(PTHREADPOOL_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/pthreadpool" CACHE STRING "pthreadpool source directory") 57*da0073e9SAndroid Build Coastguard Worker set(GOOGLETEST_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/googletest" CACHE STRING "Google Test source directory") 58*da0073e9SAndroid Build Coastguard Worker 59*da0073e9SAndroid Build Coastguard Worker if(NOT TARGET nnpack) 60*da0073e9SAndroid Build Coastguard Worker if(NOT USE_SYSTEM_PTHREADPOOL AND USE_INTERNAL_PTHREADPOOL_IMPL) 61*da0073e9SAndroid Build Coastguard Worker set(NNPACK_CUSTOM_THREADPOOL ON CACHE BOOL "") 62*da0073e9SAndroid Build Coastguard Worker endif() 63*da0073e9SAndroid Build Coastguard Worker 64*da0073e9SAndroid Build Coastguard Worker set(NNPACK_BUILD_TESTS OFF CACHE BOOL "") 65*da0073e9SAndroid Build Coastguard Worker set(NNPACK_BUILD_BENCHMARKS OFF CACHE BOOL "") 66*da0073e9SAndroid Build Coastguard Worker set(NNPACK_LIBRARY_TYPE "static" CACHE STRING "") 67*da0073e9SAndroid Build Coastguard Worker set(PTHREADPOOL_LIBRARY_TYPE "static" CACHE STRING "") 68*da0073e9SAndroid Build Coastguard Worker set(CPUINFO_LIBRARY_TYPE "static" CACHE STRING "") 69*da0073e9SAndroid Build Coastguard Worker add_subdirectory( 70*da0073e9SAndroid Build Coastguard Worker "${NNPACK_SOURCE_DIR}" 71*da0073e9SAndroid Build Coastguard Worker "${CONFU_DEPENDENCIES_BINARY_DIR}/NNPACK") 72*da0073e9SAndroid Build Coastguard Worker # We build static versions of nnpack and pthreadpool but link 73*da0073e9SAndroid Build Coastguard Worker # them into a shared library for Caffe2, so they need PIC. 74*da0073e9SAndroid Build Coastguard Worker set_property(TARGET nnpack PROPERTY POSITION_INDEPENDENT_CODE ON) 75*da0073e9SAndroid Build Coastguard Worker set_property(TARGET pthreadpool PROPERTY POSITION_INDEPENDENT_CODE ON) 76*da0073e9SAndroid Build Coastguard Worker set_property(TARGET cpuinfo PROPERTY POSITION_INDEPENDENT_CODE ON) 77*da0073e9SAndroid Build Coastguard Worker 78*da0073e9SAndroid Build Coastguard Worker if(NNPACK_CUSTOM_THREADPOOL) 79*da0073e9SAndroid Build Coastguard Worker target_compile_definitions( 80*da0073e9SAndroid Build Coastguard Worker nnpack PRIVATE 81*da0073e9SAndroid Build Coastguard Worker pthreadpool_t=legacy_pthreadpool_t 82*da0073e9SAndroid Build Coastguard Worker pthreadpool_function_1d_t=legacy_pthreadpool_function_1d_t 83*da0073e9SAndroid Build Coastguard Worker pthreadpool_function_1d_tiled_t=legacy_pthreadpool_function_1d_tiled_t 84*da0073e9SAndroid Build Coastguard Worker pthreadpool_function_2d_t=legacy_pthreadpool_function_2d_t 85*da0073e9SAndroid Build Coastguard Worker pthreadpool_function_2d_tiled_t=legacy_pthreadpool_function_2d_tiled_t 86*da0073e9SAndroid Build Coastguard Worker pthreadpool_function_3d_tiled_t=legacy_pthreadpool_function_3d_tiled_t 87*da0073e9SAndroid Build Coastguard Worker pthreadpool_function_4d_tiled_t=legacy_pthreadpool_function_4d_tiled_t 88*da0073e9SAndroid Build Coastguard Worker pthreadpool_create=legacy_pthreadpool_create 89*da0073e9SAndroid Build Coastguard Worker pthreadpool_destroy=legacy_pthreadpool_destroy 90*da0073e9SAndroid Build Coastguard Worker pthreadpool_get_threads_count=legacy_pthreadpool_get_threads_count 91*da0073e9SAndroid Build Coastguard Worker pthreadpool_compute_1d=legacy_pthreadpool_compute_1d 92*da0073e9SAndroid Build Coastguard Worker pthreadpool_parallelize_1d=legacy_pthreadpool_parallelize_1d 93*da0073e9SAndroid Build Coastguard Worker pthreadpool_compute_1d_tiled=legacy_pthreadpool_compute_1d_tiled 94*da0073e9SAndroid Build Coastguard Worker pthreadpool_compute_2d=legacy_pthreadpool_compute_2d 95*da0073e9SAndroid Build Coastguard Worker pthreadpool_compute_2d_tiled=legacy_pthreadpool_compute_2d_tiled 96*da0073e9SAndroid Build Coastguard Worker pthreadpool_compute_3d_tiled=legacy_pthreadpool_compute_3d_tiled 97*da0073e9SAndroid Build Coastguard Worker pthreadpool_compute_4d_tiled=legacy_pthreadpool_compute_4d_tiled) 98*da0073e9SAndroid Build Coastguard Worker endif() 99*da0073e9SAndroid Build Coastguard Worker endif() 100*da0073e9SAndroid Build Coastguard Worker 101*da0073e9SAndroid Build Coastguard Worker set(NNPACK_FOUND TRUE) 102*da0073e9SAndroid Build Coastguard Worker if(TARGET nnpack) 103*da0073e9SAndroid Build Coastguard Worker set(NNPACK_INCLUDE_DIRS 104*da0073e9SAndroid Build Coastguard Worker $<TARGET_PROPERTY:nnpack,INCLUDE_DIRECTORIES> 105*da0073e9SAndroid Build Coastguard Worker $<TARGET_PROPERTY:pthreadpool,INCLUDE_DIRECTORIES>) 106*da0073e9SAndroid Build Coastguard Worker set(NNPACK_LIBRARIES $<TARGET_OBJECTS:nnpack> $<TARGET_OBJECTS:cpuinfo>) 107*da0073e9SAndroid Build Coastguard Worker endif() 108*da0073e9SAndroid Build Coastguard Worker return() 109*da0073e9SAndroid Build Coastguard Workerendif() 110*da0073e9SAndroid Build Coastguard Worker 111*da0073e9SAndroid Build Coastguard Worker############################################################################## 112*da0073e9SAndroid Build Coastguard Worker# (4) Catch-all: not supported. 113*da0073e9SAndroid Build Coastguard Worker############################################################################## 114*da0073e9SAndroid Build Coastguard Worker 115*da0073e9SAndroid Build Coastguard Workermessage(WARNING "Unknown platform - I don't know how to build NNPACK. " 116*da0073e9SAndroid Build Coastguard Worker "See cmake/External/nnpack.cmake for details.") 117*da0073e9SAndroid Build Coastguard Workerset(USE_NNPACK OFF) 118