FindBLAS.cmake 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  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`_.
  9. At least one of the ``C``, ``CXX``, or ``Fortran`` languages must be enabled.
  10. .. _`BLAS linear-algebra interface`: https://netlib.org/blas/
  11. Input Variables
  12. ^^^^^^^^^^^^^^^
  13. The following variables may be set to influence this module's behavior:
  14. ``BLA_STATIC``
  15. if ``ON`` use static linkage
  16. ``BLA_VENDOR``
  17. Set to one of the :ref:`BLAS/LAPACK Vendors` to search for BLAS only
  18. from the specified vendor. If not set, all vendors are considered.
  19. ``BLA_F95``
  20. if ``ON`` tries to find the BLAS95 interfaces
  21. ``BLA_PREFER_PKGCONFIG``
  22. .. versionadded:: 3.11
  23. if set ``pkg-config`` will be used to search for a BLAS library first
  24. and if one is found that is preferred
  25. ``BLA_PKGCONFIG_BLAS``
  26. .. versionadded:: 3.25
  27. If set, the ``pkg-config`` method will look for this module name instead of
  28. just ``blas``.
  29. ``BLA_SIZEOF_INTEGER``
  30. .. versionadded:: 3.22
  31. Specify the BLAS/LAPACK library integer size:
  32. ``4``
  33. Search for a BLAS/LAPACK with 32-bit integer interfaces.
  34. ``8``
  35. Search for a BLAS/LAPACK with 64-bit integer interfaces.
  36. ``ANY``
  37. Search for any BLAS/LAPACK.
  38. Most likely, a BLAS/LAPACK with 32-bit integer interfaces will be found.
  39. Imported targets
  40. ^^^^^^^^^^^^^^^^
  41. This module defines the following :prop_tgt:`IMPORTED` targets:
  42. ``BLAS::BLAS``
  43. .. versionadded:: 3.18
  44. The libraries to use for BLAS, if found.
  45. Result Variables
  46. ^^^^^^^^^^^^^^^^
  47. This module defines the following variables:
  48. ``BLAS_FOUND``
  49. library implementing the BLAS interface is found
  50. ``BLAS_LINKER_FLAGS``
  51. uncached list of required linker flags (excluding ``-l`` and ``-L``).
  52. ``BLAS_LIBRARIES``
  53. uncached list of libraries (using full path name) to link against
  54. to use BLAS (may be empty if compiler implicitly links BLAS)
  55. ``BLAS95_LIBRARIES``
  56. uncached list of libraries (using full path name) to link against
  57. to use BLAS95 interface
  58. ``BLAS95_FOUND``
  59. library implementing the BLAS95 interface is found
  60. .. _`BLAS/LAPACK Vendors`:
  61. BLAS/LAPACK Vendors
  62. ^^^^^^^^^^^^^^^^^^^
  63. ``Generic``
  64. Generic reference implementation
  65. ``ACML``, ``ACML_MP``, ``ACML_GPU``
  66. AMD Core Math Library
  67. ``AOCL``, ``AOCL_mt``
  68. .. versionadded:: 3.27
  69. AMD Optimizing CPU Libraries
  70. ``Apple``, ``NAS``
  71. Apple BLAS (Accelerate), and Apple NAS (vecLib)
  72. ``Arm``, ``Arm_mp``, ``Arm_ilp64``, ``Arm_ilp64_mp``
  73. .. versionadded:: 3.18
  74. Arm Performance Libraries
  75. ``ATLAS``
  76. Automatically Tuned Linear Algebra Software
  77. ``CXML``, ``DXML``
  78. Compaq/Digital Extended Math Library
  79. ``EML``, ``EML_mt``
  80. .. versionadded:: 3.20
  81. Elbrus Math Library
  82. ``FLAME``
  83. .. versionadded:: 3.11
  84. BLIS Framework
  85. ``FlexiBLAS``
  86. .. versionadded:: 3.19
  87. ``Fujitsu_SSL2``, ``Fujitsu_SSL2BLAMP``, ``Fujitsu_SSL2SVE``, ``Fujitsu_SSL2BLAMPSVE``
  88. .. versionadded:: 3.20
  89. Fujitsu SSL2 serial and parallel blas/lapack with SVE instructions
  90. ``Goto``
  91. GotoBLAS
  92. ``IBMESSL``, ``IBMESSL_SMP``
  93. IBM Engineering and Scientific Subroutine Library
  94. ``Intel``
  95. Intel MKL 32 bit and 64 bit obsolete versions
  96. ``Intel10_32``
  97. Intel MKL v10 32 bit, threaded code
  98. ``Intel10_64lp``
  99. Intel MKL v10+ 64 bit, threaded code, lp64 model
  100. ``Intel10_64lp_seq``
  101. Intel MKL v10+ 64 bit, sequential code, lp64 model
  102. ``Intel10_64ilp``
  103. .. versionadded:: 3.13
  104. Intel MKL v10+ 64 bit, threaded code, ilp64 model
  105. ``Intel10_64ilp_seq``
  106. .. versionadded:: 3.13
  107. Intel MKL v10+ 64 bit, sequential code, ilp64 model
  108. ``Intel10_64_dyn``
  109. .. versionadded:: 3.17
  110. Intel MKL v10+ 64 bit, single dynamic library
  111. ``NVHPC``
  112. .. versionadded:: 3.21
  113. NVIDIA HPC SDK
  114. ``OpenBLAS``
  115. .. versionadded:: 3.6
  116. ``PhiPACK``
  117. Portable High Performance ANSI C (PHiPAC)
  118. ``SCSL``, ``SCSL_mp``
  119. Scientific Computing Software Library
  120. ``SGIMATH``
  121. SGI Scientific Mathematical Library
  122. ``SunPerf``
  123. Sun Performance Library
  124. .. _`Intel MKL`:
  125. Intel MKL
  126. ^^^^^^^^^
  127. To use the Intel MKL implementation of BLAS, a project must enable at least
  128. one of the ``C`` or ``CXX`` languages. Set ``BLA_VENDOR`` to an Intel MKL
  129. variant either on the command-line as ``-DBLA_VENDOR=Intel10_64lp`` or in
  130. project code:
  131. .. code-block:: cmake
  132. set(BLA_VENDOR Intel10_64lp)
  133. find_package(BLAS)
  134. In order to build a project using Intel MKL, and end user must first
  135. establish an Intel MKL environment:
  136. Intel oneAPI
  137. Source the full Intel environment script:
  138. .. code-block:: shell
  139. . /opt/intel/oneapi/setvars.sh
  140. Or, source the MKL component environment script:
  141. .. code-block:: shell
  142. . /opt/intel/oneapi/mkl/latest/env/vars.sh
  143. Intel Classic
  144. Source the full Intel environment script:
  145. .. code-block:: shell
  146. . /opt/intel/bin/compilervars.sh intel64
  147. Or, source the MKL component environment script:
  148. .. code-block:: shell
  149. . /opt/intel/mkl/bin/mklvars.sh intel64
  150. The above environment scripts set the ``MKLROOT`` environment variable
  151. to the top of the MKL installation. They also add the location of the
  152. runtime libraries to the dynamic library loader environment variable for
  153. your platform (e.g. ``LD_LIBRARY_PATH``). This is necessary for programs
  154. linked against MKL to run.
  155. .. note::
  156. As of Intel oneAPI 2021.2, loading only the MKL component does not
  157. make all of its dependencies available. In particular, the ``iomp5``
  158. library must be available separately, or provided by also loading
  159. the compiler component environment:
  160. .. code-block:: shell
  161. . /opt/intel/oneapi/compiler/latest/env/vars.sh
  162. #]=======================================================================]
  163. # The approach follows that of the ``autoconf`` macro file, ``acx_blas.m4``
  164. # (distributed at http://ac-archive.sourceforge.net/ac-archive/acx_blas.html).
  165. # Check the language being used
  166. if(NOT (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED OR CMAKE_Fortran_COMPILER_LOADED))
  167. if(BLAS_FIND_REQUIRED)
  168. message(FATAL_ERROR "FindBLAS requires Fortran, C, or C++ to be enabled.")
  169. else()
  170. message(STATUS "Looking for BLAS... - NOT found (Unsupported languages)")
  171. return()
  172. endif()
  173. endif()
  174. function(_add_blas_target)
  175. if(BLAS_FOUND AND NOT TARGET BLAS::BLAS)
  176. add_library(BLAS::BLAS INTERFACE IMPORTED)
  177. if(BLAS_LIBRARIES)
  178. set_target_properties(BLAS::BLAS PROPERTIES
  179. INTERFACE_LINK_LIBRARIES "${BLAS_LIBRARIES}"
  180. )
  181. endif()
  182. if(BLAS_LINKER_FLAGS)
  183. set_target_properties(BLAS::BLAS PROPERTIES
  184. INTERFACE_LINK_OPTIONS "${BLAS_LINKER_FLAGS}"
  185. )
  186. endif()
  187. endif()
  188. endfunction()
  189. if(CMAKE_Fortran_COMPILER_LOADED)
  190. include(${CMAKE_CURRENT_LIST_DIR}/CheckFortranFunctionExists.cmake)
  191. else()
  192. include(${CMAKE_CURRENT_LIST_DIR}/CheckFunctionExists.cmake)
  193. endif()
  194. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  195. if(BLA_PREFER_PKGCONFIG)
  196. if(NOT BLA_PKGCONFIG_BLAS)
  197. set(BLA_PKGCONFIG_BLAS "blas")
  198. endif()
  199. find_package(PkgConfig QUIET)
  200. pkg_check_modules(PKGC_BLAS QUIET ${BLA_PKGCONFIG_BLAS})
  201. if(PKGC_BLAS_FOUND)
  202. set(BLAS_FOUND ${PKGC_BLAS_FOUND})
  203. set(BLAS_LIBRARIES "${PKGC_BLAS_LINK_LIBRARIES}")
  204. _add_blas_target()
  205. return()
  206. endif()
  207. endif()
  208. # TODO: move this stuff to a separate module
  209. function(CHECK_BLAS_LIBRARIES LIBRARIES _prefix _name _flags _list _deps _addlibdir _subdirs)
  210. # This function checks for the existence of the combination of libraries
  211. # given by _list. If the combination is found, this checks whether can link
  212. # against that library combination using the name of a routine given by _name
  213. # using the linker flags given by _flags. If the combination of libraries is
  214. # found and passes the link test, ${LIBRARIES} is set to the list of complete
  215. # library paths that have been found. Otherwise, ${LIBRARIES} is set to FALSE.
  216. set(_libraries_work TRUE)
  217. set(_libraries)
  218. set(_combined_name)
  219. if(BLA_STATIC)
  220. if(WIN32)
  221. set(CMAKE_FIND_LIBRARY_SUFFIXES .lib ${CMAKE_FIND_LIBRARY_SUFFIXES})
  222. else()
  223. set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
  224. endif()
  225. else()
  226. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  227. # for ubuntu's libblas3gf and liblapack3gf packages
  228. set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} .so.3gf)
  229. endif()
  230. endif()
  231. set(_extaddlibdir "${_addlibdir}")
  232. if(WIN32)
  233. list(APPEND _extaddlibdir ENV LIB)
  234. elseif(APPLE)
  235. list(APPEND _extaddlibdir ENV DYLD_LIBRARY_PATH)
  236. else()
  237. list(APPEND _extaddlibdir ENV LD_LIBRARY_PATH)
  238. endif()
  239. list(APPEND _extaddlibdir "${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}")
  240. foreach(_library ${_list})
  241. if(_library MATCHES "^-")
  242. # Respect linker flags as-is (required by MKL)
  243. list(APPEND _libraries "${_library}")
  244. else()
  245. string(REGEX REPLACE "[^A-Za-z0-9]" "_" _lib_var "${_library}")
  246. string(APPEND _combined_name "_${_lib_var}")
  247. if(NOT "${_deps}" STREQUAL "")
  248. string(APPEND _combined_name "_deps")
  249. endif()
  250. if(_libraries_work)
  251. find_library(${_prefix}_${_lib_var}_LIBRARY
  252. NAMES ${_library}
  253. NAMES_PER_DIR
  254. PATHS ${_extaddlibdir}
  255. PATH_SUFFIXES ${_subdirs}
  256. )
  257. mark_as_advanced(${_prefix}_${_lib_var}_LIBRARY)
  258. list(APPEND _libraries ${${_prefix}_${_lib_var}_LIBRARY})
  259. set(_libraries_work ${${_prefix}_${_lib_var}_LIBRARY})
  260. endif()
  261. endif()
  262. endforeach()
  263. foreach(_flag ${_flags})
  264. string(REGEX REPLACE "[^A-Za-z0-9]" "_" _flag_var "${_flag}")
  265. string(APPEND _combined_name "_${_flag_var}")
  266. endforeach()
  267. if(_libraries_work)
  268. # Test this combination of libraries.
  269. set(CMAKE_REQUIRED_LIBRARIES ${_flags} ${_libraries} ${_deps})
  270. set(CMAKE_REQUIRED_QUIET ${BLAS_FIND_QUIETLY})
  271. if(CMAKE_Fortran_COMPILER_LOADED)
  272. check_fortran_function_exists("${_name}" ${_prefix}${_combined_name}_WORKS)
  273. else()
  274. check_function_exists("${_name}_" ${_prefix}${_combined_name}_WORKS)
  275. endif()
  276. set(CMAKE_REQUIRED_LIBRARIES)
  277. set(_libraries_work ${${_prefix}${_combined_name}_WORKS})
  278. endif()
  279. if(_libraries_work)
  280. if("${_list}" STREQUAL "")
  281. set(_libraries "${LIBRARIES}-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
  282. else()
  283. list(APPEND _libraries ${_deps})
  284. endif()
  285. else()
  286. set(_libraries FALSE)
  287. endif()
  288. set(${LIBRARIES} "${_libraries}" PARENT_SCOPE)
  289. endfunction()
  290. set(BLAS_LINKER_FLAGS)
  291. set(BLAS_LIBRARIES)
  292. set(BLAS95_LIBRARIES)
  293. set(_blas_fphsa_req_var BLAS_LIBRARIES)
  294. if(NOT BLA_VENDOR)
  295. if(NOT "$ENV{BLA_VENDOR}" STREQUAL "")
  296. set(BLA_VENDOR "$ENV{BLA_VENDOR}")
  297. else()
  298. set(BLA_VENDOR "All")
  299. endif()
  300. endif()
  301. if(NOT BLA_SIZEOF_INTEGER)
  302. # in the reality we do not know which API of BLAS/LAPACK is masked in library
  303. set(_blas_sizeof_integer "ANY")
  304. elseif((BLA_SIZEOF_INTEGER STREQUAL "ANY") OR
  305. (BLA_SIZEOF_INTEGER STREQUAL "4") OR
  306. (BLA_SIZEOF_INTEGER STREQUAL "8"))
  307. set(_blas_sizeof_integer ${BLA_SIZEOF_INTEGER})
  308. else()
  309. message(FATAL_ERROR "BLA_SIZEOF_INTEGER can have only <no value>, ANY, 4, or 8 values")
  310. endif()
  311. # Implicitly linked BLAS libraries?
  312. if(BLA_VENDOR STREQUAL "All")
  313. if(NOT BLAS_LIBRARIES)
  314. check_blas_libraries(
  315. BLAS_LIBRARIES
  316. BLAS
  317. sgemm
  318. ""
  319. ""
  320. ""
  321. ""
  322. ""
  323. )
  324. endif()
  325. if(BLAS_WORKS)
  326. # Give a more helpful "found" message
  327. set(BLAS_WORKS "implicitly linked")
  328. set(_blas_fphsa_req_var BLAS_WORKS)
  329. endif()
  330. endif()
  331. # BLAS in the Intel MKL 10+ library?
  332. if(BLA_VENDOR MATCHES "Intel" OR BLA_VENDOR STREQUAL "All")
  333. if(NOT BLAS_LIBRARIES)
  334. if(CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED)
  335. # System-specific settings
  336. if(WIN32)
  337. if(BLA_STATIC)
  338. set(BLAS_mkl_DLL_SUFFIX "")
  339. else()
  340. set(BLAS_mkl_DLL_SUFFIX "_dll")
  341. endif()
  342. else()
  343. if(BLA_STATIC)
  344. set(BLAS_mkl_START_GROUP "-Wl,--start-group")
  345. set(BLAS_mkl_END_GROUP "-Wl,--end-group")
  346. else()
  347. set(BLAS_mkl_START_GROUP "")
  348. set(BLAS_mkl_END_GROUP "")
  349. endif()
  350. # Switch to GNU Fortran support layer if needed (but not on Apple, where MKL does not provide it)
  351. if(CMAKE_Fortran_COMPILER_LOADED AND (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "LCC") AND NOT APPLE)
  352. set(BLAS_mkl_INTFACE "gf")
  353. set(BLAS_mkl_THREADING "gnu")
  354. set(BLAS_mkl_OMP "gomp")
  355. else()
  356. set(BLAS_mkl_INTFACE "intel")
  357. set(BLAS_mkl_THREADING "intel")
  358. set(BLAS_mkl_OMP "iomp5")
  359. endif()
  360. set(BLAS_mkl_LM "-lm")
  361. set(BLAS_mkl_LDL "-ldl")
  362. endif()
  363. if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  364. find_package(Threads)
  365. else()
  366. find_package(Threads REQUIRED)
  367. endif()
  368. if(_blas_sizeof_integer EQUAL 8)
  369. set(BLAS_mkl_ILP_MODE "ilp64")
  370. elseif(_blas_sizeof_integer EQUAL 4)
  371. set(BLAS_mkl_ILP_MODE "lp64")
  372. else()
  373. if(BLA_VENDOR MATCHES "_64ilp")
  374. set(BLAS_mkl_ILP_MODE "ilp64")
  375. else()
  376. set(BLAS_mkl_ILP_MODE "lp64")
  377. endif()
  378. endif()
  379. set(BLAS_SEARCH_LIBS "")
  380. if(BLA_F95)
  381. set(BLAS_mkl_SEARCH_SYMBOL "sgemm_f95")
  382. set(_BLAS_LIBRARIES BLAS95_LIBRARIES)
  383. if(WIN32)
  384. # Find the main file (32-bit or 64-bit)
  385. set(BLAS_SEARCH_LIBS_WIN_MAIN "")
  386. if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  387. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  388. "mkl_blas95${BLAS_mkl_DLL_SUFFIX} mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
  389. endif()
  390. if(BLA_VENDOR MATCHES "^Intel10_64i?lp" OR BLA_VENDOR STREQUAL "All")
  391. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  392. "mkl_blas95_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX} mkl_intel_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX}")
  393. endif()
  394. # Add threading/sequential libs
  395. set(BLAS_SEARCH_LIBS_WIN_THREAD "")
  396. if(BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
  397. # old version
  398. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  399. "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  400. # mkl >= 10.3
  401. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  402. "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  403. endif()
  404. if(BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
  405. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  406. "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
  407. endif()
  408. # Cartesian product of the above
  409. foreach(MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
  410. foreach(THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
  411. list(APPEND BLAS_SEARCH_LIBS
  412. "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
  413. endforeach()
  414. endforeach()
  415. else()
  416. if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  417. # old version
  418. list(APPEND BLAS_SEARCH_LIBS
  419. "mkl_blas95 mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
  420. # mkl >= 10.3
  421. list(APPEND BLAS_SEARCH_LIBS
  422. "${BLAS_mkl_START_GROUP} mkl_blas95 mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_END_GROUP} ${BLAS_mkl_OMP}")
  423. endif()
  424. if(BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
  425. # old version
  426. list(APPEND BLAS_SEARCH_LIBS
  427. "mkl_blas95 mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
  428. # mkl >= 10.3
  429. list(APPEND BLAS_SEARCH_LIBS
  430. "${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}")
  431. endif()
  432. if(BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
  433. list(APPEND BLAS_SEARCH_LIBS
  434. "${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}")
  435. endif()
  436. endif()
  437. else()
  438. set(BLAS_mkl_SEARCH_SYMBOL sgemm)
  439. set(_BLAS_LIBRARIES BLAS_LIBRARIES)
  440. if(WIN32)
  441. # Find the main file (32-bit or 64-bit)
  442. set(BLAS_SEARCH_LIBS_WIN_MAIN "")
  443. if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  444. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  445. "mkl_intel_c${BLAS_mkl_DLL_SUFFIX}")
  446. endif()
  447. if(BLA_VENDOR MATCHES "^Intel10_64i?lp" OR BLA_VENDOR STREQUAL "All")
  448. list(APPEND BLAS_SEARCH_LIBS_WIN_MAIN
  449. "mkl_intel_${BLAS_mkl_ILP_MODE}${BLAS_mkl_DLL_SUFFIX}")
  450. endif()
  451. # Add threading/sequential libs
  452. set(BLAS_SEARCH_LIBS_WIN_THREAD "")
  453. if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  454. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  455. "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  456. endif()
  457. if(BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
  458. # old version
  459. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  460. "libguide40 mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  461. # mkl >= 10.3
  462. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  463. "libiomp5md mkl_intel_thread${BLAS_mkl_DLL_SUFFIX}")
  464. endif()
  465. if(BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
  466. list(APPEND BLAS_SEARCH_LIBS_WIN_THREAD
  467. "mkl_sequential${BLAS_mkl_DLL_SUFFIX}")
  468. endif()
  469. # Cartesian product of the above
  470. foreach(MAIN ${BLAS_SEARCH_LIBS_WIN_MAIN})
  471. foreach(THREAD ${BLAS_SEARCH_LIBS_WIN_THREAD})
  472. list(APPEND BLAS_SEARCH_LIBS
  473. "${MAIN} ${THREAD} mkl_core${BLAS_mkl_DLL_SUFFIX}")
  474. endforeach()
  475. endforeach()
  476. else()
  477. if(BLA_VENDOR STREQUAL "Intel10_32" OR BLA_VENDOR STREQUAL "All")
  478. # old version
  479. list(APPEND BLAS_SEARCH_LIBS
  480. "mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
  481. # mkl >= 10.3
  482. list(APPEND BLAS_SEARCH_LIBS
  483. "${BLAS_mkl_START_GROUP} mkl_${BLAS_mkl_INTFACE} mkl_${BLAS_mkl_THREADING}_thread mkl_core ${BLAS_mkl_END_GROUP} ${BLAS_mkl_OMP}")
  484. endif()
  485. if(BLA_VENDOR MATCHES "^Intel10_64i?lp$" OR BLA_VENDOR STREQUAL "All")
  486. # old version
  487. list(APPEND BLAS_SEARCH_LIBS
  488. "mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_${BLAS_mkl_THREADING}_thread mkl_core guide")
  489. # mkl >= 10.3
  490. list(APPEND BLAS_SEARCH_LIBS
  491. "${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}")
  492. endif()
  493. if(BLA_VENDOR MATCHES "^Intel10_64i?lp_seq$" OR BLA_VENDOR STREQUAL "All")
  494. list(APPEND BLAS_SEARCH_LIBS
  495. "${BLAS_mkl_START_GROUP} mkl_${BLAS_mkl_INTFACE}_${BLAS_mkl_ILP_MODE} mkl_sequential mkl_core ${BLAS_mkl_END_GROUP}")
  496. endif()
  497. #older versions of intel mkl libs
  498. if(BLA_VENDOR STREQUAL "Intel" OR BLA_VENDOR STREQUAL "All")
  499. list(APPEND BLAS_SEARCH_LIBS
  500. "mkl")
  501. list(APPEND BLAS_SEARCH_LIBS
  502. "mkl_ia32")
  503. list(APPEND BLAS_SEARCH_LIBS
  504. "mkl_em64t")
  505. endif()
  506. endif()
  507. endif()
  508. if(BLA_VENDOR MATCHES "^Intel10_64_dyn$" OR BLA_VENDOR STREQUAL "All")
  509. # mkl >= 10.3 with single dynamic library
  510. list(APPEND BLAS_SEARCH_LIBS
  511. "mkl_rt")
  512. endif()
  513. # MKL uses a multitude of partially platform-specific subdirectories:
  514. if(BLA_VENDOR STREQUAL "Intel10_32")
  515. set(BLAS_mkl_ARCH_NAME "ia32")
  516. else()
  517. set(BLAS_mkl_ARCH_NAME "intel64")
  518. endif()
  519. if(WIN32)
  520. set(BLAS_mkl_OS_NAME "win")
  521. elseif(APPLE)
  522. set(BLAS_mkl_OS_NAME "mac")
  523. else()
  524. set(BLAS_mkl_OS_NAME "lin")
  525. endif()
  526. if(DEFINED ENV{MKLROOT})
  527. file(TO_CMAKE_PATH "$ENV{MKLROOT}" BLAS_mkl_MKLROOT)
  528. # If MKLROOT points to the subdirectory 'mkl', use the parent directory instead
  529. # so we can better detect other relevant libraries in 'compiler' or 'tbb':
  530. get_filename_component(BLAS_mkl_MKLROOT_LAST_DIR "${BLAS_mkl_MKLROOT}" NAME)
  531. if(BLAS_mkl_MKLROOT_LAST_DIR STREQUAL "mkl")
  532. get_filename_component(BLAS_mkl_MKLROOT "${BLAS_mkl_MKLROOT}" DIRECTORY)
  533. endif()
  534. endif()
  535. set(BLAS_mkl_LIB_PATH_SUFFIXES
  536. "compiler/lib" "compiler/lib/${BLAS_mkl_ARCH_NAME}_${BLAS_mkl_OS_NAME}"
  537. "compiler/lib/${BLAS_mkl_ARCH_NAME}"
  538. "mkl/lib" "mkl/lib/${BLAS_mkl_ARCH_NAME}_${BLAS_mkl_OS_NAME}"
  539. "mkl/lib/${BLAS_mkl_ARCH_NAME}"
  540. "lib" "lib/${BLAS_mkl_ARCH_NAME}_${BLAS_mkl_OS_NAME}"
  541. "lib/${BLAS_mkl_ARCH_NAME}"
  542. )
  543. foreach(_search ${BLAS_SEARCH_LIBS})
  544. string(REPLACE " " ";" _search ${_search})
  545. if(NOT ${_BLAS_LIBRARIES})
  546. check_blas_libraries(
  547. ${_BLAS_LIBRARIES}
  548. BLAS
  549. ${BLAS_mkl_SEARCH_SYMBOL}
  550. ""
  551. "${_search}"
  552. "${CMAKE_THREAD_LIBS_INIT};${BLAS_mkl_LM};${BLAS_mkl_LDL}"
  553. "${BLAS_mkl_MKLROOT}"
  554. "${BLAS_mkl_LIB_PATH_SUFFIXES}"
  555. )
  556. endif()
  557. endforeach()
  558. unset(_search)
  559. unset(BLAS_mkl_ILP_MODE)
  560. unset(BLAS_mkl_INTFACE)
  561. unset(BLAS_mkl_THREADING)
  562. unset(BLAS_mkl_OMP)
  563. unset(BLAS_mkl_DLL_SUFFIX)
  564. unset(BLAS_mkl_LM)
  565. unset(BLAS_mkl_LDL)
  566. unset(BLAS_mkl_MKLROOT)
  567. unset(BLAS_mkl_MKLROOT_LAST_DIR)
  568. unset(BLAS_mkl_ARCH_NAME)
  569. unset(BLAS_mkl_OS_NAME)
  570. unset(BLAS_mkl_LIB_PATH_SUFFIXES)
  571. endif()
  572. endif()
  573. endif()
  574. if(BLA_F95)
  575. find_package_handle_standard_args(BLAS REQUIRED_VARS BLAS95_LIBRARIES)
  576. set(BLAS95_FOUND ${BLAS_FOUND})
  577. if(BLAS_FOUND)
  578. set(BLAS_LIBRARIES "${BLAS95_LIBRARIES}")
  579. endif()
  580. endif()
  581. # gotoblas? (http://www.tacc.utexas.edu/tacc-projects/gotoblas2)
  582. if(BLA_VENDOR STREQUAL "Goto" OR BLA_VENDOR STREQUAL "All")
  583. if(NOT BLAS_LIBRARIES)
  584. check_blas_libraries(
  585. BLAS_LIBRARIES
  586. BLAS
  587. sgemm
  588. ""
  589. "goto2"
  590. ""
  591. ""
  592. ""
  593. )
  594. endif()
  595. endif()
  596. # FlexiBLAS? (http://www.mpi-magdeburg.mpg.de/mpcsc/software/FlexiBLAS/)
  597. if(BLA_VENDOR STREQUAL "FlexiBLAS" OR BLA_VENDOR STREQUAL "All")
  598. set(_blas_flexiblas_lib "flexiblas")
  599. if(_blas_sizeof_integer EQUAL 8)
  600. string(APPEND _blas_flexiblas_lib "64")
  601. endif()
  602. if(NOT BLAS_LIBRARIES)
  603. check_blas_libraries(
  604. BLAS_LIBRARIES
  605. BLAS
  606. sgemm
  607. ""
  608. "${_blas_flexiblas_lib}"
  609. ""
  610. ""
  611. ""
  612. )
  613. endif()
  614. unset(_blas_flexiblas_lib)
  615. endif()
  616. # OpenBLAS? (http://www.openblas.net)
  617. if(BLA_VENDOR STREQUAL "OpenBLAS" OR BLA_VENDOR STREQUAL "All")
  618. set(_blas_openblas_lib "openblas")
  619. if(_blas_sizeof_integer EQUAL 8)
  620. string(APPEND _blas_openblas_lib "64")
  621. endif()
  622. if(NOT BLAS_LIBRARIES)
  623. check_blas_libraries(
  624. BLAS_LIBRARIES
  625. BLAS
  626. sgemm
  627. ""
  628. "${_blas_openblas_lib}"
  629. ""
  630. ""
  631. ""
  632. )
  633. endif()
  634. if(NOT BLAS_LIBRARIES AND (CMAKE_C_COMPILER_LOADED OR CMAKE_CXX_COMPILER_LOADED))
  635. if(BLAS_FIND_QUIETLY OR NOT BLAS_FIND_REQUIRED)
  636. find_package(Threads)
  637. else()
  638. find_package(Threads REQUIRED)
  639. endif()
  640. set(_threadlibs "${CMAKE_THREAD_LIBS_INIT}")
  641. if(BLA_STATIC)
  642. if (CMAKE_C_COMPILER_LOADED)
  643. find_package(OpenMP QUIET COMPONENTS C)
  644. list(PREPEND _threadlibs "${OpenMP_C_LIBRARIES}")
  645. elseif(CMAKE_CXX_COMPILER_LOADED)
  646. find_package(OpenMP QUIET COMPONENTS CXX)
  647. list(PREPEND _threadlibs "${OpenMP_CXX_LIBRARIES}")
  648. endif()
  649. endif()
  650. check_blas_libraries(
  651. BLAS_LIBRARIES
  652. BLAS
  653. sgemm
  654. ""
  655. "${_blas_openblas_lib}"
  656. "${_threadlibs}"
  657. ""
  658. ""
  659. )
  660. unset(_threadlibs)
  661. endif()
  662. unset(_blas_openblas_lib)
  663. endif()
  664. # ArmPL blas library? (https://developer.arm.com/tools-and-software/server-and-hpc/compile/arm-compiler-for-linux/arm-performance-libraries)
  665. if(BLA_VENDOR MATCHES "Arm" OR BLA_VENDOR STREQUAL "All")
  666. # Check for 64bit Integer support
  667. if(_blas_sizeof_integer EQUAL 8)
  668. set(_blas_armpl_lib "armpl_ilp64")
  669. elseif(_blas_sizeof_integer EQUAL 4)
  670. set(_blas_armpl_lib "armpl_lp64")
  671. else()
  672. if(BLA_VENDOR MATCHES "_ilp64")
  673. set(_blas_armpl_lib "armpl_ilp64")
  674. else()
  675. set(_blas_armpl_lib "armpl_lp64")
  676. endif()
  677. endif()
  678. # Check for OpenMP support, VIA BLA_VENDOR of Arm_mp or Arm_ipl64_mp
  679. if(BLA_VENDOR MATCHES "_mp")
  680. string(APPEND _blas_armpl_lib "_mp")
  681. endif()
  682. if(NOT BLAS_LIBRARIES)
  683. check_blas_libraries(
  684. BLAS_LIBRARIES
  685. BLAS
  686. sgemm
  687. ""
  688. "${_blas_armpl_lib}"
  689. ""
  690. ""
  691. ""
  692. )
  693. endif()
  694. unset(_blas_armpl_lib)
  695. endif()
  696. # FLAME's blis library? (https://github.com/flame/blis)
  697. if(BLA_VENDOR STREQUAL "FLAME" OR BLA_VENDOR STREQUAL "All")
  698. set(_blas_flame_lib "blis")
  699. if(_blas_sizeof_integer EQUAL 8)
  700. string(APPEND _blas_flame_lib "64")
  701. endif()
  702. if(NOT BLAS_LIBRARIES)
  703. check_blas_libraries(
  704. BLAS_LIBRARIES
  705. BLAS
  706. sgemm
  707. ""
  708. "${_blas_flame_lib}"
  709. ""
  710. ""
  711. ""
  712. )
  713. endif()
  714. unset(_blas_flame_lib)
  715. endif()
  716. # AOCL's blis library? (https://developer.amd.com/amd-aocl/)
  717. if(BLA_VENDOR MATCHES "AOCL" OR BLA_VENDOR STREQUAL "All")
  718. set(_blas_aocl_lib "blis")
  719. if(_blas_sizeof_integer EQUAL 8)
  720. set(_blas_aocl_subdir "ILP64")
  721. else()
  722. set(_blas_aocl_subdir "LP64")
  723. endif()
  724. # Check for multi-threaded support
  725. if(BLA_VENDOR MATCHES "_mt")
  726. string(APPEND _blas_aocl_lib "-mt")
  727. endif()
  728. if(NOT BLAS_LIBRARIES)
  729. check_blas_libraries(
  730. BLAS_LIBRARIES
  731. BLAS
  732. sgemm
  733. ""
  734. "${_blas_aocl_lib}"
  735. ""
  736. ""
  737. "${_blas_aocl_subdir}"
  738. )
  739. endif()
  740. unset(_blas_aocl_lib)
  741. unset(_blas_aocl_subdir)
  742. endif()
  743. # BLAS in the ATLAS library? (http://math-atlas.sourceforge.net/)
  744. if(BLA_VENDOR STREQUAL "ATLAS" OR BLA_VENDOR STREQUAL "All")
  745. if(NOT BLAS_LIBRARIES)
  746. check_blas_libraries(
  747. BLAS_LIBRARIES
  748. BLAS
  749. dgemm
  750. ""
  751. "blas;f77blas;atlas"
  752. ""
  753. ""
  754. ""
  755. )
  756. endif()
  757. endif()
  758. # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
  759. if(BLA_VENDOR STREQUAL "PhiPACK" OR BLA_VENDOR STREQUAL "All")
  760. if(NOT BLAS_LIBRARIES)
  761. check_blas_libraries(
  762. BLAS_LIBRARIES
  763. BLAS
  764. sgemm
  765. ""
  766. "sgemm;dgemm;blas"
  767. ""
  768. ""
  769. ""
  770. )
  771. endif()
  772. endif()
  773. # BLAS in Alpha CXML library?
  774. if(BLA_VENDOR STREQUAL "CXML" OR BLA_VENDOR STREQUAL "All")
  775. if(_blas_sizeof_integer EQUAL 8)
  776. if(BLA_VENDOR STREQUAL "CXML")
  777. message(FATAL_ERROR "CXML does not support Int64 type")
  778. endif()
  779. else()
  780. if(NOT BLAS_LIBRARIES)
  781. check_blas_libraries(
  782. BLAS_LIBRARIES
  783. BLAS
  784. sgemm
  785. ""
  786. "cxml"
  787. ""
  788. ""
  789. ""
  790. )
  791. endif()
  792. endif()
  793. endif()
  794. # BLAS in Alpha DXML library? (now called CXML, see above)
  795. if(BLA_VENDOR STREQUAL "DXML" OR BLA_VENDOR STREQUAL "All")
  796. if(_blas_sizeof_integer EQUAL 8)
  797. if(BLA_VENDOR STREQUAL "DXML")
  798. message(FATAL_ERROR "DXML does not support Int64 type")
  799. endif()
  800. else()
  801. if(NOT BLAS_LIBRARIES)
  802. check_blas_libraries(
  803. BLAS_LIBRARIES
  804. BLAS
  805. sgemm
  806. ""
  807. "dxml"
  808. ""
  809. ""
  810. ""
  811. )
  812. endif()
  813. endif()
  814. endif()
  815. # BLAS in Sun Performance library?
  816. if(BLA_VENDOR STREQUAL "SunPerf" OR BLA_VENDOR STREQUAL "All")
  817. if(NOT BLAS_LIBRARIES)
  818. check_blas_libraries(
  819. BLAS_LIBRARIES
  820. BLAS
  821. sgemm
  822. "-xlic_lib=sunperf"
  823. "sunperf;sunmath"
  824. ""
  825. ""
  826. ""
  827. )
  828. if(BLAS_LIBRARIES)
  829. set(BLAS_LINKER_FLAGS "-xlic_lib=sunperf")
  830. endif()
  831. endif()
  832. endif()
  833. # BLAS in SCSL library? (SGI/Cray Scientific Library)
  834. if(BLA_VENDOR MATCHES "SCSL" OR BLA_VENDOR STREQUAL "All")
  835. set(_blas_scsl_lib "scs")
  836. if(_blas_sizeof_integer EQUAL 8)
  837. string(APPEND _blas_scsl_lib "_i8")
  838. endif()
  839. if(BLA_VENDOR MATCHES "_mp")
  840. string(APPEND _blas_scsl_lib "_mp")
  841. endif()
  842. if(NOT BLAS_LIBRARIES)
  843. check_blas_libraries(
  844. BLAS_LIBRARIES
  845. BLAS
  846. sgemm
  847. ""
  848. "${_blas_scsl_lib}"
  849. ""
  850. ""
  851. ""
  852. )
  853. endif()
  854. unset(_blas_scsl_lib)
  855. endif()
  856. # BLAS in SGIMATH library?
  857. if(BLA_VENDOR STREQUAL "SGIMATH" OR BLA_VENDOR STREQUAL "All")
  858. if(NOT BLAS_LIBRARIES)
  859. check_blas_libraries(
  860. BLAS_LIBRARIES
  861. BLAS
  862. sgemm
  863. ""
  864. "complib.sgimath"
  865. ""
  866. ""
  867. ""
  868. )
  869. endif()
  870. endif()
  871. # BLAS in IBM ESSL library?
  872. if(BLA_VENDOR MATCHES "IBMESSL" OR BLA_VENDOR STREQUAL "All")
  873. set(_blas_essl_lib "essl")
  874. if(BLA_VENDOR MATCHES "_SMP")
  875. string(APPEND _blas_essl_lib "smp")
  876. endif()
  877. if(_blas_sizeof_integer EQUAL 8)
  878. string(APPEND _blas_essl_lib "6464")
  879. endif()
  880. if(NOT BLAS_LIBRARIES)
  881. check_blas_libraries(
  882. BLAS_LIBRARIES
  883. BLAS
  884. sgemm
  885. ""
  886. "${_blas_essl_lib}"
  887. ""
  888. ""
  889. ""
  890. )
  891. endif()
  892. unset(_blas_essl_lib)
  893. endif()
  894. # BLAS in acml library?
  895. if(BLA_VENDOR MATCHES "ACML" OR BLA_VENDOR STREQUAL "All")
  896. if(((BLA_VENDOR STREQUAL "ACML") AND (NOT BLAS_ACML_LIB_DIRS)) OR
  897. ((BLA_VENDOR STREQUAL "ACML_MP") AND (NOT BLAS_ACML_MP_LIB_DIRS)) OR
  898. ((BLA_VENDOR STREQUAL "ACML_GPU") AND (NOT BLAS_ACML_GPU_LIB_DIRS))
  899. )
  900. # try to find acml in "standard" paths
  901. if(WIN32)
  902. file(GLOB _ACML_ROOT "C:/AMD/acml*/ACML-EULA.txt")
  903. else()
  904. file(GLOB _ACML_ROOT "/opt/acml*/ACML-EULA.txt")
  905. endif()
  906. if(WIN32)
  907. file(GLOB _ACML_GPU_ROOT "C:/AMD/acml*/GPGPUexamples")
  908. else()
  909. file(GLOB _ACML_GPU_ROOT "/opt/acml*/GPGPUexamples")
  910. endif()
  911. list(GET _ACML_ROOT 0 _ACML_ROOT)
  912. list(GET _ACML_GPU_ROOT 0 _ACML_GPU_ROOT)
  913. if(_ACML_ROOT)
  914. get_filename_component(_ACML_ROOT ${_ACML_ROOT} PATH)
  915. if(_blas_sizeof_integer EQUAL 8)
  916. set(_ACML_PATH_SUFFIX "_int64")
  917. else()
  918. set(_ACML_PATH_SUFFIX "")
  919. endif()
  920. if(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
  921. set(_ACML_COMPILER32 "ifort32")
  922. set(_ACML_COMPILER64 "ifort64")
  923. elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
  924. # 32-bit not supported
  925. set(_ACML_COMPILER64 "ifx")
  926. elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "SunPro")
  927. set(_ACML_COMPILER32 "sun32")
  928. set(_ACML_COMPILER64 "sun64")
  929. elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "PGI")
  930. set(_ACML_COMPILER32 "pgi32")
  931. if(WIN32)
  932. set(_ACML_COMPILER64 "win64")
  933. else()
  934. set(_ACML_COMPILER64 "pgi64")
  935. endif()
  936. elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Open64")
  937. # 32 bit builds not supported on Open64 but for code simplicity
  938. # We'll just use the same directory twice
  939. set(_ACML_COMPILER32 "open64_64")
  940. set(_ACML_COMPILER64 "open64_64")
  941. elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "NAG")
  942. set(_ACML_COMPILER32 "nag32")
  943. set(_ACML_COMPILER64 "nag64")
  944. else()
  945. set(_ACML_COMPILER32 "gfortran32")
  946. set(_ACML_COMPILER64 "gfortran64")
  947. endif()
  948. if(BLA_VENDOR STREQUAL "ACML_MP")
  949. set(_ACML_MP_LIB_DIRS
  950. "${_ACML_ROOT}/${_ACML_COMPILER32}_mp${_ACML_PATH_SUFFIX}/lib"
  951. "${_ACML_ROOT}/${_ACML_COMPILER64}_mp${_ACML_PATH_SUFFIX}/lib")
  952. else()
  953. set(_ACML_LIB_DIRS
  954. "${_ACML_ROOT}/${_ACML_COMPILER32}${_ACML_PATH_SUFFIX}/lib"
  955. "${_ACML_ROOT}/${_ACML_COMPILER64}${_ACML_PATH_SUFFIX}/lib")
  956. endif()
  957. endif()
  958. elseif(BLAS_${BLA_VENDOR}_LIB_DIRS)
  959. set(_${BLA_VENDOR}_LIB_DIRS ${BLAS_${BLA_VENDOR}_LIB_DIRS})
  960. endif()
  961. if(BLA_VENDOR STREQUAL "ACML_MP")
  962. foreach(BLAS_ACML_MP_LIB_DIRS ${_ACML_MP_LIB_DIRS})
  963. check_blas_libraries(
  964. BLAS_LIBRARIES
  965. BLAS
  966. sgemm
  967. "" "acml_mp;acml_mv" "" ${BLAS_ACML_MP_LIB_DIRS} ""
  968. )
  969. if(BLAS_LIBRARIES)
  970. break()
  971. endif()
  972. endforeach()
  973. elseif(BLA_VENDOR STREQUAL "ACML_GPU")
  974. foreach(BLAS_ACML_GPU_LIB_DIRS ${_ACML_GPU_LIB_DIRS})
  975. check_blas_libraries(
  976. BLAS_LIBRARIES
  977. BLAS
  978. sgemm
  979. "" "acml;acml_mv;CALBLAS" "" ${BLAS_ACML_GPU_LIB_DIRS} ""
  980. )
  981. if(BLAS_LIBRARIES)
  982. break()
  983. endif()
  984. endforeach()
  985. else()
  986. foreach(BLAS_ACML_LIB_DIRS ${_ACML_LIB_DIRS})
  987. check_blas_libraries(
  988. BLAS_LIBRARIES
  989. BLAS
  990. sgemm
  991. "" "acml;acml_mv" "" ${BLAS_ACML_LIB_DIRS} ""
  992. )
  993. if(BLAS_LIBRARIES)
  994. break()
  995. endif()
  996. endforeach()
  997. endif()
  998. # Either acml or acml_mp should be in LD_LIBRARY_PATH but not both
  999. if(NOT BLAS_LIBRARIES)
  1000. check_blas_libraries(
  1001. BLAS_LIBRARIES
  1002. BLAS
  1003. sgemm
  1004. ""
  1005. "acml;acml_mv"
  1006. ""
  1007. ""
  1008. ""
  1009. )
  1010. endif()
  1011. if(NOT BLAS_LIBRARIES)
  1012. check_blas_libraries(
  1013. BLAS_LIBRARIES
  1014. BLAS
  1015. sgemm
  1016. ""
  1017. "acml_mp;acml_mv"
  1018. ""
  1019. ""
  1020. ""
  1021. )
  1022. endif()
  1023. if(NOT BLAS_LIBRARIES)
  1024. check_blas_libraries(
  1025. BLAS_LIBRARIES
  1026. BLAS
  1027. sgemm
  1028. ""
  1029. "acml;acml_mv;CALBLAS"
  1030. ""
  1031. ""
  1032. ""
  1033. )
  1034. endif()
  1035. endif() # ACML
  1036. # Apple BLAS library?
  1037. if(BLA_VENDOR STREQUAL "Apple" OR BLA_VENDOR STREQUAL "All")
  1038. if(_blas_sizeof_integer EQUAL 8)
  1039. if(BLA_VENDOR STREQUAL "Apple")
  1040. message(FATAL_ERROR "Accelerate Framework does not support Int64 type")
  1041. endif()
  1042. else()
  1043. if(NOT BLAS_LIBRARIES)
  1044. check_blas_libraries(
  1045. BLAS_LIBRARIES
  1046. BLAS
  1047. dgemm
  1048. ""
  1049. "Accelerate"
  1050. ""
  1051. ""
  1052. ""
  1053. )
  1054. endif()
  1055. endif()
  1056. endif()
  1057. # Apple NAS (vecLib) library?
  1058. if(BLA_VENDOR STREQUAL "NAS" OR BLA_VENDOR STREQUAL "All")
  1059. if(_blas_sizeof_integer EQUAL 8)
  1060. if(BLA_VENDOR STREQUAL "NAS")
  1061. message(FATAL_ERROR "Accelerate Framework does not support Int64 type")
  1062. endif()
  1063. else()
  1064. if(NOT BLAS_LIBRARIES)
  1065. check_blas_libraries(
  1066. BLAS_LIBRARIES
  1067. BLAS
  1068. dgemm
  1069. ""
  1070. "vecLib"
  1071. ""
  1072. ""
  1073. ""
  1074. )
  1075. endif()
  1076. endif()
  1077. endif()
  1078. # Elbrus Math Library?
  1079. if(BLA_VENDOR MATCHES "EML" OR BLA_VENDOR STREQUAL "All")
  1080. set(_blas_eml_lib "eml")
  1081. if(_blas_sizeof_integer EQUAL 8)
  1082. string(APPEND _blas_eml_lib "_ilp64")
  1083. endif()
  1084. # Check for OpenMP support, VIA BLA_VENDOR of eml_mt
  1085. if(BLA_VENDOR MATCHES "_mt")
  1086. string(APPEND _blas_eml_lib "_mt")
  1087. endif()
  1088. if(NOT BLAS_LIBRARIES)
  1089. check_blas_libraries(
  1090. BLAS_LIBRARIES
  1091. BLAS
  1092. sgemm
  1093. ""
  1094. "${_blas_eml_lib}"
  1095. ""
  1096. ""
  1097. ""
  1098. )
  1099. endif()
  1100. unset(_blas_eml_lib)
  1101. endif()
  1102. # Fujitsu SSL2 Library?
  1103. if(NOT BLAS_LIBRARIES
  1104. AND (BLA_VENDOR MATCHES "^Fujitsu_SSL2" OR BLA_VENDOR STREQUAL "All"))
  1105. set(_blas_fjlapack_lib "fjlapack")
  1106. set(_blas_fjlapack_flags "-Kopenmp")
  1107. if(BLA_VENDOR MATCHES "BLAMP")
  1108. string(APPEND _blas_fjlapack_lib "ex")
  1109. endif()
  1110. if(BLA_VENDOR MATCHES "SVE")
  1111. string(APPEND _blas_fjlapack_lib "sve")
  1112. endif()
  1113. if(_blas_sizeof_integer EQUAL 8)
  1114. string(APPEND _blas_fjlapack_lib "_ilp64")
  1115. endif()
  1116. if(NOT BLAS_LIBRARIES)
  1117. check_blas_libraries(
  1118. BLAS_LIBRARIES
  1119. BLAS
  1120. sgemm
  1121. "${_blas_fjlapack_flags}"
  1122. "${_blas_fjlapack_lib}"
  1123. ""
  1124. ""
  1125. ""
  1126. )
  1127. if(BLAS_LIBRARIES)
  1128. set(BLAS_LINKER_FLAGS ${_blas_fjlapack_flags})
  1129. endif()
  1130. endif()
  1131. unset(_blas_fjlapack_flags)
  1132. unset(_blas_fjlapack_lib)
  1133. endif()
  1134. # BLAS in nVidia HPC SDK? (https://developer.nvidia.com/hpc-sdk)
  1135. if(BLA_VENDOR STREQUAL "NVHPC" OR BLA_VENDOR STREQUAL "All")
  1136. set(_blas_nvhpc_lib "blas")
  1137. if(_blas_sizeof_integer EQUAL 8)
  1138. string(APPEND _blas_nvhpc_lib "_ilp64")
  1139. elseif(_blas_sizeof_integer EQUAL 4)
  1140. string(APPEND _blas_nvhpc_lib "_lp64")
  1141. endif()
  1142. if(NOT BLAS_LIBRARIES)
  1143. check_blas_libraries(
  1144. BLAS_LIBRARIES
  1145. BLAS
  1146. sgemm
  1147. ""
  1148. "${_blas_nvhpc_lib}"
  1149. ""
  1150. ""
  1151. ""
  1152. )
  1153. endif()
  1154. # an additional check for NVHPC 2020
  1155. # which does not have differentiation
  1156. # between lp64 and ilp64 modes
  1157. if(NOT BLAS_LIBRARIES AND NOT _blas_sizeof_integer EQUAL 8)
  1158. set(_blas_nvhpc_lib "blas")
  1159. check_blas_libraries(
  1160. BLAS_LIBRARIES
  1161. BLAS
  1162. sgemm
  1163. ""
  1164. "${_blas_nvhpc_lib}"
  1165. ""
  1166. ""
  1167. ""
  1168. )
  1169. endif()
  1170. unset(_blas_nvhpc_lib)
  1171. endif()
  1172. # Generic BLAS library?
  1173. if(BLA_VENDOR STREQUAL "Generic" OR
  1174. BLA_VENDOR STREQUAL "All")
  1175. set(_blas_generic_lib "blas")
  1176. if(_blas_sizeof_integer EQUAL 8)
  1177. string(APPEND _blas_generic_lib "64")
  1178. endif()
  1179. if(NOT BLAS_LIBRARIES)
  1180. check_blas_libraries(
  1181. BLAS_LIBRARIES
  1182. BLAS
  1183. sgemm
  1184. ""
  1185. "${_blas_generic_lib}"
  1186. ""
  1187. ""
  1188. ""
  1189. )
  1190. endif()
  1191. unset(_blas_generic_lib)
  1192. endif()
  1193. # On compilers that implicitly link BLAS (i.e. CrayPrgEnv) we used a
  1194. # placeholder for empty BLAS_LIBRARIES to get through our logic above.
  1195. if(BLAS_LIBRARIES STREQUAL "BLAS_LIBRARIES-PLACEHOLDER-FOR-EMPTY-LIBRARIES")
  1196. set(BLAS_LIBRARIES "")
  1197. endif()
  1198. if(NOT BLA_F95)
  1199. find_package_handle_standard_args(BLAS REQUIRED_VARS ${_blas_fphsa_req_var})
  1200. endif()
  1201. _add_blas_target()
  1202. unset(_blas_fphsa_req_var)
  1203. unset(_blas_sizeof_integer)
  1204. unset(_BLAS_LIBRARIES)