提交 d2573550 编写于 作者: Z zhouwei25 提交者: Tao Luo

Remove useless code of openblas and fix the previous incorrect message (#21092)

上级 de5d3ff6
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Find the CBlas and lapack libraries # Find the CBlas and lapack libraries
# #
# It will search MKLML, atlas, OpenBlas, reference-cblas in order. # It will search MKLML, atlas, OpenBlas, reference-cblas in order.
...@@ -8,87 +22,111 @@ ...@@ -8,87 +22,111 @@
# CBLAS_LIBS # a list of libraries should be linked by paddle. # CBLAS_LIBS # a list of libraries should be linked by paddle.
# # Each library should be full path to object file. # # Each library should be full path to object file.
set(CBLAS_FOUND OFF) set(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/cblas_dummy.c)
file(WRITE ${dummyfile} "const char *dummy_cblas = \"${dummyfile}\";")
add_library(cblas STATIC ${dummyfile})
if(WITH_LIBXSMM)
target_link_libraries(cblas ${LIBXSMM_LIBS})
add_dependencies(cblas extern_libxsmm)
endif()
## Find MKLML First. ## Find MKLML First.
if(WITH_MKLML AND MKLML_INC_DIR AND MKLML_LIB) if(WITH_MKLML)
set(CBLAS_FOUND ON) include(external/mklml) # download, install mklml package
set(CBLAS_PROVIDER MKLML) set(CBLAS_PROVIDER MKLML)
set(CBLAS_INC_DIR ${MKLML_INC_DIR}) set(CBLAS_INC_DIR ${MKLML_INC_DIR})
set(CBLAS_LIBRARIES ${MKLML_LIB}) set(CBLAS_LIBRARIES ${MKLML_LIB})
add_definitions(-DPADDLE_WITH_MKLML) add_definitions(-DPADDLE_WITH_MKLML)
add_definitions(-DLAPACK_FOUND) add_definitions(-DLAPACK_FOUND)
add_dependencies(cblas mklml)
target_link_libraries(cblas dynload_mklml)
message(STATUS "Found cblas and lapack in MKLML " message(STATUS "Found cblas and lapack in MKLML "
"(include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") "(include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})")
return()
endif() endif()
## Then find openblas. ## Then find openblas.
set(OPENBLAS_ROOT $ENV{OPENBLAS_ROOT} CACHE PATH "Folder contains Openblas") if(NOT DEFINED CBLAS_PROVIDER)
set(OPENBLAS_INCLUDE_SEARCH_PATHS set(OPENBLAS_ROOT $ENV{OPENBLAS_ROOT} CACHE PATH "Folder contains Openblas")
${OPENBLAS_ROOT}/include set(OPENBLAS_INCLUDE_SEARCH_PATHS
/usr/include ${OPENBLAS_ROOT}/include
/usr/include/openblas /usr/include
/usr/local/opt/openblas/include) /usr/include/openblas
set(OPENBLAS_LIB_SEARCH_PATHS /usr/local/opt/openblas/include)
${OPENBLAS_ROOT}/lib set(OPENBLAS_LIB_SEARCH_PATHS
/usr/lib ${OPENBLAS_ROOT}/lib
/usr/lib/blas/openblas /usr/lib
/usr/lib/openblas /usr/lib/blas/openblas
/usr/local/opt/openblas/lib) /usr/lib/openblas
/usr/local/opt/openblas/lib)
find_path(OPENBLAS_INC_DIR NAMES cblas.h
PATHS ${OPENBLAS_INCLUDE_SEARCH_PATHS} NO_DEFAULT_PATH)
find_path(OPENBLAS_LAPACKE_INC_DIR NAMES lapacke.h
PATHS ${OPENBLAS_INCLUDE_SEARCH_PATHS})
find_library(OPENBLAS_LIB NAMES openblas
PATHS ${OPENBLAS_LIB_SEARCH_PATHS})
if(OPENBLAS_LAPACKE_INC_DIR AND OPENBLAS_INC_DIR AND OPENBLAS_LIB)
set(CBLAS_FOUND ON)
set(CBLAS_PROVIDER OPENBLAS)
set(CBLAS_INC_DIR ${OPENBLAS_INC_DIR} ${OPENBLAS_LAPACKE_INC_DIR})
set(CBLAS_LIBRARIES ${OPENBLAS_LIB})
add_definitions(-DPADDLE_USE_OPENBLAS) find_path(OPENBLAS_INC_DIR NAMES cblas.h
add_definitions(-DLAPACK_FOUND) PATHS ${OPENBLAS_INCLUDE_SEARCH_PATHS} NO_DEFAULT_PATH)
find_path(OPENBLAS_LAPACKE_INC_DIR NAMES lapacke.h
PATHS ${OPENBLAS_INCLUDE_SEARCH_PATHS})
find_library(OPENBLAS_LIB NAMES openblas
PATHS ${OPENBLAS_LIB_SEARCH_PATHS})
message(STATUS "Found OpenBLAS (include: ${OPENBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") if(OPENBLAS_LAPACKE_INC_DIR AND OPENBLAS_INC_DIR AND OPENBLAS_LIB)
message(STATUS "Found lapack in OpenBLAS (include: ${OPENBLAS_LAPACKE_INC_DIR})") set(CBLAS_PROVIDER OPENBLAS)
return() set(CBLAS_INC_DIR ${OPENBLAS_INC_DIR} ${OPENBLAS_LAPACKE_INC_DIR})
endif() set(CBLAS_LIBRARIES ${OPENBLAS_LIB})
add_definitions(-DPADDLE_USE_OPENBLAS)
add_definitions(-DLAPACK_FOUND)
## Then find the reference-cblas. www.netlib.org/blas/ message(STATUS "Found OpenBLAS (include: ${OPENBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})")
set(REFERENCE_CBLAS_ROOT $ENV{REFERENCE_CBLAS_ROOT} CACHE PATH message(STATUS "Found lapack in OpenBLAS (include: ${OPENBLAS_LAPACKE_INC_DIR})")
"Folder contains reference-cblas") endif()
set(REFERENCE_CBLAS_INCLUDE_SEARCH_PATHS endif()
${REFERENCE_CBLAS_ROOT}/include
/usr/include
/usr/include/cblas
)
set(REFERENCE_CBLAS_LIB_SEARCH_PATHS ## Then find the reference-cblas if WITH_SYSTEM_BLAS. www.netlib.org/blas/
${REFERENCE_CBLAS_ROOT}/lib if(NOT DEFINED CBLAS_PROVIDER AND WITH_SYSTEM_BLAS)
/usr/lib set(REFERENCE_CBLAS_ROOT $ENV{REFERENCE_CBLAS_ROOT} CACHE PATH
/usr/lib/blas/reference/ "Folder contains reference-cblas")
/usr/lib/reference/ set(REFERENCE_CBLAS_INCLUDE_SEARCH_PATHS
) ${REFERENCE_CBLAS_ROOT}/include
/usr/include
/usr/include/cblas
)
set(REFERENCE_CBLAS_LIB_SEARCH_PATHS
${REFERENCE_CBLAS_ROOT}/lib
/usr/lib
/usr/lib/blas/reference/
/usr/lib/reference/
)
if(WITH_SYSTEM_BLAS)
find_path(REFERENCE_CBLAS_INCLUDE_DIR NAMES cblas.h PATHS find_path(REFERENCE_CBLAS_INCLUDE_DIR NAMES cblas.h PATHS
${REFERENCE_CBLAS_INCLUDE_SEARCH_PATHS}) ${REFERENCE_CBLAS_INCLUDE_SEARCH_PATHS})
find_library(REFERENCE_CBLAS_LIBRARY NAMES cblas PATHS find_library(REFERENCE_CBLAS_LIBRARY NAMES cblas PATHS
${REFERENCE_CBLAS_LIB_SEARCH_PATHS}) ${REFERENCE_CBLAS_LIB_SEARCH_PATHS})
if(REFERENCE_CBLAS_INCLUDE_DIR AND REFERENCE_CBLAS_LIBRARY) if(REFERENCE_CBLAS_INCLUDE_DIR AND REFERENCE_CBLAS_LIBRARY)
set(CBLAS_FOUND ON) set(CBLAS_PROVIDER REFERENCE_CBLAS)
set(CBLAS_PROVIDER REFERENCE)
set(CBLAS_INC_DIR ${REFERENCE_CBLAS_INCLUDE_DIR}) set(CBLAS_INC_DIR ${REFERENCE_CBLAS_INCLUDE_DIR})
set(CBLAS_LIBRARIES ${REFERENCE_CBLAS_LIBRARY}) set(CBLAS_LIBRARIES ${REFERENCE_CBLAS_LIBRARY})
add_definitions(-DPADDLE_USE_REFERENCE_CBLAS) add_definitions(-DPADDLE_USE_REFERENCE_CBLAS)
message(STATUS "Found reference-cblas (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})") message(STATUS "Found reference-cblas (include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})")
endif() endif()
endif() endif()
## Then build openblas by external_project
if(NOT DEFINED CBLAS_PROVIDER)
include(external/openblas) # download, build, install openblas
set(CBLAS_PROVIDER EXTERN_OPENBLAS)
add_dependencies(cblas extern_openblas)
add_definitions(-DPADDLE_USE_OPENBLAS)
message(STATUS "Build OpenBLAS by External Project "
"(include: ${CBLAS_INC_DIR}, library: ${CBLAS_LIBRARIES})")
endif()
# FIXME(gangliao): generate cblas target to track all high performance
# linear algebra libraries for cc_library(xxx SRCS xxx.c DEPS cblas)
include_directories(${CBLAS_INC_DIR})
if(NOT ${CBLAS_PROVIDER} STREQUAL MKLML)
target_link_libraries(cblas ${CBLAS_LIBRARIES})
endif()
\ No newline at end of file
...@@ -11,27 +11,16 @@ ...@@ -11,27 +11,16 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# 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(cblas)
IF(NOT ${CBLAS_FOUND}) INCLUDE(ExternalProject)
INCLUDE(ExternalProject)
SET(CBLAS_SOURCES_DIR ${THIRD_PARTY_PATH}/openblas)
SET(CBLAS_INSTALL_DIR ${THIRD_PARTY_PATH}/install/openblas)
SET(CBLAS_INC_DIR "${CBLAS_INSTALL_DIR}/include" CACHE PATH "openblas include directory." FORCE)
SET(CBLAS_SOURCES_DIR ${THIRD_PARTY_PATH}/openblas)
SET(CBLAS_INSTALL_DIR ${THIRD_PARTY_PATH}/install/openblas)
IF(NOT WIN32)
SET(CBLAS_LIBRARIES SET(CBLAS_LIBRARIES
"${CBLAS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}openblas${CMAKE_STATIC_LIBRARY_SUFFIX}" "${CBLAS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}openblas${CMAKE_STATIC_LIBRARY_SUFFIX}"
CACHE FILEPATH "openblas library." FORCE) CACHE FILEPATH "openblas library." FORCE)
SET(CBLAS_INC_DIR "${CBLAS_INSTALL_DIR}/include" CACHE PATH "openblas include directory." FORCE)
ADD_DEFINITIONS(-DPADDLE_USE_OPENBLAS)
IF (WIN32)
SET(CBLAS_FOUND true)
MESSAGE(WARNING, "In windows, openblas only support msvc build, please build it manually and put it at " ${CBLAS_INSTALL_DIR})
ENDIF(WIN32)
IF (NOT WIN32)
SET(OPENBLAS_CC "${CMAKE_C_COMPILER} -Wno-unused-but-set-variable -Wno-unused-variable") SET(OPENBLAS_CC "${CMAKE_C_COMPILER} -Wno-unused-but-set-variable -Wno-unused-variable")
SET(OPENBLAS_COMMIT "v0.2.20") SET(OPENBLAS_COMMIT "v0.2.20")
...@@ -59,70 +48,31 @@ IF(NOT ${CBLAS_FOUND}) ...@@ -59,70 +48,31 @@ IF(NOT ${CBLAS_FOUND})
UPDATE_COMMAND "" UPDATE_COMMAND ""
CONFIGURE_COMMAND "" CONFIGURE_COMMAND ""
) )
ELSE(NOT WIN32) ELSE(NOT WIN32)
SET(CBLAS_FOUND false) SET(CBLAS_LIBRARIES
SET(CBLAS_LIBRARIES "${CBLAS_INSTALL_DIR}/lib/openblas${CMAKE_STATIC_LIBRARY_SUFFIX}"
"${CBLAS_INSTALL_DIR}/lib/openblas${CMAKE_STATIC_LIBRARY_SUFFIX}" CACHE FILEPATH "openblas library." FORCE)
CACHE FILEPATH "openblas library." FORCE) SET(CBLAS_INC_DIR "${CBLAS_INSTALL_DIR}/include/openblas" CACHE PATH "openblas include directory." FORCE)
INCLUDE_DIRECTORIES(${CBLAS_INC_DIR}/openblas) # For openbals code to include its own headers. ExternalProject_Add(
INCLUDE_DIRECTORIES(${THIRD_PARTY_PATH}/install) extern_openblas
ExternalProject_Add( ${EXTERNAL_PROJECT_LOG_ARGS}
extern_openblas GIT_REPOSITORY https://github.com/xianyi/OpenBLAS.git
${EXTERNAL_PROJECT_LOG_ARGS} GIT_TAG "v0.3.7"
GIT_REPOSITORY https://github.com/xianyi/OpenBLAS.git PREFIX ${CBLAS_SOURCES_DIR}
GIT_TAG "v0.3.7" INSTALL_DIR ${CBLAS_INSTALL_DIR}
PREFIX ${CBLAS_SOURCES_DIR} BUILD_IN_SOURCE 0
INSTALL_DIR ${CBLAS_INSTALL_DIR} UPDATE_COMMAND ""
BUILD_IN_SOURCE 0 CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
UPDATE_COMMAND "" -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
CMAKE_ARGS -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS} -DCMAKE_INSTALL_PREFIX=${CBLAS_INSTALL_DIR}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCMAKE_INSTALL_PREFIX=${CBLAS_INSTALL_DIR} -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DMSVC_STATIC_CRT=${MSVC_STATIC_CRT}
-DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE} ${EXTERNAL_OPTIONAL_ARGS}
-DBUILD_SHARED_LIBS=ON CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CBLAS_INSTALL_DIR}
-DMSVC_STATIC_CRT=${MSVC_STATIC_CRT} -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
${EXTERNAL_OPTIONAL_ARGS} -DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE}
CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CBLAS_INSTALL_DIR} )
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON ENDIF(NOT WIN32)
-DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE}
)
add_custom_command(TARGET extern_openblas POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CBLAS_INSTALL_DIR}/bin/openblas${CMAKE_SHARED_LIBRARY_SUFFIX} ${CBLAS_INSTALL_DIR}/lib )
ADD_LIBRARY(openblas STATIC IMPORTED GLOBAL)
SET_PROPERTY(TARGET openblas PROPERTY IMPORTED_LOCATION ${CBLAS_LIBRARIES})
ADD_DEPENDENCIES(openblas extern_openblas)
ENDIF(NOT WIN32)
SET(CBLAS_PROVIDER openblas)
ENDIF(NOT ${CBLAS_FOUND})
MESSAGE(STATUS "BLAS library: ${CBLAS_LIBRARIES}")
MESSAGE(STATUS "BLAS Include: ${CBLAS_INC_DIR}")
INCLUDE_DIRECTORIES(${CBLAS_INC_DIR})
# FIXME(gangliao): generate cblas target to track all high performance
# linear algebra libraries for cc_library(xxx SRCS xxx.c DEPS cblas)
SET(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/cblas_dummy.c)
FILE(WRITE ${dummyfile} "const char *dummy_cblas = \"${dummyfile}\";")
ADD_LIBRARY(cblas STATIC ${dummyfile})
IF("${CBLAS_PROVIDER}" STREQUAL "MKLML")
TARGET_LINK_LIBRARIES(cblas dynload_mklml)
ELSE()
TARGET_LINK_LIBRARIES(cblas ${CBLAS_LIBRARIES})
ENDIF("${CBLAS_PROVIDER}" STREQUAL "MKLML")
IF(WITH_LIBXSMM)
TARGET_LINK_LIBRARIES(cblas ${LIBXSMM_LIBS})
ADD_DEPENDENCIES(cblas extern_libxsmm)
ENDIF()
IF(NOT ${CBLAS_FOUND})
ADD_DEPENDENCIES(cblas extern_openblas)
ELSE()
IF("${CBLAS_PROVIDER}" STREQUAL "MKLML")
ADD_DEPENDENCIES(cblas mklml)
ENDIF()
ENDIF(NOT ${CBLAS_FOUND})
...@@ -76,8 +76,8 @@ if(WIN32 OR APPLE) ...@@ -76,8 +76,8 @@ if(WIN32 OR APPLE)
endif() endif()
set(WITH_MKLML ${WITH_MKL}) set(WITH_MKLML ${WITH_MKL})
if (NOT DEFINED WITH_MKLDNN) if(NOT DEFINED WITH_MKLDNN)
if (WITH_MKL AND AVX2_FOUND) if(WITH_MKL AND AVX2_FOUND)
set(WITH_MKLDNN ON) set(WITH_MKLDNN ON)
else() else()
message(STATUS "Do not have AVX2 intrinsics and disabled MKL-DNN") message(STATUS "Do not have AVX2 intrinsics and disabled MKL-DNN")
...@@ -113,12 +113,11 @@ if(WITH_AMD_GPU) ...@@ -113,12 +113,11 @@ if(WITH_AMD_GPU)
list(APPEND third_party_deps extern_rocprim) list(APPEND third_party_deps extern_rocprim)
endif() endif()
if(WITH_MKLML) include(cblas) # find first, then download, build, install openblas
include(external/mklml) # download, install mklml package if(${CBLAS_PROVIDER} STREQUAL MKLML)
list(APPEND third_party_deps extern_mklml) list(APPEND third_party_deps extern_mklml)
endif() endif()
include(external/openblas) # find first, then download, build, install openblas if(${CBLAS_PROVIDER} STREQUAL EXTERN_OPENBLAS)
if(NOT CBLAS_FOUND)
list(APPEND third_party_deps extern_openblas) list(APPEND third_party_deps extern_openblas)
endif() endif()
...@@ -127,7 +126,7 @@ if(WITH_MKLDNN) ...@@ -127,7 +126,7 @@ if(WITH_MKLDNN)
list(APPEND third_party_deps extern_mkldnn) list(APPEND third_party_deps extern_mkldnn)
endif() endif()
include(external/protobuf) # find first, then download, build, install protobuf include(external/protobuf) # find first, then download, build, install protobuf
if(NOT PROTOBUF_FOUND OR WIN32) if(NOT PROTOBUF_FOUND OR WIN32)
list(APPEND third_party_deps extern_protobuf) list(APPEND third_party_deps extern_protobuf)
endif() endif()
...@@ -189,20 +188,20 @@ if(WITH_NGRAPH) ...@@ -189,20 +188,20 @@ if(WITH_NGRAPH)
endif() endif()
if(WITH_XBYAK) if(WITH_XBYAK)
include(external/xbyak) # download, build, install xbyak include(external/xbyak) # download, build, install xbyak
list(APPEND third_party_deps extern_xbyak) list(APPEND third_party_deps extern_xbyak)
endif() endif()
if(WITH_LIBXSMM) if(WITH_LIBXSMM)
include(external/libxsmm) # download, build, install libxsmm include(external/libxsmm) # download, build, install libxsmm
list(APPEND third_party_deps extern_libxsmm) list(APPEND third_party_deps extern_libxsmm)
endif() endif()
if(WITH_DGC) if(WITH_DGC)
message(STATUS "add dgc lib.") message(STATUS "add dgc lib.")
include(external/dgc) # download, build, install dgc include(external/dgc) # download, build, install dgc
add_definitions(-DPADDLE_WITH_DGC) add_definitions(-DPADDLE_WITH_DGC)
list(APPEND third_party_deps extern_dgc) list(APPEND third_party_deps extern_dgc)
endif() endif()
add_custom_target(third_party DEPENDS ${third_party_deps}) add_custom_target(third_party DEPENDS ${third_party_deps})
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册