Skip to content

Commit

Permalink
Merge pull request #91 from mgates3/symv
Browse files Browse the repository at this point in the history
Move [cz]symv and [cz]syr from LAPACK++
  • Loading branch information
mgates3 authored Dec 7, 2024
2 parents 8d770a9 + 3640355 commit 0a63dc7
Show file tree
Hide file tree
Showing 13 changed files with 405 additions and 190 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,8 @@ else()
endif()

if (NOT LAPACK_FOUND)
message( "For [cz]rot, [cz]syr, and [cz]symv, BLAS++ requires a LAPACK library and none was found."
" Ensure that it is accessible in environment variables"
" $CPATH, $LIBRARY_PATH, and $LD_LIBRARY_PATH." )
message( FATAL_ERROR
"BLAS++ requires LAPACK for [cz]rot, [cz]syr, [cz]symv." )
endif()

# BLAS++ doesn't need LAPACKConfig.cmake, which checks version, XBLAS, LAPACKE.
Expand Down
116 changes: 30 additions & 86 deletions cmake/BLASFinder.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,10 @@ endfunction()
# Setup.

#---------------------------------------- compiler
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set( gnu_compiler true )
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "IntelLLVM")
set( intelllvm_compiler true )
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set( intel_compiler true )
endif()

if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "XL|XLClang")
set( ibm_compiler true )
endif()
string( COMPARE EQUAL "${CMAKE_CXX_COMPILER_ID}" "GNU" gnu_compiler)
string( COMPARE EQUAL "${CMAKE_CXX_COMPILER_ID}" "IntelLLVM" intelllvm_compiler )
string( COMPARE EQUAL "${CMAKE_CXX_COMPILER_ID}" "Intel" intel_compiler )
string( REGEX MATCH "XL|XLClang" ibm_compiler "${CMAKE_CXX_COMPILER_ID}" )

#---------------------------------------- Fortran manglings to test
if (ibm_compiler)
Expand Down Expand Up @@ -136,37 +125,13 @@ endif()
#---------------------------------------- blas
string( TOLOWER "${blas}" blas_ )

if ("${blas_}" MATCHES "auto")
set( test_all true )
endif()

if ("${blas_}" MATCHES "acml")
set( test_acml true )
endif()

if ("${blas_}" MATCHES "apple|accelerate")
set( test_accelerate true )
endif()

if ("${blas_}" MATCHES "cray|libsci|default")
set( test_default true )
endif()

if ("${blas_}" MATCHES "ibm|essl")
set( test_essl true )
endif()

if ("${blas_}" MATCHES "intel|mkl")
set( test_mkl true )
endif()

if ("${blas_}" MATCHES "openblas")
set( test_openblas true )
endif()

if ("${blas_}" MATCHES "generic")
set( test_generic true )
endif()
string( REGEX MATCH "auto|acml" test_acml "${blas_}" )
string( REGEX MATCH "auto|ibm|essl" test_essl "${blas_}" )
string( REGEX MATCH "auto|intel|mkl" test_mkl "${blas_}" )
string( REGEX MATCH "auto|openblas" test_openblas "${blas_}" )
string( REGEX MATCH "auto|generic" test_generic "${blas_}" )
string( REGEX MATCH "auto|apple|accelerate" test_accelerate "${blas_}" )
string( REGEX MATCH "auto|cray|libsci|default" test_default "${blas_}" )

