FindBLASEXT.cmake 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. ###
  2. #
  3. # @copyright (c) 2009-2014 The University of Tennessee and The University
  4. # of Tennessee Research Foundation.
  5. # All rights reserved.
  6. # @copyright (c) 2012-2016 Inria. All rights reserved.
  7. # @copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
  8. #
  9. ###
  10. #
  11. # - Find BLAS EXTENDED for MORSE projects: find include dirs and libraries
  12. #
  13. # This module allows to find BLAS libraries by calling the official FindBLAS module
  14. # and handles the creation of different library lists whether the user wishes to link
  15. # with a sequential BLAS or a multihreaded (BLAS_SEQ_LIBRARIES and BLAS_PAR_LIBRARIES).
  16. # BLAS is detected with a FindBLAS call then if the BLAS vendor is Intel10_64lp, ACML
  17. # or IBMESSLMT then the module attempts to find the corresponding multithreaded libraries.
  18. #
  19. # The following variables have been added to manage links with sequential or multithreaded
  20. # versions:
  21. # BLAS_INCLUDE_DIRS - BLAS include directories
  22. # BLAS_LIBRARY_DIRS - Link directories for BLAS libraries
  23. # BLAS_SEQ_LIBRARIES - BLAS component libraries to be linked (sequential)
  24. # BLAS_PAR_LIBRARIES - BLAS component libraries to be linked (multithreaded)
  25. #=============================================================================
  26. # Copyright 2012-2013 Inria
  27. # Copyright 2012-2013 Emmanuel Agullo
  28. # Copyright 2012-2013 Mathieu Faverge
  29. # Copyright 2012 Cedric Castagnede
  30. # Copyright 2013-2016 Florent Pruvost
  31. #
  32. # Distributed under the OSI-approved BSD License (the "License");
  33. # see accompanying file MORSE-Copyright.txt for details.
  34. #
  35. # This software is distributed WITHOUT ANY WARRANTY; without even the
  36. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  37. # See the License for more information.
  38. #=============================================================================
  39. # (To distribute this file outside of Morse, substitute the full
  40. # License text for the above reference.)
  41. # macro to factorize this call
  42. include(CMakeFindDependencyMacro)
  43. macro(find_package_blas)
  44. if(BLASEXT_FIND_REQUIRED)
  45. if(BLASEXT_FIND_QUIETLY)
  46. find_dependency(BLAS REQUIRED QUIET)
  47. else()
  48. find_dependency(BLAS REQUIRED)
  49. endif()
  50. else()
  51. if(BLASEXT_FIND_QUIETLY)
  52. find_dependency(BLAS QUIET)
  53. else()
  54. find_dependency(BLAS)
  55. endif()
  56. endif()
  57. endmacro()
  58. # add a cache variable to let the user specify the BLAS vendor
  59. set(BLA_VENDOR "" CACHE STRING "list of possible BLAS vendor:
  60. Open, Eigen, Goto, ATLAS PhiPACK, CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, IBMESSLMT,
  61. Intel10_32 (intel mkl v10 32 bit),
  62. Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model),
  63. Intel10_64lp_seq (intel mkl v10 64 bit, sequential code, lp64 model),
  64. Intel( older versions of mkl 32 and 64 bit),
  65. ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic")
  66. if(NOT BLASEXT_FIND_QUIETLY)
  67. message(STATUS "In FindBLASEXT")
  68. message(STATUS "If you want to force the use of one specific library, "
  69. "\n please specify the BLAS vendor by setting -DBLA_VENDOR=blas_vendor_name"
  70. "\n at cmake configure.")
  71. message(STATUS "List of possible BLAS vendor: Goto, ATLAS PhiPACK, CXML, "
  72. "\n DXML, SunPerf, SCSL, SGIMATH, IBMESSL, IBMESSLMT, Intel10_32 (intel mkl v10 32 bit),"
  73. "\n Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model),"
  74. "\n Intel10_64lp_seq (intel mkl v10 64 bit, sequential code, lp64 model),"
  75. "\n Intel( older versions of mkl 32 and 64 bit),"
  76. "\n ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic")
  77. endif()
  78. if (NOT BLAS_FOUND)
  79. # First try to detect two cases:
  80. # 1: only SEQ libs are handled
  81. # 2: both SEQ and PAR libs are handled
  82. find_package_blas()
  83. endif ()
  84. # detect the cases where SEQ and PAR libs are handled
  85. if(BLA_VENDOR STREQUAL "All" AND
  86. (BLAS_mkl_core_LIBRARY OR BLAS_mkl_core_dll_LIBRARY)
  87. )
  88. set(BLA_VENDOR "Intel")
  89. if(BLAS_mkl_intel_LIBRARY)
  90. set(BLA_VENDOR "Intel10_32")
  91. endif()
  92. if(BLAS_mkl_intel_lp64_LIBRARY)
  93. set(BLA_VENDOR "Intel10_64lp")
  94. endif()
  95. if(NOT BLASEXT_FIND_QUIETLY)
  96. message(STATUS "A BLAS library has been found (${BLAS_LIBRARIES}) but we"
  97. "\n have also potentially detected some multithreaded BLAS libraries from the MKL."
  98. "\n We try to find both libraries lists (Sequential/Multithreaded).")
  99. endif()
  100. set(BLAS_FOUND "")
  101. elseif(BLA_VENDOR STREQUAL "All" AND BLAS_acml_LIBRARY)
  102. set(BLA_VENDOR "ACML")
  103. if(NOT BLASEXT_FIND_QUIETLY)
  104. message(STATUS "A BLAS library has been found (${BLAS_LIBRARIES}) but we"
  105. "\n have also potentially detected some multithreaded BLAS libraries from the ACML."
  106. "\n We try to find both libraries lists (Sequential/Multithreaded).")
  107. endif()
  108. set(BLAS_FOUND "")
  109. elseif(BLA_VENDOR STREQUAL "All" AND BLAS_essl_LIBRARY)
  110. set(BLA_VENDOR "IBMESSL")
  111. if(NOT BLASEXT_FIND_QUIETLY)
  112. message(STATUS "A BLAS library has been found (${BLAS_LIBRARIES}) but we"
  113. "\n have also potentially detected some multithreaded BLAS libraries from the ESSL."
  114. "\n We try to find both libraries lists (Sequential/Multithreaded).")
  115. endif()
  116. set(BLAS_FOUND "")
  117. endif()
  118. # Intel case
  119. if(BLA_VENDOR MATCHES "Intel*")
  120. ###
  121. # look for include path if the BLAS vendor is Intel
  122. ###
  123. # gather system include paths
  124. unset(_inc_env)
  125. if(WIN32)
  126. string(REPLACE ":" ";" _inc_env "$ENV{INCLUDE}")
  127. else()
  128. string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
  129. list(APPEND _inc_env "${_path_env}")
  130. string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
  131. list(APPEND _inc_env "${_path_env}")
  132. string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
  133. list(APPEND _inc_env "${_path_env}")
  134. string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
  135. list(APPEND _inc_env "${_path_env}")
  136. endif()
  137. list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
  138. list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
  139. set(ENV_MKLROOT "$ENV{MKLROOT}")
  140. if (ENV_MKLROOT)
  141. list(APPEND _inc_env "${ENV_MKLROOT}/include")
  142. endif()
  143. list(REMOVE_DUPLICATES _inc_env)
  144. # find mkl.h inside known include paths
  145. set(BLAS_mkl.h_INCLUDE_DIRS "BLAS_mkl.h_INCLUDE_DIRS-NOTFOUND")
  146. if(BLAS_INCDIR)
  147. set(BLAS_mkl.h_INCLUDE_DIRS "BLAS_mkl.h_INCLUDE_DIRS-NOTFOUND")
  148. find_path(BLAS_mkl.h_INCLUDE_DIRS
  149. NAMES mkl.h
  150. HINTS ${BLAS_INCDIR})
  151. else()
  152. if(BLAS_DIR)
  153. set(BLAS_mkl.h_INCLUDE_DIRS "BLAS_mkl.h_INCLUDE_DIRS-NOTFOUND")
  154. find_path(BLAS_mkl.h_INCLUDE_DIRS
  155. NAMES mkl.h
  156. HINTS ${BLAS_DIR}
  157. PATH_SUFFIXES include)
  158. else()
  159. set(BLAS_mkl.h_INCLUDE_DIRS "BLAS_mkl.h_INCLUDE_DIRS-NOTFOUND")
  160. find_path(BLAS_mkl.h_INCLUDE_DIRS
  161. NAMES mkl.h
  162. HINTS ${_inc_env})
  163. endif()
  164. endif()
  165. mark_as_advanced(BLAS_mkl.h_INCLUDE_DIRS)
  166. ## Print status if not found
  167. ## -------------------------
  168. #if (NOT BLAS_mkl.h_INCLUDE_DIRS AND MORSE_VERBOSE)
  169. # Print_Find_Header_Status(blas mkl.h)
  170. #endif ()
  171. set(BLAS_INCLUDE_DIRS "")
  172. if(BLAS_mkl.h_INCLUDE_DIRS)
  173. list(APPEND BLAS_INCLUDE_DIRS "${BLAS_mkl.h_INCLUDE_DIRS}" )
  174. endif()
  175. ###
  176. # look for libs
  177. ###
  178. # if Intel 10 64 bit -> look for sequential and multithreaded versions
  179. if(BLA_VENDOR MATCHES "Intel10_64lp*")
  180. ## look for the sequential version
  181. set(BLA_VENDOR "Intel10_64lp_seq")
  182. if(NOT BLASEXT_FIND_QUIETLY)
  183. message(STATUS "Look for the sequential version Intel10_64lp_seq")
  184. endif()
  185. find_package_blas()
  186. if(BLAS_FOUND)
  187. set(BLAS_SEQ_LIBRARIES "${BLAS_LIBRARIES}")
  188. else()
  189. set(BLAS_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES-NOTFOUND}")
  190. endif()
  191. ## look for the multithreaded version
  192. set(BLA_VENDOR "Intel10_64lp")
  193. if(NOT BLASEXT_FIND_QUIETLY)
  194. message(STATUS "Look for the multithreaded version Intel10_64lp")
  195. endif()
  196. find_package_blas()
  197. if(BLAS_FOUND)
  198. set(BLAS_PAR_LIBRARIES "${BLAS_LIBRARIES}")
  199. else()
  200. set(BLAS_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES-NOTFOUND}")
  201. endif()
  202. else()
  203. if(BLAS_FOUND)
  204. set(BLAS_SEQ_LIBRARIES "${BLAS_LIBRARIES}")
  205. else()
  206. set(BLAS_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES-NOTFOUND}")
  207. endif()
  208. endif()
  209. # ACML case
  210. elseif(BLA_VENDOR MATCHES "ACML*")
  211. ## look for the sequential version
  212. set(BLA_VENDOR "ACML")
  213. find_package_blas()
  214. if(BLAS_FOUND)
  215. set(BLAS_SEQ_LIBRARIES "${BLAS_LIBRARIES}")
  216. else()
  217. set(BLAS_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES-NOTFOUND}")
  218. endif()
  219. ## look for the multithreaded version
  220. set(BLA_VENDOR "ACML_MP")
  221. find_package_blas()
  222. if(BLAS_FOUND)
  223. set(BLAS_PAR_LIBRARIES "${BLAS_LIBRARIES}")
  224. else()
  225. set(BLAS_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES-NOTFOUND}")
  226. endif()
  227. # IBMESSL case
  228. elseif(BLA_VENDOR MATCHES "IBMESSL*")
  229. ## look for the sequential version
  230. set(BLA_VENDOR "IBMESSL")
  231. find_package_blas()
  232. if(BLAS_FOUND)
  233. set(BLAS_SEQ_LIBRARIES "${BLAS_LIBRARIES}")
  234. else()
  235. set(BLAS_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES-NOTFOUND}")
  236. endif()
  237. ## look for the multithreaded version
  238. set(BLA_VENDOR "IBMESSLMT")
  239. find_package_blas()
  240. if(BLAS_FOUND)
  241. set(BLAS_PAR_LIBRARIES "${BLAS_LIBRARIES}")
  242. else()
  243. set(BLAS_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES-NOTFOUND}")
  244. endif()
  245. else()
  246. if(BLAS_FOUND)
  247. # define the SEQ libs as the BLAS_LIBRARIES
  248. set(BLAS_SEQ_LIBRARIES "${BLAS_LIBRARIES}")
  249. else()
  250. set(BLAS_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES-NOTFOUND}")
  251. endif()
  252. set(BLAS_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES-NOTFOUND}")
  253. endif()
  254. if(BLAS_SEQ_LIBRARIES)
  255. set(BLAS_LIBRARIES "${BLAS_SEQ_LIBRARIES}")
  256. endif()
  257. # extract libs paths
  258. # remark: because it is not given by find_package(BLAS)
  259. set(BLAS_LIBRARY_DIRS "")
  260. string(REPLACE " " ";" BLAS_LIBRARIES "${BLAS_LIBRARIES}")
  261. foreach(blas_lib ${BLAS_LIBRARIES})
  262. if (EXISTS "${blas_lib}")
  263. get_filename_component(a_blas_lib_dir "${blas_lib}" PATH)
  264. list(APPEND BLAS_LIBRARY_DIRS "${a_blas_lib_dir}" )
  265. else()
  266. string(REPLACE "-L" "" blas_lib "${blas_lib}")
  267. if (EXISTS "${blas_lib}")
  268. list(APPEND BLAS_LIBRARY_DIRS "${blas_lib}" )
  269. else()
  270. get_filename_component(a_blas_lib_dir "${blas_lib}" PATH)
  271. if (EXISTS "${a_blas_lib_dir}")
  272. list(APPEND BLAS_LIBRARY_DIRS "${a_blas_lib_dir}" )
  273. endif()
  274. endif()
  275. endif()
  276. endforeach()
  277. if (BLAS_LIBRARY_DIRS)
  278. list(REMOVE_DUPLICATES BLAS_LIBRARY_DIRS)
  279. endif ()
  280. # check that BLAS has been found
  281. # ---------------------------------
  282. include(FindPackageHandleStandardArgs)
  283. if(BLA_VENDOR MATCHES "Intel*")
  284. if(BLA_VENDOR MATCHES "Intel10_64lp*")
  285. if(NOT BLASEXT_FIND_QUIETLY)
  286. message(STATUS "BLAS found is Intel MKL:"
  287. "\n we manage two lists of libs, one sequential and one parallel if found"
  288. "\n (see BLAS_SEQ_LIBRARIES and BLAS_PAR_LIBRARIES)")
  289. message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES")
  290. endif()
  291. find_package_handle_standard_args(BLASEXT DEFAULT_MSG
  292. BLAS_SEQ_LIBRARIES
  293. BLAS_LIBRARY_DIRS
  294. BLAS_INCLUDE_DIRS)
  295. if(BLAS_PAR_LIBRARIES)
  296. if(NOT BLASEXT_FIND_QUIETLY)
  297. message(STATUS "BLAS parallel libraries stored in BLAS_PAR_LIBRARIES")
  298. endif()
  299. find_package_handle_standard_args(BLASEXT DEFAULT_MSG
  300. BLAS_PAR_LIBRARIES)
  301. endif()
  302. else()
  303. if(NOT BLASEXT_FIND_QUIETLY)
  304. message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES")
  305. endif()
  306. find_package_handle_standard_args(BLASEXT DEFAULT_MSG
  307. BLAS_SEQ_LIBRARIES
  308. BLAS_LIBRARY_DIRS
  309. BLAS_INCLUDE_DIRS)
  310. endif()
  311. elseif(BLA_VENDOR MATCHES "ACML*")
  312. if(NOT BLASEXT_FIND_QUIETLY)
  313. message(STATUS "BLAS found is ACML:"
  314. "\n we manage two lists of libs, one sequential and one parallel if found"
  315. "\n (see BLAS_SEQ_LIBRARIES and BLAS_PAR_LIBRARIES)")
  316. message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES")
  317. endif()
  318. find_package_handle_standard_args(BLASEXT DEFAULT_MSG
  319. BLAS_SEQ_LIBRARIES
  320. BLAS_LIBRARY_DIRS)
  321. if(BLAS_PAR_LIBRARIES)
  322. if(NOT BLASEXT_FIND_QUIETLY)
  323. message(STATUS "BLAS parallel libraries stored in BLAS_PAR_LIBRARIES")
  324. endif()
  325. find_package_handle_standard_args(BLASEXT DEFAULT_MSG
  326. BLAS_PAR_LIBRARIES)
  327. endif()
  328. elseif(BLA_VENDOR MATCHES "IBMESSL*")
  329. if(NOT BLASEXT_FIND_QUIETLY)
  330. message(STATUS "BLAS found is ESSL:"
  331. "\n we manage two lists of libs, one sequential and one parallel if found"
  332. "\n (see BLAS_SEQ_LIBRARIES and BLAS_PAR_LIBRARIES)")
  333. message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES")
  334. endif()
  335. find_package_handle_standard_args(BLASEXT DEFAULT_MSG
  336. BLAS_SEQ_LIBRARIES
  337. BLAS_LIBRARY_DIRS)
  338. if(BLAS_PAR_LIBRARIES)
  339. if(NOT BLASEXT_FIND_QUIETLY)
  340. message(STATUS "BLAS parallel libraries stored in BLAS_PAR_LIBRARIES")
  341. endif()
  342. find_package_handle_standard_args(BLASEXT DEFAULT_MSG
  343. BLAS_PAR_LIBRARIES)
  344. endif()
  345. else()
  346. if(NOT BLASEXT_FIND_QUIETLY)
  347. message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES")
  348. endif()
  349. find_package_handle_standard_args(BLASEXT DEFAULT_MSG
  350. BLAS_SEQ_LIBRARIES
  351. BLAS_LIBRARY_DIRS)
  352. endif()
  353. # Callers expect BLAS_FOUND to be set as well.
  354. set(BLAS_FOUND BLASEXT_FOUND)