FindBLAS.cmake 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindBLAS
  5. --------
  6. Find Basic Linear Algebra Subprograms (BLAS) library
  7. This module finds an installed Fortran library that implements the
  8. BLAS linear-algebra interface (see http://www.netlib.org/blas/).
  9. The approach follows that taken for the ``autoconf`` macro file,
  10. ``acx_blas.m4`` (distributed at
  11. http://ac-archive.sourceforge.net/ac-archive/acx_blas.html).
  12. Input Variables
  13. ^^^^^^^^^^^^^^^
  14. The following variables may be set to influence this module's behavior:
  15. ``BLA_STATIC``
  16. if ``ON`` use static linkage
  17. ``BLA_VENDOR``
  18. If set, checks only the specified vendor, if not set checks all the
  19. possibilities. List of vendors valid in this module:
  20. * ``Goto``
  21. * ``OpenBLAS``
  22. * ``FLAME``
  23. * ``ATLAS PhiPACK``
  24. * ``CXML``
  25. * ``DXML``
  26. * ``SunPerf``
  27. * ``SCSL``
  28. * ``SGIMATH``
  29. * ``IBMESSL``
  30. * ``Intel10_32`` (intel mkl v10 32 bit)
  31. * ``Intel10_64lp`` (intel mkl v10+ 64 bit, threaded code, lp64 model)
  32. * ``Intel10_64lp_seq`` (intel mkl v10+ 64 bit, sequential code, lp64 model)
  33. * ``Intel10_64ilp`` (intel mkl v10+ 64 bit, threaded code, ilp64 model)
  34. * ``Intel10_64ilp_seq`` (intel mkl v10+ 64 bit, sequential code, ilp64 model)
  35. * ``Intel10_64_dyn`` (intel mkl v10+ 64 bit, single dynamic library)
  36. * ``Intel`` (obsolete versions of mkl 32 and 64 bit)
  37. * ``ACML``
  38. * ``ACML_MP``
  39. * ``ACML_GPU``
  40. * ``Apple``
  41. * ``NAS``
  42. * ``Generic``
  43. ``BLA_F95``
  44. if ``ON`` tries to find the BLAS95 interfaces
  45. ``BLA_PREFER_PKGCONFIG``
  46. if set ``pkg-config`` will be used to search for a BLAS library first
  47. and if one is found that is preferred
  48. Result Variables
  49. ^^^^^^^^^^^^^^^^
  50. This module defines the following variables:
  51. ``BLAS_FOUND``
  52. library implementing the BLAS interface is found
  53. ``BLAS_LINKER_FLAGS``
  54. uncached list of required linker flags (excluding ``-l`` and ``-L``).
  55. ``BLAS_LIBRARIES``
  56. uncached list of libraries (using full path name) to link against
  57. to use BLAS (may be empty if compiler implicitly links BLAS)
  58. ``BLAS95_LIBRARIES``
  59. uncached list of libraries (using full path name) to link against
  60. to use BLAS95 interface
  61. ``BLAS95_FOUND``
  62. library implementing the BLAS95 interface is found
  63. .. note::
  64. C, CXX or Fortran must be enabled to detect a BLAS library.
  65. C or CXX must be enabled to use Intel Math Kernel Library (MKL).
  66. For example, to use Intel MKL libraries and/or Intel compiler:
  67. .. code-block:: cmake
  68. set(BLA_VENDOR Intel10_64lp)
  69. find_package(BLAS)
  70. Hints
  71. ^^^^^
  72. Set the ``MKLROOT`` environment variable to a directory that contains an MKL
  73. installation, or add the directory to the dynamic library loader environment
  74. variable for your platform (``LIB``, ``DYLD_LIBRARY_PATH`` or
  75. ``LD_LIBRARY_PATH``).
  76. #]=======================================================================]
  77. # Check the language being used
  78. if(NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED OR CMAKE_Fortran_COMPILER_LOADED))
  79. if(BLAS_FIND_REQUIRED)
  80. message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.")
  81. else()
  82. message(STATUS "Looking for BLAS... - NOT found (Unsupported languages)")
  83. return()
  84. endif()
  85. endif()
  86. if(CMAKE_Fortran_COMPILER_LOADED)
  87. include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranFunctionExists.cmake)
  88. else()
  89. include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
  90. endif()
  91. include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
  92. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  93. cmake_push_check_state()
  94. set(CMAKE_REQUIRED_QUIET ${BLAS_FIND_QUIETLY})
  95. if(BLA_PREFER_PKGCONFIG)
  96. find_package(PkgConfig)
  97. pkg_check_modules(PKGC_BLAS blas)
  98. if(PKGC_BLAS_FOUND)
  99. set(BLAS_FOUND ${PKGC_BLAS_FOUND})
  100. set(BLAS_LIBRARIES "${PKGC_BLAS_LINK_LIBRARIES}")
  101. return()
  102. endif()
  103. endif()
  104. set(_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  105. if(BLA_STATIC)
  106. if(WIN32)
  107. set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
  108. else()
  109. set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
  110. endif()
  111. else()
  112. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  113. # for ubuntu's libblas3gf and liblapack3gf packages
  114. set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
  115. endif()
  116. endif()
  117. # TODO: move this stuff to a separate module
  118. macro(CHECK_BLAS_LIBRARIES LIBRARIES _prefix _name _flags _list _threadlibs _addlibdir _subdirs)
  119. # This macro checks for the existence of the combination of fortran libraries
  120. # given by _list. If the combination is found, this macro checks (using the
  121. # Check_Fortran_Function_Exists macro) whether can link against that library
  122. # combination using the name of a routine given by _name using the linker
  123. # flags given by _flags. If the combination of libraries is found and passes
  124. # the link test, LIBRARIES is set to the list of complete library paths that
  125. # have been found. Otherwise, LIBRARIES is set to FALSE.
  126. # N.B. _prefix is the prefix applied to the names of all cached variables that
  127. # are generated internally and marked advanced by this macro.
  128. # _addlibdir is a list of additional search paths. _subdirs is a list of path
  129. # suffixes to be used by find_library().
  130. set(_libraries_work TRUE)
  131. set(${LIBRARIES})
  132. set(_combined_name)
  133. if(NOT _addlibdir)
  134. if(WIN32)
  135. set(_addlibdir ENV LIB)
  136. elseif(APPLE)
  137. set(_addlibdir ENV DYLD_LIBRARY_PATH)
  138. else()
  139. set(_addlibdir ENV LD_LIBRARY_PATH)
  140. endif()
  141. endif()
  142. list(APPEND _addlibdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
  143. foreach(_library ${_list})
  144. if(_library MATCHES "^-Wl,--(start|end)-group$")
  145. # Respect linker flags like --start/end-group (required by MKL)
  146. set(${LIBRARIES} ${${LIBRARIES}} "${_library}")
  147. else()
  148. set(_combined_name ${_combined_name}_${_library})
  149. if(NOT "${_threadlibs}" STREQUAL "")
  150. set(_combined_name ${_combined_name}_threadlibs)
  151. endif()
  152. if(_libraries_work)
  153. find_library(${_prefix}_${_library}_LIBRARY
  154. NAMES ${_library}
  155. PATHS ${_addlibdir}
  156. PATH_SUFFIXES ${_subdirs}
  157. )
  158. #message("DEBUG: find_library(${_library}) got ${${_prefix}_${_library}_LIBRARY}")
  159. mark_as_advanced(${_prefix}_${_library}_LIBRARY)
  160. set(${LIBRARIES} ${${LIBRARIES}} ${${_prefix}_${_library}_LIBRARY})
  161. set(_libraries_work ${${_prefix}_${_library}_LIBRARY})
  162. endif()
  163. endif()
  164. endforeach()
  165. if(_libraries_work)
  166. # Test this combination of libraries.
  167. set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${${LIBRARIES}} ${_threadlibs})
  168. #message("DEBUG: CMAKE_REQUIRED_LIBRARIES = ${CMAKE_REQUIRED_LIBRARIES}")
  169. if(CMAKE_Fortran_COMPILER_LOADED)
  170. check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
  171. else()
  172. check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
  173. endif()
  174. set(CMAKE_REQUIRED_LIBRARIES)
  175. set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
  176. endif()
  177. if(_libraries_work)
  178. if("${_list}" STREQUAL "")
  179. set(${LIBRARIES} "${LIBRARIES}-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
  180. else()
  181. set(${LIBRARIES} ${${LIBRARIES}} ${_threadlibs})
  182. endif()
  183. else()
  184. set(${LIBRARIES} FALSE)
  185. endif()
  186. #message("DEBUG: ${LIBRARIES} = ${${LIBRARIES}}")
  187. endmacro()
  188. set(BLAS_LINKER_FLAGS)
  189. set(BLAS_LIBRARIES)
  190. set(BLAS95_LIBRARIES)
  191. if(NOT $ENV{BLA_VENDOR} STREQUAL "")
  192. set(BLA_VENDOR $ENV{BLA_VENDOR})
  193. else()
  194. if(NOT BLA_VENDOR)
  195. set(BLA_VENDOR "All")
  196. endif()
  197. endif()
  198. # Implicitly linked BLAS libraries?
  199. if(BLA_VENDOR STREQUAL "All")
  200. if(NOT BLAS_LIBRARIES)
  201. check_blas_libraries(
  202. BLAS_LIBRARIES
  203. BLAS
  204. sgemm
  205. ""
  206. ""
  207. ""
  208. ""
  209. ""
  210. )
  211. endif()
  212. endif()
  213. # BLAS in the Intel MKL 10+ library?
  214. if(BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
  215. if(NOT BLAS_LIBRARIES)
  216. if(CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED)
  217. # System-specific settings
  218. if(WIN32)
  219. if(BLA_STATIC)
  220. set(BLAS_mkl_DLL_SUFFIX "")
  221. else()
  222. set(BLAS_mkl_DLL_SUFFIX "_dll")
  223. endif()
  224. else()
  225. if(BLA_STATIC)
  226. set(BLAS_mkl_START_GROUP "-Wl,--start-group")
  227. set(BLAS_mkl_END_GROUP "-Wl,--end-group")
  228. else()
  229. set(BLAS_mkl_START_GROUP "")
  230. set(BLAS_mkl_END_GROUP "")
  231. endif()
  232. # Switch to GNU Fortran support layer if needed (but not on Apple, where MKL does not provide it)
  233. if(CMAKE_Fortran_COMPILER_LOADED AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND NOT APPLE)
  234. set(BLAS_mkl_INTFACE "gf")
  235. set(BLAS_mkl_THREADING "gnu")
  236. set(BLAS_mkl_OMP "gomp")
  237. else()
  238. set(BLAS_mkl_INTFACE "intel")
  239. set(BLAS_mkl_THREADING "intel")
  240. set(BLAS_mkl_OMP "iomp5")
  241. endif()
  242. set(BLAS_mkl_LM "-lm")
  243. set(BLAS_mkl_LDL "-ldl")
  244. endif()
  245. if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  246. find_package(Threads)
  247. else()
  248. find_package(Threads REQUIRED)
  249. endif()
  250. if(BLA_VENDOR MATCHES "_64ilp")
  251. set(BLAS_mkl_ILP_MODE "ilp64")
  252. else()
  253. set(BLAS_mkl_ILP_MODE "lp64")
  254. endif()
  255. set(BLAS_SEARCH_LIBS "")
  256. if(BLA_F95)
  257. set(BLAS_mkl_SEARCH_SYMBOL "sgemm_f95")
  258. set(_LIBRARIES BLAS95_LIBRARIES)
  259. if(WIN32)
  260. # Find the main file (32-bit or 64-bit)
  261. set(BLAS_SEARCH_LIBS_WIN_MAIN "")
  262. if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  263. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  264. "mkl_blas95${BLAS_mkl_DLL_SUFFIX} mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
  265. endif()
  266. if(BLA_VENDOR MATCHES "^Intel10_64i?lp" OR BLA_VENDOR STREQUAL "All")
  267. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  268. "mkl_blas95_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX} mkl_intel_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX}")
  269. endif()
  270. # Add threading/sequential libs
  271. set(BLAS_SEARCH_LIBS_WIN_THREAD "")
  272. if(BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
  273. # old version
  274. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  275. "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  276. # mkl >= 10.3
  277. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  278. "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  279. endif()
  280. if(BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
  281. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  282. "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
  283. endif()
  284. # Cartesian product of the above
  285. foreach(MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
  286. foreach(THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
  287. list(APPEND BLAS_SEARCH_LIBS
  288. "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
  289. endforeach()
  290. endforeach()
  291. else()
  292. if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  293. # old version
  294. list(APPEND BLAS_SEARCH_LIBS
  295. "mkl_blas95 mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
  296. # mkl >= 10.3
  297. list(APPEND BLAS_SEARCH_LIBS
  298. "${BLAS_mkl_START_GROUP} mkl_blas95 mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_END_GROUP} ${BLAS_mkl_OMP}")
  299. endif()
  300. if(BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
  301. # old version
  302. list(APPEND BLAS_SEARCH_LIBS
  303. "mkl_blas95 mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
  304. # mkl >= 10.3
  305. list(APPEND BLAS_SEARCH_LIBS
  306. "${BLAS_mkl_START_GROUP} mkl_blas95_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_END_GROUP} ${BLAS_mkl_OMP}")
  307. endif()
  308. if(BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
  309. list(APPEND BLAS_SEARCH_LIBS
  310. "${BLAS_mkl_START_GROUP} mkl_blas95_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_sequential mkl_core ${BLAS_mkl_END_GROUP}")
  311. endif()
  312. endif()
  313. else()
  314. set(BLAS_mkl_SEARCH_SYMBOL sgemm)
  315. set(_LIBRARIES BLAS_LIBRARIES)
  316. if(WIN32)
  317. # Find the main file (32-bit or 64-bit)
  318. set(BLAS_SEARCH_LIBS_WIN_MAIN "")
  319. if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  320. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  321. "mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
  322. endif()
  323. if(BLA_VENDOR MATCHES "^Intel10_64i?lp" OR BLA_VENDOR STREQUAL "All")
  324. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  325. "mkl_intel_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX}")
  326. endif()
  327. # Add threading/sequential libs
  328. set(BLAS_SEARCH_LIBS_WIN_THREAD "")
  329. if(BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
  330. # old version
  331. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  332. "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  333. # mkl >= 10.3
  334. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  335. "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  336. endif()
  337. if(BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
  338. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  339. "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
  340. endif()
  341. # Cartesian product of the above
  342. foreach(MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
  343. foreach(THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
  344. list(APPEND BLAS_SEARCH_LIBS
  345. "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
  346. endforeach()
  347. endforeach()
  348. else()
  349. if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  350. # old version
  351. list(APPEND BLAS_SEARCH_LIBS
  352. "mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
  353. # mkl >= 10.3
  354. list(APPEND BLAS_SEARCH_LIBS
  355. "${BLAS_mkl_START_GROUP} mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_END_GROUP} ${BLAS_mkl_OMP}")
  356. endif()
  357. if(BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
  358. # old version
  359. list(APPEND BLAS_SEARCH_LIBS
  360. "mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
  361. # mkl >= 10.3
  362. list(APPEND BLAS_SEARCH_LIBS
  363. "${BLAS_mkl_START_GROUP} mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_END_GROUP} ${BLAS_mkl_OMP}")
  364. endif()
  365. if(BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
  366. list(APPEND BLAS_SEARCH_LIBS
  367. "${BLAS_mkl_START_GROUP} mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_sequential mkl_core ${BLAS_mkl_END_GROUP}")
  368. endif()
  369. #older vesions of intel mkl libs
  370. if(BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All")
  371. list(APPEND BLAS_SEARCH_LIBS
  372. "mkl")
  373. list(APPEND BLAS_SEARCH_LIBS
  374. "mkl_ia32")
  375. list(APPEND BLAS_SEARCH_LIBS
  376. "mkl_em64t")
  377. endif()
  378. endif()
  379. endif()
  380. if(BLA_VENDOR MATCHES "^Intel10_64_dyn$" OR BLA_VENDOR STREQUAL "All")
  381. # mkl >= 10.3 with single dynamic library
  382. list(APPEND BLAS_SEARCH_LIBS
  383. "mkl_rt")
  384. endif()
  385. # MKL uses a multitude of partially platform-specific subdirectories:
  386. if(BLA_VENDOR STREQUAL "Intel10_32")
  387. set(BLAS_mkl_ARCH_NAME "ia32")
  388. else()
  389. set(BLAS_mkl_ARCH_NAME "intel64")
  390. endif()
  391. if(WIN32)
  392. set(BLAS_mkl_OS_NAME "win")
  393. elseif(APPLE)
  394. set(BLAS_mkl_OS_NAME "mac")
  395. else()
  396. set(BLAS_mkl_OS_NAME "lin")
  397. endif()
  398. if(DEFINED ENV{MKLROOT})
  399. set(BLAS_mkl_MKLROOT "$ENV{MKLROOT}")
  400. endif()
  401. set(BLAS_mkl_LIB_PATH_SUFFIXES
  402. "compiler/lib" "compiler/lib/${BLAS_mkl_ARCH_NAME}_${BLAS_mkl_OS_NAME}"
  403. "mkl/lib" "mkl/lib/${BLAS_mkl_ARCH_NAME}_${BLAS_mkl_OS_NAME}"
  404. "lib/${BLAS_mkl_ARCH_NAME}_${BLAS_mkl_OS_NAME}")
  405. foreach(IT ${BLAS_SEARCH_LIBS})
  406. string(REPLACE " " ";" SEARCH_LIBS ${IT})
  407. if(NOT ${_LIBRARIES})
  408. check_blas_libraries(
  409. ${_LIBRARIES}
  410. BLAS
  411. ${BLAS_mkl_SEARCH_SYMBOL}
  412. ""
  413. "${SEARCH_LIBS}"
  414. "${CMAKE_THREAD_LIBS_INIT};${BLAS_mkl_LM};${BLAS_mkl_LDL}"
  415. "${BLAS_mkl_MKLROOT}"
  416. "${BLAS_mkl_LIB_PATH_SUFFIXES}"
  417. )
  418. endif()
  419. endforeach()
  420. unset(BLAS_mkl_ILP_MODE)
  421. unset(BLAS_mkl_INTFACE)
  422. unset(BLAS_mkl_THREADING)
  423. unset(BLAS_mkl_OMP)
  424. unset(BLAS_mkl_DLL_SUFFIX)
  425. unset(BLAS_mkl_LM)
  426. unset(BLAS_mkl_LDL)
  427. unset(BLAS_mkl_MKLROOT)
  428. unset(BLAS_mkl_ARCH_NAME)
  429. unset(BLAS_mkl_OS_NAME)
  430. unset(BLAS_mkl_LIB_PATH_SUFFIXES)
  431. endif()
  432. endif()
  433. endif()
  434. if(BLA_F95)
  435. find_package_handle_standard_args(BLAS REQUIRED_VARS BLAS95_LIBRARIES)
  436. set(BLAS95_FOUND ${BLAS_FOUND})
  437. if(BLAS_FOUND)
  438. set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
  439. endif()
  440. endif()
  441. # gotoblas? (http://www.tacc.utexas.edu/tacc-projects/gotoblas2)
  442. if(BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
  443. if(NOT BLAS_LIBRARIES)
  444. check_blas_libraries(
  445. BLAS_LIBRARIES
  446. BLAS
  447. sgemm
  448. ""
  449. "goto2"
  450. ""
  451. ""
  452. ""
  453. )
  454. endif()
  455. endif()
  456. # OpenBLAS? (http://www.openblas.net)
  457. if(BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All")
  458. if(NOT BLAS_LIBRARIES)
  459. check_blas_libraries(
  460. BLAS_LIBRARIES
  461. BLAS
  462. sgemm
  463. ""
  464. "openblas"
  465. ""
  466. ""
  467. ""
  468. )
  469. endif()
  470. if(NOT BLAS_LIBRARIES AND (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED))
  471. if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  472. find_package(Threads)
  473. else()
  474. find_package(Threads REQUIRED)
  475. endif()
  476. check_blas_libraries(
  477. BLAS_LIBRARIES
  478. BLAS
  479. sgemm
  480. ""
  481. "openblas"
  482. "${CMAKE_THREAD_LIBS_INIT}"
  483. ""
  484. ""
  485. )
  486. endif()
  487. endif()
  488. # FLAME's blis library? (https://github.com/flame/blis)
  489. if(BLA_VENDOR STREQUAL "FLAME" OR BLA_VENDOR STREQUAL "All")
  490. if(NOT BLAS_LIBRARIES)
  491. check_blas_libraries(
  492. BLAS_LIBRARIES
  493. BLAS
  494. sgemm
  495. ""
  496. "blis"
  497. ""
  498. ""
  499. ""
  500. )
  501. endif()
  502. endif()
  503. # BLAS in the ATLAS library? (http://math-atlas.sourceforge.net/)
  504. if(BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
  505. if(NOT BLAS_LIBRARIES)
  506. check_blas_libraries(
  507. BLAS_LIBRARIES
  508. BLAS
  509. dgemm
  510. ""
  511. "blas;f77blas;atlas"
  512. ""
  513. ""
  514. ""
  515. )
  516. endif()
  517. endif()
  518. # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
  519. if(BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
  520. if(NOT BLAS_LIBRARIES)
  521. check_blas_libraries(
  522. BLAS_LIBRARIES
  523. BLAS
  524. sgemm
  525. ""
  526. "sgemm;dgemm;blas"
  527. ""
  528. ""
  529. ""
  530. )
  531. endif()
  532. endif()
  533. # BLAS in Alpha CXML library?
  534. if(BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
  535. if(NOT BLAS_LIBRARIES)
  536. check_blas_libraries(
  537. BLAS_LIBRARIES
  538. BLAS
  539. sgemm
  540. ""
  541. "cxml"
  542. ""
  543. ""
  544. ""
  545. )
  546. endif()
  547. endif()
  548. # BLAS in Alpha DXML library? (now called CXML, see above)
  549. if(BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
  550. if(NOT BLAS_LIBRARIES)
  551. check_blas_libraries(
  552. BLAS_LIBRARIES
  553. BLAS
  554. sgemm
  555. ""
  556. "dxml"
  557. ""
  558. ""
  559. ""
  560. )
  561. endif()
  562. endif()
  563. # BLAS in Sun Performance library?
  564. if(BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
  565. if(NOT BLAS_LIBRARIES)
  566. check_blas_libraries(
  567. BLAS_LIBRARIES
  568. BLAS
  569. sgemm
  570. "-xlic_lib=sunperf"
  571. "sunperf;sunmath"
  572. ""
  573. ""
  574. ""
  575. )
  576. if(BLAS_LIBRARIES)
  577. set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
  578. endif()
  579. endif()
  580. endif()
  581. # BLAS in SCSL library? (SGI/Cray Scientific Library)
  582. if(BLA_VENDOR STREQUAL "SCSL" OR BLA_VENDOR STREQUAL "All")
  583. if(NOT BLAS_LIBRARIES)
  584. check_blas_libraries(
  585. BLAS_LIBRARIES
  586. BLAS
  587. sgemm
  588. ""
  589. "scsl"
  590. ""
  591. ""
  592. ""
  593. )
  594. endif()
  595. endif()
  596. # BLAS in SGIMATH library?
  597. if(BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
  598. if(NOT BLAS_LIBRARIES)
  599. check_blas_libraries(
  600. BLAS_LIBRARIES
  601. BLAS
  602. sgemm
  603. ""
  604. "complib.sgimath"
  605. ""
  606. ""
  607. ""
  608. )
  609. endif()
  610. endif()
  611. # BLAS in IBM ESSL library? (requires generic BLAS lib, too)
  612. if(BLA_VENDOR STREQUAL "IBMESSL" OR BLA_VENDOR STREQUAL "All")
  613. if(NOT BLAS_LIBRARIES)
  614. check_blas_libraries(
  615. BLAS_LIBRARIES
  616. BLAS
  617. sgemm
  618. ""
  619. "essl;blas"
  620. ""
  621. ""
  622. ""
  623. )
  624. endif()
  625. endif()
  626. # BLAS in acml library?
  627. if(BLA_VENDOR MATCHES "ACML" OR BLA_VENDOR STREQUAL "All")
  628. if(((BLA_VENDOR STREQUAL "ACML") AND (NOT BLAS_ACML_LIB_DIRS)) OR
  629. ((BLA_VENDOR STREQUAL "ACML_MP") AND (NOT BLAS_ACML_MP_LIB_DIRS)) OR
  630. ((BLA_VENDOR STREQUAL "ACML_GPU") AND (NOT BLAS_ACML_GPU_LIB_DIRS))
  631. )
  632. # try to find acml in "standard" paths
  633. if(WIN32)
  634. file(GLOB _ACML_ROOT "C:/AMD/acml*/ACML-EULA.txt")
  635. else()
  636. file(GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt")
  637. endif()
  638. if(WIN32)
  639. file(GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples")
  640. else()
  641. file(GLOB _ACML_GPU_ROOT "/opt/acml*/GPGPUexamples")
  642. endif()
  643. list(GET _ACML_ROOT 0 _ACML_ROOT)
  644. list(GET _ACML_GPU_ROOT 0 _ACML_GPU_ROOT)
  645. if(_ACML_ROOT)
  646. get_filename_component(_ACML_ROOT ${_ACML_ROOT} PATH)
  647. if(SIZEOF_INTEGER EQUAL 8)
  648. set(_ACML_PATH_SUFFIX "_int64")
  649. else()
  650. set(_ACML_PATH_SUFFIX "")
  651. endif()
  652. if(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
  653. set(_ACML_COMPILER32 "ifort32")
  654. set(_ACML_COMPILER64 "ifort64")
  655. elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro")
  656. set(_ACML_COMPILER32 "sun32")
  657. set(_ACML_COMPILER64 "sun64")
  658. elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "PGI")
  659. set(_ACML_COMPILER32 "pgi32")
  660. if(WIN32)
  661. set(_ACML_COMPILER64 "win64")
  662. else()
  663. set(_ACML_COMPILER64 "pgi64")
  664. endif()
  665. elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Open64")
  666. # 32 bit builds not supported on Open64 but for code simplicity
  667. # We'll just use the same directory twice
  668. set(_ACML_COMPILER32 "open64_64")
  669. set(_ACML_COMPILER64 "open64_64")
  670. elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "NAG")
  671. set(_ACML_COMPILER32 "nag32")
  672. set(_ACML_COMPILER64 "nag64")
  673. else()
  674. set(_ACML_COMPILER32 "gfortran32")
  675. set(_ACML_COMPILER64 "gfortran64")
  676. endif()
  677. if(BLA_VENDOR STREQUAL "ACML_MP")
  678. set(_ACML_MP_LIB_DIRS
  679. "${_ACML_ROOT}/${_ACML_COMPILER32}_mp${_ACML_PATH_SUFFIX}/lib"
  680. "${_ACML_ROOT}/${_ACML_COMPILER64}_mp${_ACML_PATH_SUFFIX}/lib")
  681. else()
  682. set(_ACML_LIB_DIRS
  683. "${_ACML_ROOT}/${_ACML_COMPILER32}${_ACML_PATH_SUFFIX}/lib"
  684. "${_ACML_ROOT}/${_ACML_COMPILER64}${_ACML_PATH_SUFFIX}/lib")
  685. endif()
  686. endif()
  687. elseif(BLAS_${BLA_VENDOR}_LIB_DIRS)
  688. set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS})
  689. endif()
  690. if(BLA_VENDOR STREQUAL "ACML_MP")
  691. foreach(BLAS_ACML_MP_LIB_DIRS ${_ACML_MP_LIB_DIRS})
  692. check_blas_libraries(
  693. BLAS_LIBRARIES
  694. BLAS
  695. sgemm
  696. "" "acml_mp;acml_mv" "" ${BLAS_ACML_MP_LIB_DIRS} ""
  697. )
  698. if(BLAS_LIBRARIES)
  699. break()
  700. endif()
  701. endforeach()
  702. elseif(BLA_VENDOR STREQUAL "ACML_GPU")
  703. foreach(BLAS_ACML_GPU_LIB_DIRS ${_ACML_GPU_LIB_DIRS})
  704. check_blas_libraries(
  705. BLAS_LIBRARIES
  706. BLAS
  707. sgemm
  708. "" "acml;acml_mv;CALBLAS" "" ${BLAS_ACML_GPU_LIB_DIRS} ""
  709. )
  710. if(BLAS_LIBRARIES)
  711. break()
  712. endif()
  713. endforeach()
  714. else()
  715. foreach(BLAS_ACML_LIB_DIRS ${_ACML_LIB_DIRS})
  716. check_blas_libraries(
  717. BLAS_LIBRARIES
  718. BLAS
  719. sgemm
  720. "" "acml;acml_mv" "" ${BLAS_ACML_LIB_DIRS} ""
  721. )
  722. if(BLAS_LIBRARIES)
  723. break()
  724. endif()
  725. endforeach()
  726. endif()
  727. # Either acml or acml_mp should be in LD_LIBRARY_PATH but not both
  728. if(NOT BLAS_LIBRARIES)
  729. check_blas_libraries(
  730. BLAS_LIBRARIES
  731. BLAS
  732. sgemm
  733. ""
  734. "acml;acml_mv"
  735. ""
  736. ""
  737. ""
  738. )
  739. endif()
  740. if(NOT BLAS_LIBRARIES)
  741. check_blas_libraries(
  742. BLAS_LIBRARIES
  743. BLAS
  744. sgemm
  745. ""
  746. "acml_mp;acml_mv"
  747. ""
  748. ""
  749. ""
  750. )
  751. endif()
  752. if(NOT BLAS_LIBRARIES)
  753. check_blas_libraries(
  754. BLAS_LIBRARIES
  755. BLAS
  756. sgemm
  757. ""
  758. "acml;acml_mv;CALBLAS"
  759. ""
  760. ""
  761. ""
  762. )
  763. endif()
  764. endif() # ACML
  765. # Apple BLAS library?
  766. if(BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  767. if(NOT BLAS_LIBRARIES)
  768. check_blas_libraries(
  769. BLAS_LIBRARIES
  770. BLAS
  771. dgemm
  772. ""
  773. "Accelerate"
  774. ""
  775. ""
  776. ""
  777. )
  778. endif()
  779. endif()
  780. # Apple NAS (vecLib) library?
  781. if(BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  782. if(NOT BLAS_LIBRARIES)
  783. check_blas_libraries(
  784. BLAS_LIBRARIES
  785. BLAS
  786. dgemm
  787. ""
  788. "vecLib"
  789. ""
  790. ""
  791. ""
  792. )
  793. endif()
  794. endif()
  795. # Generic BLAS library?
  796. if(BLA_VENDOR STREQUAL "Generic" OR BLA_VENDOR STREQUAL "All")
  797. if(NOT BLAS_LIBRARIES)
  798. check_blas_libraries(
  799. BLAS_LIBRARIES
  800. BLAS
  801. sgemm
  802. ""
  803. "blas"
  804. ""
  805. ""
  806. ""
  807. )
  808. endif()
  809. endif()
  810. if(NOT BLA_F95)
  811. find_package_handle_standard_args(BLAS REQUIRED_VARS BLAS_LIBRARIES)
  812. endif()
  813. # On compilers that implicitly link BLAS (such as ftn, cc, and CC on Cray HPC machines)
  814. # we used a placeholder for empty BLAS_LIBRARIES to get through our logic above.
  815. if(BLAS_LIBRARIES STREQUAL "BLAS_LIBRARIES-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
  816. set(BLAS_LIBRARIES "")
  817. endif()
  818. cmake_pop_check_state()
  819. set(CMAKE_FIND_LIBRARY_SUFFIXES ${_blas_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})