Tencent / ncnn

ncnn is a high-performance neural network inference framework optimized for the mobile platform
Other
20.42k stars 4.16k forks source link

编译arm-linux时为何编译的却是x86(参考了#28仍然未解决) #675

Closed bigbao9494 closed 5 years ago

bigbao9494 commented 5 years ago

我在一个arm平台下编译(全志,非android) 发现它编译的是src/layer/x86而不是src/layer/arm 但是我编译Android版本时却是正常的,不知道需要怎样修改才能编译出arm版本呢??? 下面是编译打印: [ 24%] Building CXX object src/CMakeFiles/ncnn.dir/layer/x86/convolution_x86.cpp.obj In file included from /home/ncnn-master_20181128_cross/src/layer/x86/convolution_x86.cpp:19:0:

@nihui 你好 我尝试了#28中的方法,仍然不行,以下是我尝试的方法不知道是否正确: 我使用的芯片是全志的H2 1、 新建一个arm.toolchan.cmake SET(CMAKE_SYSTEM_NANE Android) SET(CMAKE_SYSTEM_PROCESSOR "armv7-a") SET(ANDROID_ARCH_NAME "arm") SET(ANDROID true) SET(CMAKE_C_COMPILER "arm-cortexa9-linux-gnueabihf-gcc") SET(CMAKE_CXX_COMPILER "arm-cortexa9-linux-gnueabihf-g++") 然后:mkdir arm;cd arm;cmake -DCMAKE_TOOLCHAIN_FILE=../arm.toolchain.cmake ..;make -j2 2、 直接修改CMakeLists.txt,全部文件内容如下(注释为ljy的是我添加的内容): if(CMAKE_TOOLCHAIN_FILE) set(LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_BINARY_DIR} CACHE PATH "root for library output, set this to change where android libs are compiled to")

get absolute path, but get_filename_component ABSOLUTE only refer with source dir, so find_file here :(

get_filename_component(CMAKE_TOOLCHAIN_FILE_NAME ${CMAKE_TOOLCHAIN_FILE} NAME) find_file(CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_FILE_NAME} PATHS ${CMAKE_SOURCE_DIR} NO_DEFAULT_PATH) message(STATUS "CMAKE_TOOLCHAIN_FILE = ${CMAKE_TOOLCHAIN_FILE}") endif()

if(NOT DEFINED CMAKE_INSTALL_PREFIX) set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Installation Directory") endif() message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")

cmake_minimum_required(VERSION 2.8.10)

if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE release CACHE STRING "Choose the type of build" FORCE) endif()

set(COVERAGE OFF CACHE BOOL "Coverage")

project(ncnn)

option(NCNN_OPENMP "openmp support" ON) option(NCNN_STDIO "load model from external file" ON) option(NCNN_STRING "plain and verbose string" ON) 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)

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()

if(WIN32) add_definitions(-D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE) add_definitions(-DNOMINMAX) else()

add_definitions(-Wall -Wextra -Wno-unused-function)

add_definitions(-fPIC)
if(CMAKE_BUILD_TYPE MATCHES "(Release|RELEASE|release)")
    add_definitions(-Ofast)

    add_definitions(-ffast-math)
endif()

if(PI3)
    add_definitions(-march=native)
    add_definitions(-mfpu=neon)
    add_definitions(-mfloat-abi=hard)
    add_definitions(-D__ARM_NEON)
    add_definitions(-D__ANDROID__)
endif()
# add_definitions(-march=native)
# add_definitions(-flto)
add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden)

endif()

if(ANDROID)

if(TRUE) #ljy modify

# disable shared library on android
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")

elseif(IOS)

disable shared library on xcode ios

set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")

endif()

##############################################

add_subdirectory(examples)

add_subdirectory(benchmark)

add_subdirectory(src) if(NOT ANDROID AND NOT IOS) add_subdirectory(tools) endif()

add_definitions(-mfpu=neon)#ljy added. add_definitions(-march=native)#ljy added. add_definitions(-mfloat-abi=hard)#ljy added. add_definitions(-D__ARM_NEON)#ljy added.

nihui commented 5 years ago

https://github.com/Tencent/ncnn/blob/d9d7d6b6eae223598cb63e27335d5e6385d9750c/src/CMakeLists.txt#L43 这里的条件你检查下是不是进去了

bigbao9494 commented 5 years ago

@nihui 非常感谢您的回复

我修改src/CmakeLists.txt的第43行,强制进入ARM平台编译

if((IOS AND ${CMAKE_OSX_ARCHITECTURES} MATCHES "arm")

    if(TRUE 
        OR (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|aarch64)"))

这样可以进入ARM平台编译,但是编译时会报错,我看了下代码意思是convolutiondepthwise_3x3_int8.h文件中 未找到int8x8_t类型的定义 内容如下(列出一个错误,其它都同一个错误): /home/ncnn-master_20181128_cross/src/layer/arm/convolutiondepthwise_3x3_int8.h:679:9: 错误:‘int8x8_t’在此作用域中尚未声明 int8x8_t _k0 = vdup_n_s8(kernel[0]); ^ /home/ncnn-master_20181128_cross/src/layer/arm/convolutiondepthwise_3x3_int8.h:680:18: 错误:expected ‘;’ before ‘_k1’ int8x8_t _k1 = vdup_n_s8(kernel[1]);