Skip to content
FindBLAS.cmake 42.8 KiB
Newer Older
Luker's avatar
Luker committed
      set (BLAS_VENDOR_FOUND "SGIMATH")
  endif()

endif ()


# BLAS in IBM ESSL library (requires generic BLAS lib, too)
if (BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")

  if(NOT BLAS_LIBRARIES)
    check_fortran_libraries(
Luker's avatar
Luker committed
      BLAS_LIBRARIES
      BLAS
      sgemm
      ""
Luker's avatar
Luker committed
      "essl;xlfmath;xlf90_r;blas"
      ""
Luker's avatar
Luker committed
      )
Luker's avatar
Luker committed
    if(NOT BLAS_FIND_QUIETLY)
      if(BLAS_LIBRARIES)
	message(STATUS "Looking for IBM ESSL BLAS: found")
      else()
	message(STATUS "Looking for IBM ESSL BLAS: not found")
      endif()
Luker's avatar
Luker committed
    endif()
Luker's avatar
Luker committed
  endif()
Luker's avatar
Luker committed

Luker's avatar
Luker committed
  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
      set (BLAS_VENDOR_FOUND "IBM ESSL")
  endif()

endif ()

# BLAS in IBM ESSL_MT library (requires generic BLAS lib, too)
if (BLA_VENDOR STREQUAL "IBMESSLMT" OR BLA_VENDOR STREQUAL "All")

  if(NOT BLAS_LIBRARIES)
    check_fortran_libraries(
Luker's avatar
Luker committed
      BLAS_LIBRARIES
      BLAS
      sgemm
      ""
Luker's avatar
Luker committed
      "esslsmp;xlsmp;xlfmath;xlf90_r;blas"
      ""
Luker's avatar
Luker committed
      )
Luker's avatar
Luker committed
    if(NOT BLAS_FIND_QUIETLY)
      if(BLAS_LIBRARIES)
	message(STATUS "Looking for IBM ESSL MT BLAS: found")
      else()
	message(STATUS "Looking for IBM ESSL MT BLAS: not found")
      endif()
Luker's avatar
Luker committed
    endif()
Luker's avatar
Luker committed
  endif()
Luker's avatar
Luker committed

Luker's avatar
Luker committed
  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
      set (BLAS_VENDOR_FOUND "IBM ESSL MT")
  endif()

endif ()


#BLAS in acml library?
if (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All")

  if( ((BLA_VENDOR STREQUAL "ACML") AND (NOT BLAS_ACML_LIB_DIRS)) OR
      ((BLA_VENDOR STREQUAL "ACML_MP") AND (NOT BLAS_ACML_MP_LIB_DIRS)) OR
      ((BLA_VENDOR STREQUAL "ACML_GPU") AND (NOT BLAS_ACML_GPU_LIB_DIRS)))

    # try to find acml in "standard" paths
    if( WIN32 )
      file( GLOB _ACML_ROOT "C:/AMD/acml*/ACML-EULA.txt" )
    else()
      file( GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt" )
    endif()
    if( WIN32 )
      file( GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples" )
    else()
      file( GLOB _ACML_GPU_ROOT "/opt/acml*/GPGPUexamples" )
    endif()
    list(GET _ACML_ROOT 0 _ACML_ROOT)
    list(GET _ACML_GPU_ROOT 0 _ACML_GPU_ROOT)

    if( _ACML_ROOT )

      get_filename_component( _ACML_ROOT ${_ACML_ROOT} PATH )
      if( SIZEOF_INTEGER EQUAL 8 )
	set( _ACML_PATH_SUFFIX "_int64" )
      else()
	set( _ACML_PATH_SUFFIX "" )
      endif()
      if( CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" )
	set( _ACML_COMPILER32 "ifort32" )
	set( _ACML_COMPILER64 "ifort64" )
      elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro" )
	set( _ACML_COMPILER32 "sun32" )
	set( _ACML_COMPILER64 "sun64" )
      elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "PGI" )
	set( _ACML_COMPILER32 "pgi32" )
	if( WIN32 )
	  set( _ACML_COMPILER64 "win64" )
	else()
	  set( _ACML_COMPILER64 "pgi64" )
	endif()
      elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "Open64" )
	# 32 bit builds not supported on Open64 but for code simplicity
	# We'll just use the same directory twice
	set( _ACML_COMPILER32 "open64_64" )
	set( _ACML_COMPILER64 "open64_64" )
      elseif( CMAKE_Fortran_COMPILER_ID STREQUAL "NAG" )
	set( _ACML_COMPILER32 "nag32" )
	set( _ACML_COMPILER64 "nag64" )
      else()
	set( _ACML_COMPILER32 "gfortran32" )
	set( _ACML_COMPILER64 "gfortran64" )
      endif()

      if( BLA_VENDOR STREQUAL "ACML_MP" )
	set(_ACML_MP_LIB_DIRS
	  "${_ACML_ROOT}/${_ACML_COMPILER32}_mp${_ACML_PATH_SUFFIX}/lib"
	  "${_ACML_ROOT}/${_ACML_COMPILER64}_mp${_ACML_PATH_SUFFIX}/lib" )
      else()
	set(_ACML_LIB_DIRS
	  "${_ACML_ROOT}/${_ACML_COMPILER32}${_ACML_PATH_SUFFIX}/lib"
	  "${_ACML_ROOT}/${_ACML_COMPILER64}${_ACML_PATH_SUFFIX}/lib" )
      endif()

    endif(_ACML_ROOT)

  elseif(BLAS_${BLA_VENDOR}_LIB_DIRS)

    set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS})

  endif()

  if( BLA_VENDOR STREQUAL "ACML_MP" )
    foreach( BLAS_ACML_MP_LIB_DIRS ${_ACML_MP_LIB_DIRS})
      check_fortran_libraries (
	BLAS_LIBRARIES
	BLAS
	sgemm
	"" "acml_mp;acml_mv" "" ${BLAS_ACML_MP_LIB_DIRS}
	)
      if( BLAS_LIBRARIES )
	break()
      endif()
    endforeach()
  elseif( BLA_VENDOR STREQUAL "ACML_GPU" )
    foreach( BLAS_ACML_GPU_LIB_DIRS ${_ACML_GPU_LIB_DIRS})
      check_fortran_libraries (
	BLAS_LIBRARIES
	BLAS
	sgemm
	"" "acml;acml_mv;CALBLAS" "" ${BLAS_ACML_GPU_LIB_DIRS}
	)
      if( BLAS_LIBRARIES )
	break()
      endif()
    endforeach()
  else()
    foreach( BLAS_ACML_LIB_DIRS ${_ACML_LIB_DIRS} )
      check_fortran_libraries (
	BLAS_LIBRARIES
	BLAS
	sgemm
	"" "acml;acml_mv" "" ${BLAS_ACML_LIB_DIRS}
	)
      if( BLAS_LIBRARIES )
	break()
      endif()
    endforeach()
  endif()

  # Either acml or acml_mp should be in LD_LIBRARY_PATH but not both
  if(NOT BLAS_LIBRARIES)
    check_fortran_libraries(
Luker's avatar
Luker committed
      BLAS_LIBRARIES
      BLAS
      sgemm
      ""
Luker's avatar
Luker committed
      "acml;acml_mv"
      ""
Luker's avatar
Luker committed
      )
Luker's avatar
Luker committed
    if(NOT BLAS_FIND_QUIETLY)
      if(BLAS_LIBRARIES)
	message(STATUS "Looking for ACML BLAS: found")
      else()
	message(STATUS "Looking for ACML BLAS: not found")
      endif()
Luker's avatar
Luker committed
    endif()
Luker's avatar
Luker committed
  endif()
Luker's avatar
Luker committed

Luker's avatar
Luker committed
  if(NOT BLAS_LIBRARIES)
    check_fortran_libraries(
Luker's avatar
Luker committed
      BLAS_LIBRARIES
      BLAS
      sgemm
      ""
Luker's avatar
Luker committed
      "acml_mp;acml_mv"
      ""
Luker's avatar
Luker committed
      )
Luker's avatar
Luker committed
    if(NOT BLAS_FIND_QUIETLY)
      if(BLAS_LIBRARIES)
	message(STATUS "Looking for ACML BLAS: found")
      else()
	message(STATUS "Looking for ACML BLAS: not found")
      endif()
Luker's avatar
Luker committed
    endif()
Luker's avatar
Luker committed
  endif()
Luker's avatar
Luker committed

Luker's avatar
Luker committed
  if(NOT BLAS_LIBRARIES)
    check_fortran_libraries(
Luker's avatar
Luker committed
      BLAS_LIBRARIES
      BLAS
      sgemm
      ""
Luker's avatar
Luker committed
      "acml;acml_mv;CALBLAS"
      ""
Luker's avatar
Luker committed
      )
Luker's avatar
Luker committed
    if(NOT BLAS_FIND_QUIETLY)
      if(BLAS_LIBRARIES)
	message(STATUS "Looking for ACML BLAS: found")
      else()
	message(STATUS "Looking for ACML BLAS: not found")
      endif()
    endif()
  endif()
Luker's avatar
Luker committed

Luker's avatar
Luker committed
  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
      set (BLAS_VENDOR_FOUND "ACML")
  endif()

endif (BLA_VENDOR MATCHES "ACML.*" OR BLA_VENDOR STREQUAL "All") # ACML


# Apple BLAS library?
if (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")

  if(NOT BLAS_LIBRARIES)
    check_fortran_libraries(
Luker's avatar
Luker committed
      BLAS_LIBRARIES
      BLAS
Luker's avatar
Luker committed
      dgemm
      ""
      "Accelerate"
Luker's avatar
Luker committed
      ""
      )
Luker's avatar
Luker committed
    if(NOT BLAS_FIND_QUIETLY)
      if(BLAS_LIBRARIES)
	message(STATUS "Looking for Apple BLAS: found")
      else()
	message(STATUS "Looking for Apple BLAS: not found")
      endif()
Luker's avatar
Luker committed
    endif()
Luker's avatar
Luker committed
  endif()

  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
      set (BLAS_VENDOR_FOUND "Apple Accelerate")
  endif()

endif (BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
Luker's avatar
Luker committed

Luker's avatar
Luker committed

if (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")

  if ( NOT BLAS_LIBRARIES )
    check_fortran_libraries(
      BLAS_LIBRARIES
      BLAS
      dgemm
      ""
      "vecLib"
      ""
      )
    if(NOT BLAS_FIND_QUIETLY)
      if(BLAS_LIBRARIES)
	message(STATUS "Looking for NAS BLAS: found")
      else()
	message(STATUS "Looking for NAS BLAS: not found")
      endif()
    endif()
  endif ()

  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
      set (BLAS_VENDOR_FOUND "NAS")
  endif()

endif (BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")


# Generic BLAS library?
if (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")

  set(BLAS_SEARCH_LIBS "blas;blas_LINUX;blas_MAC;blas_WINDOWS;refblas")
  foreach (SEARCH_LIB ${BLAS_SEARCH_LIBS})
    if (BLAS_LIBRARIES)
    else ()
      check_fortran_libraries(
	BLAS_LIBRARIES
	BLAS
	sgemm
	""
	"${SEARCH_LIB}"
	"${LGFORTRAN}"
	)
      if(NOT BLAS_FIND_QUIETLY)
	if(BLAS_LIBRARIES)
	  message(STATUS "Looking for Generic BLAS: found")
	else()
	  message(STATUS "Looking for Generic BLAS: not found")
	endif()
      endif()
    endif()
  endforeach ()

  if (BLAS_LIBRARIES AND NOT BLAS_VENDOR_FOUND)
      set (BLAS_VENDOR_FOUND "Netlib or other Generic libblas")
  endif()

endif (BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")


if(BLA_F95)

  if(BLAS95_LIBRARIES)
    set(BLAS95_FOUND TRUE)
  else()
    set(BLAS95_FOUND FALSE)
  endif()

  if(NOT BLAS_FIND_QUIETLY)
    if(BLAS95_FOUND)
      message(STATUS "A library with BLAS95 API found.")
      message(STATUS "BLAS_LIBRARIES ${BLAS_LIBRARIES}")
    else(BLAS95_FOUND)
      message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but blas 95 libraries could not be found or check of symbols failed."
	"\nPlease indicate where to find blas libraries. You have three options:\n"
	"- Option 1: Provide the installation directory of BLAS library with cmake option: -DBLAS_DIR=your/path/to/blas\n"
	"- Option 2: Provide the directory where to find BLAS libraries with cmake option: -DBLAS_LIBDIR=your/path/to/blas/libs\n"
	"- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
	"\nTo follow libraries detection more precisely you can activate a verbose mode with -DBLAS_VERBOSE=ON at cmake configure."
	"\nYou could also specify a BLAS vendor to look for by setting -DBLA_VENDOR=blas_vendor_name."
	"\nList of possible BLAS vendor: Goto, ATLAS PhiPACK, CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, Intel10_32 (intel mkl v10 32 bit),"
	"Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model), Intel10_64lp_seq (intel mkl v10 64 bit, sequential code, lp64 model),"
	"Intel( older versions of mkl 32 and 64 bit), ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic")
      if(BLAS_FIND_REQUIRED)
	message(FATAL_ERROR
	  "A required library with BLAS95 API not found. Please specify library location.")
      else()
	message(STATUS
	  "A library with BLAS95 API not found. Please specify library location.")
      endif()
    endif(BLAS95_FOUND)
  endif(NOT BLAS_FIND_QUIETLY)

  set(BLAS_FOUND TRUE)
  set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")

else(BLA_F95)

  if(BLAS_LIBRARIES)
Luker's avatar
Luker committed
    set(BLAS_FOUND TRUE)
  else()
    set(BLAS_FOUND FALSE)
  endif()

  if(NOT BLAS_FIND_QUIETLY)
    if(BLAS_FOUND)
      message(STATUS "A library with BLAS API found.")
Luker's avatar
Luker committed
      message(STATUS "BLAS_LIBRARIES ${BLAS_LIBRARIES}")
Luker's avatar
Luker committed
    else(BLAS_FOUND)
Luker's avatar
Luker committed
      message(WARNING "BLA_VENDOR has been set to ${BLA_VENDOR} but blas libraries could not be found or check of symbols failed."
	"\nPlease indicate where to find blas libraries. You have three options:\n"
	"- Option 1: Provide the installation directory of BLAS library with cmake option: -DBLAS_DIR=your/path/to/blas\n"
	"- Option 2: Provide the directory where to find BLAS libraries with cmake option: -DBLAS_LIBDIR=your/path/to/blas/libs\n"
	"- Option 3: Update your environment variable (Linux: LD_LIBRARY_PATH, Windows: LIB, Mac: DYLD_LIBRARY_PATH)\n"
	"\nTo follow libraries detection more precisely you can activate a verbose mode with -DBLAS_VERBOSE=ON at cmake configure."
	"\nYou could also specify a BLAS vendor to look for by setting -DBLA_VENDOR=blas_vendor_name."
	"\nList of possible BLAS vendor: Goto, ATLAS PhiPACK, CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, Intel10_32 (intel mkl v10 32 bit),"
	"Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model), Intel10_64lp_seq (intel mkl v10 64 bit, sequential code, lp64 model),"
	"Intel( older versions of mkl 32 and 64 bit), ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic")
Luker's avatar
Luker committed
      if(BLAS_FIND_REQUIRED)
Luker's avatar
Luker committed
	message(FATAL_ERROR
	  "A required library with BLAS API not found. Please specify library location.")
Luker's avatar
Luker committed
      else()
Luker's avatar
Luker committed
	message(STATUS
	  "A library with BLAS API not found. Please specify library location.")
Luker's avatar
Luker committed
      endif()
    endif(BLAS_FOUND)
  endif(NOT BLAS_FIND_QUIETLY)

Luker's avatar
Luker committed
endif(BLA_F95)

set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})

if (BLAS_FOUND)
  list(GET BLAS_LIBRARIES 0 first_lib)
  get_filename_component(first_lib_path "${first_lib}" PATH)
  if (${first_lib_path} MATCHES "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)")
    string(REGEX REPLACE "(/lib(32|64)?$)|(/lib/intel64$|/lib/ia32$)" "" not_cached_dir "${first_lib_path}")
    set(BLAS_DIR_FOUND "${not_cached_dir}" CACHE PATH "Installation directory of BLAS library" FORCE)
  else()
    set(BLAS_DIR_FOUND "${first_lib_path}" CACHE PATH "Installation directory of BLAS library" FORCE)
  endif()
endif()
mark_as_advanced(BLAS_DIR)
mark_as_advanced(BLAS_DIR_FOUND)