message( DEBUG "
BLAS_LIBRARIES = '${BLAS_LIBRARIES}'
Expand All @@ -179,22 +144,13 @@ test_default = '${test_default}'
test_essl = '${test_essl}'
test_mkl = '${test_mkl}'
test_openblas = '${test_openblas}'
test_generic = '${test_generic}'
test_all = '${test_all}'")
test_generic = '${test_generic}'" )

#---------------------------------------- blas_fortran
string( TOLOWER "${blas_fortran}" blas_fortran_ )

if ("${blas_fortran_}" MATCHES "gfortran")
set( test_gfortran true )
endif()
if ("${blas_fortran_}" MATCHES "ifort")
set( test_ifort true )
endif()
if ("${blas_fortran_}" MATCHES "auto")
set( test_gfortran true )
set( test_ifort true )
endif()
string( REGEX MATCH "auto|gfortran" test_gfortran "${blas_fortran_}" )
string( REGEX MATCH "auto|ifort" test_ifort "${blas_fortran_}" )

message( DEBUG "
blas_fortran = '${blas_fortran}'
Expand All @@ -206,16 +162,10 @@ test_ifort = '${test_ifort}'")
string( TOLOWER "${blas_int}" blas_int_ )

# This regex is similar to "\b(lp64|int)\b".
if ("${blas_int_}" MATCHES "(^|[^a-zA-Z0-9_])(lp64|int|int32|int32_t)($|[^a-zA-Z0-9_])")
set( test_int true )
endif()
if ("${blas_int_}" MATCHES "(^|[^a-zA-Z0-9_])(ilp64|int64|int64_t)($|[^a-zA-Z0-9_])")
set( test_int64 true )
endif()
if ("${blas_int_}" MATCHES "auto")
set( test_int true )
set( test_int64 true )
endif()
set( regex_int32 "(^|[^a-zA-Z0-9_])(auto|lp64|int|int32|int32_t)($|[^a-zA-Z0-9_])" )
set( regex_int64 "(^|[^a-zA-Z0-9_])(auto|ilp64|int64|int64_t)($|[^a-zA-Z0-9_])" )
string( REGEX MATCH ${regex_int32} test_int "${blas_int_}" )
string( REGEX MATCH ${regex_int64} test_int64 "${blas_int_}" )

if (CMAKE_CROSSCOMPILING AND test_int AND test_int64)
message( FATAL_ERROR " ${red}When cross-compiling, one must define either\n"
Expand All @@ -232,17 +182,11 @@ test_int64 = '${test_int64}'")
#---------------------------------------- blas_threaded
string( TOLOWER "${blas_threaded}" blas_threaded_ )

# This regex is similar to "\b(yes|...)\b".
if ("${blas_threaded_}" MATCHES "(^|[^a-zA-Z0-9_])(y|yes|true|on|1)($|[^a-zA-Z0-9_])")
set( test_threaded true )
endif()
if ("${blas_threaded_}" MATCHES "(^|[^a-zA-Z0-9_])(n|no|false|off|0)($|[^a-zA-Z0-9_])")
set( test_sequential true )
endif()
if ("${blas_threaded_}" MATCHES "auto")
set( test_threaded true )
set( test_sequential true )
endif()
# These regex are similar to "\b(yes|...)\b".
set( regex_yes "(^|[^a-zA-Z0-9_])(auto|y|yes|true|on|1)($|[^a-zA-Z0-9_])" )
set( regex_no "(^|[^a-zA-Z0-9_])(auto|n|no|false|off|0)($|[^a-zA-Z0-9_])" )
string( REGEX MATCH ${regex_yes} test_threaded "${blas_threaded_}" )
string( REGEX MATCH ${regex_no} test_sequential "${blas_threaded_}" )

message( DEBUG "
blas_threaded = '${blas_threaded}'
Expand Down Expand Up @@ -270,14 +214,14 @@ if (test_blas_libraries)
endif()

#---------------------------------------- default; Cray libsci
if (test_all OR test_default)
if (test_default)
list( APPEND blas_name_list "default (no library)" )
list( APPEND blas_libs_list " " ) # Use space so APPEND works later.
debug_print_list( "default" )
endif()

#---------------------------------------- Intel MKL
if (test_all OR test_mkl)
if (test_mkl)
# todo: MKL_?(ROOT|DIR)
if (test_threaded AND OpenMP_CXX_FOUND)
if (test_gfortran AND gnu_compiler)
Expand Down Expand Up @@ -366,7 +310,7 @@ if (test_all OR test_mkl)
endif() # MKL

#---------------------------------------- IBM ESSL
if (test_all OR test_essl)
if (test_essl)
# todo: ESSL_?(ROOT|DIR)
if (test_threaded)
#message( "essl OpenMP_CXX_FOUND ${OpenMP_CXX_FOUND}" )
Expand Down Expand Up @@ -411,30 +355,30 @@ if (test_all OR test_essl)
endif()

#---------------------------------------- OpenBLAS
if (test_all OR test_openblas)
if (test_openblas)
# todo: OPENBLAS_?(ROOT|DIR)
list( APPEND blas_name_list "OpenBLAS" )
list( APPEND blas_libs_list "-lopenblas" )
debug_print_list( "openblas" )
endif()

#---------------------------------------- Apple Accelerate
if (test_all OR test_accelerate)
if (test_accelerate)
list( APPEND blas_name_list "Apple Accelerate" )
list( APPEND blas_libs_list "-framework Accelerate" )
debug_print_list( "accelerate" )
endif()

#---------------------------------------- generic -lblas
if (test_all OR test_generic)
if (test_generic)
list( APPEND blas_name_list "generic" )
list( APPEND blas_libs_list "-lblas" )
debug_print_list( "generic" )
endif()

#---------------------------------------- AMD ACML
# Deprecated libraries last.
if (test_all OR test_acml)
if (test_acml)
# todo: ACML_?(ROOT|DIR)
if (test_threaded)
list( APPEND blas_name_list "AMD ACML threaded" )
Expand Down
30 changes: 10 additions & 20 deletions cmake/LAPACKFinder.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,16 @@ endif()
#---------------------------------------- lapack
string( TOLOWER "${lapack}" lapack_ )

if ("${lapack_}" MATCHES "auto")
set( test_all true )
endif()

if ("${lapack_}" MATCHES "default")
set( test_default true )
endif()

if ("${lapack_}" MATCHES "generic")
set( test_generic true )
endif()
string( REGEX MATCH "auto|default" test_default "${lapack_}" )
string( REGEX MATCH "auto|generic" test_generic "${lapack_}" )

message( DEBUG "
LAPACK_LIBRARIES = '${LAPACK_LIBRARIES}'
lapack = '${lapack}'
lapack_ = '${lapack_}'
test_lapack_libraries = '${test_lapack_libraries}'
test_default = '${test_default}'
test_generic = '${test_generic}'
test_all = '${test_all}'")
test_generic = '${test_generic}'" )

#-------------------------------------------------------------------------------
# Build list of libraries to check.
Expand All @@ -91,23 +81,23 @@ if (test_lapack_libraries)
endif()

#---------------------------------------- default (in BLAS library)
if (test_all OR test_default)
if (test_default)
list( APPEND lapack_libs_list " " )
endif()

#---------------------------------------- generic -llapack
if (test_all OR test_generic)
if (test_generic)
list( APPEND lapack_libs_list "-llapack" )
endif()

message( DEBUG "lapack_libs_list ${lapack_libs_list}" )

#-------------------------------------------------------------------------------
# Check each LAPACK library.
# BLAS++ needs only a limited subset of LAPACK, so check for potrf (Cholesky).
# LAPACK++ checks for pstrf (Cholesky with pivoting) to make sure it is
# Checks for pstrf (Cholesky with pivoting) to make sure it is
# a complete LAPACK library, since some BLAS libraries (ESSL, ATLAS)
# contain only an optimized subset of LAPACK routines.
# ESSL lacks [cz]symv, [cz]syr.

unset( LAPACK_FOUND CACHE )
unset( lapackpp_defs_ CACHE )
Expand All @@ -124,7 +114,7 @@ foreach (lapack_libs IN LISTS lapack_libs_list)
try_run(
run_result compile_result ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/config/lapack_potrf.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/config/lapack_pstrf.cc"
LINK_LIBRARIES
# Use blaspp_libraries instead of blaspp, when SLATE includes
# blaspp and lapackpp, so the blaspp library doesn't exist yet.
Expand All @@ -139,11 +129,11 @@ foreach (lapack_libs IN LISTS lapack_libs_list)
)
# For cross-compiling, if it links, assume the run is okay.
if (CMAKE_CROSSCOMPILING AND compile_result)
message( DEBUG "cross: lapack_potrf" )
message( DEBUG "cross: lapack_pstrf" )
set( run_result "0" CACHE STRING "" FORCE )
set( run_output "ok" CACHE STRING "" FORCE )
endif()
debug_try_run( "lapack_potrf.cc" "${compile_result}" "${compile_output}"
debug_try_run( "lapack_pstrf.cc" "${compile_result}" "${compile_output}"
"${run_result}" "${run_output}" )

if (NOT compile_result)
Expand Down
5 changes: 3 additions & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def main():

try:
config.lapack.lapack()
except Error:
print_warn( 'BLAS++ needs LAPACK for testers.' )
except Error as ex:
print_warn( 'BLAS++ requires LAPACK for [cz]rot, [cz]syr, [cz]symv.' )
raise( ex )

config.gpu_blas()

Expand Down
Loading

0 comments on commit 0a63dc7

Please sign in to comment.