improved blas/lapack cmake scripts

This commit is contained in:
Ronan Collobert
2012-03-05 10:51:11 +01:00
parent 2ba221f9f3
commit c17cb214b3
3 changed files with 148 additions and 82 deletions

View File

@ -17,19 +17,11 @@ SET(BLAS_INCLUDE_DIR)
SET(BLAS_INFO)
SET(BLAS_F2C)
# CBLAS in Intel mkl
FIND_PACKAGE(MKL)
IF (MKL_FOUND AND NOT BLAS_LIBRARIES)
SET(BLAS_INFO imkl)
SET(BLAS_LIBRARIES ${MKL_LIBRARIES})
SET(BLAS_INCLUDE_DIR ${MKL_INCLUDE_DIR})
SET(BLAS_VERSION ${MKL_VERSION})
ENDIF (MKL_FOUND AND NOT BLAS_LIBRARIES)
SET(WITH_BLAS "" CACHE STRING "Blas type [mkl/open/goto/acml/atlas/accelerate/veclib/generic]")
# Old FindBlas
INCLUDE(CheckCSourceRuns)
INCLUDE(CheckFortranFunctionExists)
SET(_verbose TRUE)
MACRO(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list)
# This macro checks for the existence of the combination of fortran libraries
@ -50,9 +42,7 @@ MACRO(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list)
set(__list "${_elem}")
endif(__list)
endforeach(_elem)
if(_verbose)
message(STATUS "Checking for [${__list}]")
endif(_verbose)
message(STATUS "Checking for [${__list}]")
set(_libraries_work TRUE)
set(${LIBRARIES})
@ -80,6 +70,7 @@ MACRO(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list)
mark_as_advanced(${_prefix}_${_library}_LIBRARY)
set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
MESSAGE(STATUS " Library ${_library}: ${${_prefix}_${_library}_LIBRARY}")
endif(_libraries_work)
endforeach(_library ${_list})
if(_libraries_work)
@ -99,9 +90,60 @@ MACRO(Check_Fortran_Libraries LIBRARIES _prefix _name _flags _list)
endif(NOT _libraries_work)
endmacro(Check_Fortran_Libraries)
# Intel MKL?
if((NOT BLAS_LIBRARIES)
AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "mkl")))
FIND_PACKAGE(MKL)
IF(MKL_FOUND)
SET(BLAS_INFO "mkl")
SET(BLAS_LIBRARIES ${MKL_LIBRARIES})
SET(BLAS_INCLUDE_DIR ${MKL_INCLUDE_DIR})
SET(BLAS_VERSION ${MKL_VERSION})
ENDIF(MKL_FOUND)
endif()
if((NOT BLAS_LIBRARIES)
AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "open")))
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"openblas;gfortran")
if(BLAS_LIBRARIES)
set(BLAS_INFO "open")
endif(BLAS_LIBRARIES)
endif()
if((NOT BLAS_LIBRARIES)
AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "goto")))
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"goto2;gfortran")
if (BLAS_LIBRARIES)
set(BLAS_INFO "goto")
endif (BLAS_LIBRARIES)
endif()
if((NOT BLAS_LIBRARIES)
AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "acml")))
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
sgemm
""
"acml;gfortran")
if (BLAS_LIBRARIES)
set(BLAS_INFO "acml")
endif (BLAS_LIBRARIES)
endif()
# Apple BLAS library?
if(NOT BLAS_LIBRARIES)
if((NOT BLAS_LIBRARIES)
AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "accelerate")))
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
@ -111,8 +153,10 @@ if(NOT BLAS_LIBRARIES)
if (BLAS_LIBRARIES)
set(BLAS_INFO "accelerate")
endif (BLAS_LIBRARIES)
endif(NOT BLAS_LIBRARIES)
if ( NOT BLAS_LIBRARIES )
endif()
if((NOT BLAS_LIBRARIES)
AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "veclib")))
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
@ -122,10 +166,11 @@ if ( NOT BLAS_LIBRARIES )
if (BLAS_LIBRARIES)
set(BLAS_INFO "veclib")
endif (BLAS_LIBRARIES)
endif ( NOT BLAS_LIBRARIES )
endif()
# BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
if(NOT BLAS_LIBRARIES)
if((NOT BLAS_LIBRARIES)
AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "atlas")))
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
@ -135,10 +180,11 @@ if(NOT BLAS_LIBRARIES)
if (BLAS_LIBRARIES)
set(BLAS_INFO "atlas")
endif (BLAS_LIBRARIES)
endif(NOT BLAS_LIBRARIES)
endif()
# Generic BLAS library?
if(NOT BLAS_LIBRARIES)
if((NOT BLAS_LIBRARIES)
AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "generic")))
check_fortran_libraries(
BLAS_LIBRARIES
BLAS
@ -148,7 +194,7 @@ if(NOT BLAS_LIBRARIES)
if (BLAS_LIBRARIES)
set(BLAS_INFO "generic")
endif (BLAS_LIBRARIES)
endif(NOT BLAS_LIBRARIES)
endif()
# Determine if blas was compiled with the f2c conventions
IF (BLAS_LIBRARIES)
@ -178,9 +224,7 @@ int main() {
exit((float)r != (float).1234);
}" BLAS_F2C_FLOAT_WORKS )
IF (BLAS_F2C_DOUBLE_WORKS AND NOT BLAS_F2C_FLOAT_WORKS)
IF (_verbose)
MESSAGE(STATUS "This BLAS uses the F2C return conventions")
ENDIF(_verbose)
MESSAGE(STATUS "This BLAS uses the F2C return conventions")
SET(BLAS_F2C TRUE)
ELSE (BLAS_F2C_DOUBLE_WORKS AND NOT BLAS_F2C_FLOAT_WORKS)
SET(BLAS_F2C FALSE)
@ -205,8 +249,3 @@ IF(NOT BLAS_FIND_QUIETLY)
MESSAGE(STATUS "Cannot find a library with BLAS API. Not using BLAS.")
ENDIF(BLAS_FOUND)
ENDIF(NOT BLAS_FIND_QUIETLY)

View File

@ -9,6 +9,9 @@
# LAPACK_FOUND - set to true if a library implementing the LAPACK interface is found
# LAPACK_LIBRARIES - list of libraries (using full path name) for LAPACK
# Note: I do not think it is a good idea to mixup different BLAS/LAPACK versions
# Hence, this script wants to find a Lapack library matching your Blas library
SET(LAPACK_LIBRARIES)
SET(LAPACK_INFO)
@ -18,17 +21,6 @@ ELSE(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
FIND_PACKAGE(BLAS REQUIRED)
ENDIF(LAPACK_FIND_QUIETLY OR NOT LAPACK_FIND_REQUIRED)
# LAPACK in Intel mkl
IF (MKL_FOUND AND NOT LAPACK_LIBRARIES)
IF(MKL_LAPACK_LIBRARIES)
SET(LAPACK_LIBRARIES ${MKL_LAPACK_LIBRARIES} ${MKL_LIBRARIES})
ELSE(MKL_LAPACK_LIBRARIES)
SET(LAPACK_LIBRARIES ${MKL_LIBRARIES})
ENDIF(MKL_LAPACK_LIBRARIES)
SET(LAPACK_INCLUDE_DIR ${MKL_INCLUDE_DIR})
SET(LAPACK_INFO "mkl")
ENDIF (MKL_FOUND AND NOT LAPACK_LIBRARIES)
# Old search lapack script
include(CheckFortranFunctionExists)
@ -88,53 +80,104 @@ endmacro(Check_Lapack_Libraries)
if(BLAS_FOUND)
# Intel MKL
IF((NOT LAPACK_LIBRARIES) AND (BLAS_INFO STREQUAL "mkl"))
IF(MKL_LAPACK_LIBRARIES)
SET(LAPACK_LIBRARIES ${MKL_LAPACK_LIBRARIES} ${MKL_LIBRARIES})
ELSE(MKL_LAPACK_LIBRARIES)
SET(LAPACK_LIBRARIES ${MKL_LIBRARIES})
ENDIF(MKL_LAPACK_LIBRARIES)
SET(LAPACK_INCLUDE_DIR ${MKL_INCLUDE_DIR})
SET(LAPACK_INFO "mkl")
ENDIF()
#acml lapack
if(NOT LAPACK_LIBRARIES)
# OpenBlas
IF((NOT LAPACK_LIBRARIES) AND (BLAS_INFO STREQUAL "open"))
check_lapack_libraries(
LAPACK_LIBRARIES
LAPACK
cheev
""
"acml"
""
"${BLAS_LIBRARIES}"
)
if(LAPACK_LIBRARIES)
SET(LAPACK_INFO "openblas")
else(LAPACK_LIBRARIES)
message(STATUS "It seems OpenBlas has not been compiled with Lapack support")
endif(LAPACK_LIBRARIES)
endif()
# Goto2
IF((NOT LAPACK_LIBRARIES) AND (BLAS_INFO STREQUAL "goto"))
check_lapack_libraries(
LAPACK_LIBRARIES
LAPACK
cheev
""
""
"${BLAS_LIBRARIES}"
)
if(LAPACK_LIBRARIES)
SET(LAPACK_INFO "goto")
else(LAPACK_LIBRARIES)
message(STATUS "It seems GotoBlas has not been compiled with Lapack support")
endif(LAPACK_LIBRARIES)
endif()
#acml lapack
IF((NOT LAPACK_LIBRARIES) AND (BLAS_INFO STREQUAL "acml"))
check_lapack_libraries(
LAPACK_LIBRARIES
LAPACK
cheev
""
""
"${BLAS_LIBRARIES}"
)
if(LAPACK_LIBRARIES)
SET(LAPACK_INFO "acml")
else(LAPACK_LIBRARIES)
message(STATUS "Strangely, your ACML library does not support Lapack?!")
endif(LAPACK_LIBRARIES)
endif(NOT LAPACK_LIBRARIES)
endif()
# Apple LAPACK library?
if(NOT LAPACK_LIBRARIES)
IF((NOT LAPACK_LIBRARIES) AND (BLAS_INFO STREQUAL "accelerate"))
check_lapack_libraries(
LAPACK_LIBRARIES
LAPACK
cheev
""
"Accelerate"
""
"${BLAS_LIBRARIES}"
)
if(LAPACK_LIBRARIES)
SET(LAPACK_INFO "Accelerate")
SET(LAPACK_INFO "accelerate")
else(LAPACK_LIBRARIES)
message(STATUS "Strangely, your Accelerate library does not support Lapack?!")
endif(LAPACK_LIBRARIES)
endif(NOT LAPACK_LIBRARIES)
endif()
if ( NOT LAPACK_LIBRARIES )
IF((NOT LAPACK_LIBRARIES) AND (BLAS_INFO STREQUAL "veclib"))
check_lapack_libraries(
LAPACK_LIBRARIES
LAPACK
cheev
""
"vecLib"
""
"${BLAS_LIBRARIES}"
)
if(LAPACK_LIBRARIES)
SET(LAPACK_INFO "veclib")
else(LAPACK_LIBRARIES)
message(STATUS "Strangely, your vecLib library does not support Lapack?!")
endif(LAPACK_LIBRARIES)
endif ( NOT LAPACK_LIBRARIES )
endif()
# Generic LAPACK library?
if ( NOT LAPACK_LIBRARIES )
IF((NOT LAPACK_LIBRARIES) AND (BLAS_INFO STREQUAL "generic"))
check_lapack_libraries(
LAPACK_LIBRARIES
LAPACK
@ -146,7 +189,7 @@ if(BLAS_FOUND)
if(LAPACK_LIBRARIES)
SET(LAPACK_INFO "generic")
endif(LAPACK_LIBRARIES)
endif ( NOT LAPACK_LIBRARIES )
endif()
else(BLAS_FOUND)
message(STATUS "LAPACK requires BLAS")

View File

@ -28,9 +28,6 @@ SET(MKL_CDFT_LIBRARIES)
INCLUDE(CheckTypeSize)
INCLUDE(CheckFunctionExists)
# Prints diagnostic
# SET(_verbose TRUE)
# Intel Compiler Suite
SET(INTEL_COMPILER_DIR CACHE STRING
"Root directory of the Intel Compiler Suite (contains ipp, mkl, etc.)")
@ -95,21 +92,20 @@ MACRO(CHECK_ALL_LIBRARIES LIBRARIES _name _list _flags)
# N.B. _prefix is the prefix applied to the names of all cached variables that
# are generated internally and marked advanced by this macro.
SET(_prefix "${LIBRARIES}")
IF (_verbose)
SET(__list)
FOREACH(_elem ${_list})
IF(__list)
SET(__list "${__list} - ${_elem}")
ELSE(__list)
SET(__list "${_elem}")
ENDIF(__list)
ENDFOREACH(_elem)
ENDIF(_verbose)
# start checking
SET(_libraries_work TRUE)
SET(${LIBRARIES})
SET(_combined_name)
SET(_paths)
set(__list)
foreach(_elem ${_list})
if(__list)
set(__list "${__list} - ${_elem}")
else(__list)
set(__list "${_elem}")
endif(__list)
endforeach(_elem)
message(STATUS "Checking for [${__list}]")
FOREACH(_library ${_list})
SET(_combined_name ${_combined_name}_${_library})
IF(_libraries_work)
@ -117,6 +113,11 @@ MACRO(CHECK_ALL_LIBRARIES LIBRARIES _name _list _flags)
MARK_AS_ADVANCED(${_prefix}_${_library}_LIBRARY)
SET(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
SET(_libraries_work ${${_prefix}_${_library}_LIBRARY})
IF(${_prefix}_${_library}_LIBRARY)
MESSAGE(STATUS " Library ${_library}: ${${_prefix}_${_library}_LIBRARY}")
ELSE(${_prefix}_${_library}_LIBRARY)
MESSAGE(STATUS " Library ${_library}: not found")
ENDIF(${_prefix}_${_library}_LIBRARY)
ENDIF(_libraries_work)
ENDFOREACH(_library ${_list})
# Test this combination of libraries.
@ -129,15 +130,9 @@ MACRO(CHECK_ALL_LIBRARIES LIBRARIES _name _list _flags)
ENDIF(_libraries_work)
# Fin
IF(_libraries_work)
IF (_verbose)
MESSAGE(STATUS "FindMKL: ${__list} : ok")
ENDIF (_verbose)
ELSE (_libraries_work)
SET(${LIBRARIES})
MARK_AS_ADVANCED(${LIBRARIES})
IF (_verbose)
MESSAGE(STATUS "FindMKL: ${__list} : no")
ENDIF (_verbose)
ENDIF(_libraries_work)
ENDMACRO(CHECK_ALL_LIBRARIES)
@ -245,17 +240,6 @@ ELSE (MKL_LIBRARIES)
SET(MKL_VERSION)
ENDIF (MKL_LIBRARIES)
# Results
IF (_verbose)
MESSAGE(STATUS "*** MKL_FOUND = ${MKL_FOUND}")
MESSAGE(STATUS "*** MKL_INCLUDE_DIR = ${MKL_INCLUDE_DIR}")
MESSAGE(STATUS "*** MKL_LIBRARIES = ${MKL_LIBRARIES}")
MESSAGE(STATUS "*** MKL_LAPACK_LIBRARIES = ${MKL_LAPACK_LIBRARIES}")
MESSAGE(STATUS "*** MKL_SCALAPACK_LIBRARIES = ${MKL_SCALAPACK_LIBRARIES}")
MESSAGE(STATUS "*** MKL_SOLVER_LIBRARIES = ${MKL_SOLVER_LIBRARIES}")
MESSAGE(STATUS "*** MKL_CDFT_LIBRARIES = ${MKL_CDFT_LIBRARIES}")
ENDIF(_verbose)
# Standard termination
IF(NOT MKL_FOUND AND MKL_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "MKL library not found. Please specify library location")