提交 ccd3d0a4 编写于 作者: L Liu Yiqun

Modify cmake for cross-compiling on arm architecture.

上级 df371329
...@@ -25,7 +25,6 @@ find_package(Git REQUIRED) ...@@ -25,7 +25,6 @@ find_package(Git REQUIRED)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
include(system) include(system)
include(simd)
################################ Configurations ####################################### ################################ Configurations #######################################
option(WITH_GPU "Compile PaddlePaddle with NVIDIA GPU" ${CUDA_FOUND}) option(WITH_GPU "Compile PaddlePaddle with NVIDIA GPU" ${CUDA_FOUND})
...@@ -65,6 +64,7 @@ include(external/openblas) # download, build, install openblas ...@@ -65,6 +64,7 @@ include(external/openblas) # download, build, install openblas
include(external/swig) # download, build, install swig include(external/swig) # download, build, install swig
include(external/warpctc) # download, build, install warpctc include(external/warpctc) # download, build, install warpctc
include(simd) # set simd flag
include(package) # set paddle packages include(package) # set paddle packages
include(cpplint) # set paddle c++ style include(cpplint) # set paddle c++ style
include(ccache) # set ccache for compilation include(ccache) # set ccache for compilation
...@@ -74,7 +74,6 @@ include(flags) # set paddle compile flags ...@@ -74,7 +74,6 @@ include(flags) # set paddle compile flags
include(cudnn) # set cudnn libraries include(cudnn) # set cudnn libraries
include(version) # set PADDLE_VERSION include(version) # set PADDLE_VERSION
include(coveralls) # set code coverage include(coveralls) # set code coverage
include(configure) # add paddle env configuration include(configure) # add paddle env configuration
include_directories("${PROJ_ROOT}") include_directories("${PROJ_ROOT}")
......
...@@ -59,10 +59,5 @@ else() ...@@ -59,10 +59,5 @@ else()
include_directories(${CUDA_TOOLKIT_INCLUDE}) include_directories(${CUDA_TOOLKIT_INCLUDE})
endif(NOT WITH_GPU) endif(NOT WITH_GPU)
if(WITH_AVX) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SIMD_FLAG}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${AVX_FLAG}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SIMD_FLAG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${AVX_FLAG}")
else(WITH_AVX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SSE3_FLAG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SSE3_FLAG}")
endif(WITH_AVX)
if(NOT WITH_GPU)
return()
endif()
set(CUDNN_ROOT "" CACHE PATH "CUDNN ROOT") set(CUDNN_ROOT "" CACHE PATH "CUDNN ROOT")
find_path(CUDNN_INCLUDE_DIR cudnn.h find_path(CUDNN_INCLUDE_DIR cudnn.h
PATHS ${CUDNN_ROOT} ${CUDNN_ROOT}/include PATHS ${CUDNN_ROOT} ${CUDNN_ROOT}/include
......
...@@ -12,48 +12,67 @@ ...@@ -12,48 +12,67 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
INCLUDE(ExternalProject) FIND_PACKAGE(Protobuf REQUIRED)
IF(Protobuf_FOUND)
# Check protobuf library version.
execute_process(COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --version
OUTPUT_VARIABLE PROTOBUF_VERSION)
string(REPLACE "libprotoc " "" PROTOBUF_VERSION ${PROTOBUF_VERSION})
#MESSAGE("PROTOBUF_INCLUDE_DIR: " ${PROTOBUF_INCLUDE_DIR})
#MESSAGE("PROTOBUF_LITE_LIBRARY: " ${PROTOBUF_LITE_LIBRARY})
#MESSAGE("PROTOBUF_LIBRARY: " ${PROTOBUF_LIBRARY})
#MESSAGE("PROTOBUF_PROTOC_LIBRARY: " ${PROTOBUF_PROTOC_LIBRARY})
#MESSAGE("PROTOBUF_PROTOC_EXECUTABLE: " ${PROTOBUF_PROTOC_EXECUTABLE})
SET(PROTOBUF_SOURCES_DIR ${THIRD_PARTY_PATH}/protobuf) set(PROTOBUF_3 OFF)
SET(PROTOBUF_INSTALL_DIR ${THIRD_PARTY_PATH}/install/protobuf) if (${PROTOBUF_VERSION} VERSION_GREATER "3.0.0" OR ${PROTOBUF_VERSION} VERSION_EQUAL "3.0.0")
SET(PROTOBUF_INCLUDE_DIR "${PROTOBUF_INSTALL_DIR}/include" CACHE PATH "protobuf include directory." FORCE) set(PROTOBUF_3 ON)
endif()
ELSE()
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR}) INCLUDE(ExternalProject)
SET(PROTOBUF_SOURCES_DIR ${THIRD_PARTY_PATH}/protobuf)
SET(PROTOBUF_INSTALL_DIR ${THIRD_PARTY_PATH}/install/protobuf)
SET(PROTOBUF_INCLUDE_DIR "${PROTOBUF_INSTALL_DIR}/include" CACHE PATH "protobuf include directory." FORCE)
IF(WIN32)
SET(PROTOBUF_LITE_LIBRARY
"${PROTOBUF_INSTALL_DIR}/lib/libprotobuf-lite.lib" CACHE FILEPATH "protobuf lite library." FORCE)
SET(PROTOBUF_LIBRARY
"${PROTOBUF_INSTALL_DIR}/lib/libprotobuf.lib" CACHE FILEPATH "protobuf library." FORCE)
SET(PROTOBUF_PROTOC_LIBRARY
"${PROTOBUF_INSTALL_DIR}/lib/libprotoc.lib" CACHE FILEPATH "protoc library." FORCE)
SET(PROTOBUF_PROTOC_EXECUTABLE "${PROTOBUF_INSTALL_DIR}/bin/protoc.exe" CACHE FILEPATH "protobuf executable." FORCE)
ELSE(WIN32)
SET(PROTOBUF_LITE_LIBRARY
"${PROTOBUF_INSTALL_DIR}/lib/libprotobuf-lite.a" CACHE FILEPATH "protobuf lite library." FORCE)
SET(PROTOBUF_LIBRARY
"${PROTOBUF_INSTALL_DIR}/lib/libprotobuf.a" CACHE FILEPATH "protobuf library." FORCE)
SET(PROTOBUF_PROTOC_LIBRARY
"${PROTOBUF_INSTALL_DIR}/lib/libprotoc.a" CACHE FILEPATH "protoc library." FORCE)
SET(PROTOBUF_PROTOC_EXECUTABLE "${PROTOBUF_INSTALL_DIR}/bin/protoc" CACHE FILEPATH "protobuf executable." FORCE)
ENDIF(WIN32)
IF(WIN32) ExternalProject_Add(
SET(PROTOBUF_LITE_LIBRARY protobuf
"${PROTOBUF_INSTALL_DIR}/lib/libprotobuf-lite.lib" CACHE FILEPATH "protobuf lite library." FORCE) ${EXTERNAL_PROJECT_LOG_ARGS}
SET(PROTOBUF_LIBRARY PREFIX ${PROTOBUF_SOURCES_DIR}
"${PROTOBUF_INSTALL_DIR}/lib/libprotobuf.lib" CACHE FILEPATH "protobuf library." FORCE) UPDATE_COMMAND ""
SET(PROTOBUF_PROTOC_LIBRARY DEPENDS zlib
"${PROTOBUF_INSTALL_DIR}/lib/libprotoc.lib" CACHE FILEPATH "protoc library." FORCE) GIT_REPOSITORY "https://github.com/google/protobuf.git"
SET(PROTOBUF_PROTOC_EXECUTABLE "${PROTOBUF_INSTALL_DIR}/bin/protoc.exe" CACHE FILEPATH "protobuf executable." FORCE) GIT_TAG "9f75c5aa851cd877fb0d93ccc31b8567a6706546"
ELSE(WIN32) CONFIGURE_COMMAND
SET(PROTOBUF_LITE_LIBRARY ${CMAKE_COMMAND} ${PROTOBUF_SOURCES_DIR}/src/protobuf/cmake
"${PROTOBUF_INSTALL_DIR}/lib/libprotobuf-lite.a" CACHE FILEPATH "protobuf lite library." FORCE) -Dprotobuf_BUILD_TESTS=OFF
SET(PROTOBUF_LIBRARY -DZLIB_ROOT:FILEPATH=${ZLIB_ROOT}
"${PROTOBUF_INSTALL_DIR}/lib/libprotobuf.a" CACHE FILEPATH "protobuf library." FORCE) -DCMAKE_POSITION_INDEPENDENT_CODE=ON
SET(PROTOBUF_PROTOC_LIBRARY -DCMAKE_BUILD_TYPE=Release
"${PROTOBUF_INSTALL_DIR}/lib/libprotoc.a" CACHE FILEPATH "protoc library." FORCE) -DCMAKE_INSTALL_PREFIX=${PROTOBUF_INSTALL_DIR}
SET(PROTOBUF_PROTOC_EXECUTABLE "${PROTOBUF_INSTALL_DIR}/bin/protoc" CACHE FILEPATH "protobuf executable." FORCE) -DCMAKE_INSTALL_LIBDIR=lib
ENDIF(WIN32) )
ExternalProject_Add( LIST(APPEND external_project_dependencies protobuf)
protobuf ENDIF()
${EXTERNAL_PROJECT_LOG_ARGS}
PREFIX ${PROTOBUF_SOURCES_DIR} INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
UPDATE_COMMAND ""
DEPENDS zlib
GIT_REPOSITORY "https://github.com/google/protobuf.git"
GIT_TAG "9f75c5aa851cd877fb0d93ccc31b8567a6706546"
CONFIGURE_COMMAND
${CMAKE_COMMAND} ${PROTOBUF_SOURCES_DIR}/src/protobuf/cmake
-Dprotobuf_BUILD_TESTS=OFF
-DZLIB_ROOT:FILEPATH=${ZLIB_ROOT}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=${PROTOBUF_INSTALL_DIR}
-DCMAKE_INSTALL_LIBDIR=lib
)
LIST(APPEND external_project_dependencies protobuf)
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# so that PaddlePaddle can unleash the vectorization power of muticore. # so that PaddlePaddle can unleash the vectorization power of muticore.
INCLUDE(CheckCXXSourceRuns) INCLUDE(CheckCXXSourceRuns)
INCLUDE(CheckCXXSourceCompiles)
IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(MMX_FLAG "-mmmx") set(MMX_FLAG "-mmmx")
...@@ -9,12 +10,14 @@ IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID ...@@ -9,12 +10,14 @@ IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID
set(SSE3_FLAG "-msse3") set(SSE3_FLAG "-msse3")
SET(AVX_FLAG "-mavx") SET(AVX_FLAG "-mavx")
SET(AVX2_FLAG "-mavx2") SET(AVX2_FLAG "-mavx2")
SET(NEON_FLAG "-mfloat-abi=softfp -mfpu=neon")
ELSEIF(MSVC) ELSEIF(MSVC)
set(MMX_FLAG "/arch:MMX") set(MMX_FLAG "/arch:MMX")
set(SSE2_FLAG "/arch:SSE2") set(SSE2_FLAG "/arch:SSE2")
set(SSE3_FLAG "/arch:SSE3") set(SSE3_FLAG "/arch:SSE3")
SET(AVX_FLAG "/arch:AVX") SET(AVX_FLAG "/arch:AVX")
SET(AVX2_FLAG "/arch:AVX2") SET(AVX2_FLAG "/arch:AVX2")
#SET(NEON_FLAG "")
ENDIF() ENDIF()
# Check MMX # Check MMX
...@@ -73,4 +76,26 @@ int main() ...@@ -73,4 +76,26 @@ int main()
return 0; return 0;
}" AVX2_FOUND) }" AVX2_FOUND)
mark_as_advanced(MMX_FOUND SSE2_FOUND SSE3_FOUND AVX_FOUND AVX2_FOUND) # Check NEON
set(CMAKE_REQUIRED_FLAGS ${NEON_FLAG})
CHECK_CXX_SOURCE_COMPILES("
#include <arm_neon.h>
int main()
{
float32x4_t a = {-1.0f, 2.0f, -3.0f, 4.0f};
float32x4_t b = {1.0f, 2.0f, 3.0f, 4.0f};
float32x4_t c = vaddq_f32(a, b);
return 0;
}" NEON_FOUND)
if(NEON_FOUND)
set(SIMD_FLAG ${NEON_FLAG})
else(NEON_FOUND)
if(WITH_AVX)
set(SIMD_FLAG ${AVX_FLAG})
else(WITH_AVX)
set(SIMD_FLAG ${SSE3_FLAG})
endif(WITH_AVX)
endif(NEON_FOUND)
mark_as_advanced(MMX_FOUND SSE2_FOUND SSE3_FOUND AVX_FOUND AVX2_FOUND NEON_FOUND)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册