Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: build for any kind of arm combination #657

Merged
merged 1 commit into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@ option(NCNN_OPENCV "minimal opencv structure emulation" OFF)
option(NCNN_BENCHMARK "print benchmark information for every layer" OFF)
option(NCNN_PIXEL "convert and resize from/to image pixel" ON)
option(NCNN_PIXEL_ROTATE "rotate image pixel orientation" OFF)
option(NCNN_CMAKE_VERBOSE "print verbose cmake messages" OFF)

if(NCNN_OPENMP)
find_package(OpenMP)
if(OpenMP_CXX_FOUND OR OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
# For CMake < 3.9, we need to make the target ourselves
if(NOT TARGET OpenMP::OpenMP_CXX)
find_package(Threads REQUIRED)
add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE)
set_property(TARGET OpenMP::OpenMP_CXX
PROPERTY INTERFACE_COMPILE_OPTIONS ${OpenMP_CXX_FLAGS})
# Only works if the same flag is passed to the linker; use CMake 3.9+ otherwise (Intel, AppleClang)
set_property(TARGET OpenMP::OpenMP_CXX
PROPERTY INTERFACE_LINK_LIBRARIES ${OpenMP_CXX_FLAGS} Threads::Threads)
endif()
endif()

Expand Down
49 changes: 25 additions & 24 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,38 @@ macro(ncnn_add_layer class)
option(WITH_LAYER_${name} "build with layer ${name}" ON)
endif()

message("WITH_LAYER_${name} = ${WITH_LAYER_${name}}")
if(NCNN_CMAKE_VERBOSE)
message(STATUS "WITH_LAYER_${name} = ${WITH_LAYER_${name}}")
endif()

if(WITH_LAYER_${name})
list(APPEND ncnn_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/layer/${name}.cpp")

# look for arch specific implementation and append source
# optimized implementation for armv7 aarch64
if((ANDROID AND ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a"))
OR (ANDROID AND ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64"))
OR (UNIX AND ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l"))
OR (UNIX AND ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64"))
OR (IOS AND ("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "armv7"))
OR (IOS AND ("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "arm64"))
OR (IOS AND ("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "armv7;arm64")))
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/layer/arm/${name}_arm.cpp")
list(APPEND ncnn_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/layer/arm/${name}_arm.cpp")
set(WITH_LAYER_${name}_arm 1)
endif()
# optimized implementation for armv7, aarch64 or x86
if((IOS AND ${CMAKE_OSX_ARCHITECTURES} MATCHES "arm")
OR (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|aarch64)"))
set(arch arm)
else()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/layer/x86/${name}_x86.cpp")
list(APPEND ncnn_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/layer/x86/${name}_x86.cpp")
set(WITH_LAYER_${name}_x86 1)
set(arch x86)
endif()
set(LAYER_SRC ${CMAKE_CURRENT_SOURCE_DIR}/layer/${arch}/${name}_${arch}.cpp)
if(EXISTS ${LAYER_SRC})
set(WITH_LAYER_${name}_${arch} 1)
list(APPEND ncnn_SRCS ${LAYER_SRC})
if(NCNN_CMAKE_VERBOSE)
message(STATUS "Adding layer: ${LAYER_SRC}")
endif()
endif()
endif()

# generate layer_declaration and layer_registry file
if(WITH_LAYER_${name})
if(WITH_LAYER_${name}_arm)
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/layer_declaration.h
"extern Layer* ${class}_arm_layer_creator();\n")
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/layer_registry.h
"#if NCNN_STRING\n{\"${class}\",${class}_arm_layer_creator},\n#else\n{${class}_arm_layer_creator},\n#endif\n")
elseif(WITH_LAYER_${name}_x86)
if(WITH_LAYER_${name}_${arch})
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/layer_declaration.h
"extern Layer* ${class}_x86_layer_creator();\n")
"extern Layer* ${class}_${arch}_layer_creator();\n")
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/layer_registry.h
"#if NCNN_STRING\n{\"${class}\",${class}_x86_layer_creator},\n#else\n{${class}_x86_layer_creator},\n#endif\n")
"#if NCNN_STRING\n{\"${class}\",${class}_${arch}_layer_creator},\n#else\n{${class}_${arch}_layer_creator},\n#endif\n")
else()
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/layer_declaration.h
"extern Layer* ${class}_layer_creator();\n")
Expand Down Expand Up @@ -155,6 +149,13 @@ ncnn_add_layer(PSROIPooling)

add_library(ncnn STATIC ${ncnn_SRCS})

if(NCNN_OPENMP AND OpenMP_CXX_FOUND)
if(NCNN_CMAKE_VERBOSE)
message("Building with OpenMP")
endif()
target_link_libraries(ncnn PUBLIC OpenMP::OpenMP_CXX)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only a static library is generated for the ncnn target
linking openmp library is required when building shared library/module or executable, but makes nonsense here

endif()

if(COVERAGE)
target_compile_options(ncnn PRIVATE --coverage)
endif()
Expand Down