FindBLAS.cmake 40 KB

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