FindBLAS.cmake 38 KB

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