Skip to content

Commit 57f9db9

Browse files
ezyangsoumith
authored andcommitted
Two NNPACK build fixes. (#4439)
1. master NNPACK now uses cpuinfo library, so we detect it and add it to the list of libraries. 2. If a user builds nnpack with --inference-only, there won't actually be enough symbols to successfully link against NNPACK. This won't manifest until quite late in the build process. So we now explicitly test that the gradient functions are available in the library. Upstream bug: Maratyszcza/NNPACK#123 Fixes #4336 Signed-off-by: Edward Z. Yang <ezyang@fb.com>
1 parent 98e5f2c commit 57f9db9

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

aten/cmake/FindNNPACK.cmake

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# NNPACK_LIBRARYRARY_DIRS
1313

1414
include(FindPackageHandleStandardArgs)
15+
include(CheckSymbolExists)
1516

1617
set(NNPACK_ROOT_DIR "" CACHE PATH "Folder contains NNPACK")
1718

@@ -26,17 +27,31 @@ find_library(NNPACK_LIBRARY nnpack
2627
PATHS ${NNPACK_ROOT_DIR}
2728
PATH_SUFFIXES lib lib64)
2829

30+
find_library(CPUINFO_LIBRARY cpuinfo
31+
PATHS ${NNPACK_ROOT_DIR}
32+
PATH_SUFFIXES lib lib64)
33+
2934
find_library(PTHREADPOOL_LIBRARY pthreadpool
3035
PATHS ${NNPACK_ROOT_DIR}
3136
PATH_SUFFIXES lib lib64)
3237

33-
find_package_handle_standard_args(NNPACK DEFAULT_MSG NNPACK_INCLUDE_DIR NNPACK_LIBRARY PTHREADPOOL_LIBRARY)
38+
find_package_handle_standard_args(NNPACK DEFAULT_MSG NNPACK_INCLUDE_DIR NNPACK_LIBRARY CPUINFO_LIBRARY PTHREADPOOL_LIBRARY)
3439

3540
if(NNPACK_FOUND)
3641
set(NNPACK_INCLUDE_DIRS ${NNPACK_INCLUDE_DIR})
37-
set(NNPACK_LIBRARIES ${NNPACK_LIBRARY} ${PTHREADPOOL_LIBRARY})
38-
message(STATUS "Found NNPACK (include: ${NNPACK_INCLUDE_DIR}, library: ${NNPACK_LIBRARY})")
39-
message(STATUS "Found PTHREADPOOL (library: ${PTHREADPOOL_LIBRARY})")
40-
mark_as_advanced(NNPACK_ROOT_DIR NNPACK_LIBRARY_RELEASE NNPACK_LIBRARY_DEBUG
41-
NNPACK_LIBRARY NNPACK_INCLUDE_DIR)
42+
set(NNPACK_LIBRARIES ${NNPACK_LIBRARY} ${CPUINFO_LIBRARY} ${PTHREADPOOL_LIBRARY})
43+
44+
list(APPEND CMAKE_REQUIRED_LIBRARIES ${NNPACK_LIBRARIES})
45+
list(APPEND CMAKE_REQUIRED_INCLUDES ${NNPACK_INCLUDE_DIRS})
46+
check_symbol_exists(nnp_convolution_kernel_gradient "nnpack.h" NNPACK_HAS_INFERENCE)
47+
48+
if(NNPACK_HAS_INFERENCE)
49+
message(STATUS "Found NNPACK (include: ${NNPACK_INCLUDE_DIR}, library: ${NNPACK_LIBRARY})")
50+
message(STATUS "Found CPUINFO (library: ${CPUINFO_LIBRARY})")
51+
message(STATUS "Found PTHREADPOOL (library: ${PTHREADPOOL_LIBRARY})")
52+
mark_as_advanced(NNPACK_ROOT_DIR NNPACK_LIBRARY_RELEASE NNPACK_LIBRARY_DEBUG
53+
NNPACK_LIBRARY NNPACK_INCLUDE_DIR)
54+
else()
55+
message(STATUS "Refusing to use incomplete NNPACK (include: ${NNPACK_INCLUDE_DIR}, library: ${NNPACK_LIBRARY}); try reinstalling NNPACK without --inference-only")
56+
endif()
4257
endif()

0 commit comments

Comments
 (0)