FindBLASEXT.cmake 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. macro(find_package_blas)
  43. if(BLASEXT_FIND_REQUIRED)
  44. if(BLASEXT_FIND_QUIETLY)
  45. find_package(BLAS REQUIRED QUIET)
  46. else()
  47. find_package(BLAS REQUIRED)
  48. endif()
  49. else()
  50. if(BLASEXT_FIND_QUIETLY)
  51. find_package(BLAS QUIET)
  52. else()
  53. find_package(BLAS)
  54. endif()
  55. endif()
  56. endmacro()
  57. # add a cache variable to let the user specify the BLAS vendor
  58. set(BLA_VENDOR "" CACHE STRING "list of possible BLAS vendor:
  59. Open, Eigen, Goto, ATLAS PhiPACK, CXML, DXML, SunPerf, SCSL, SGIMATH, IBMESSL, IBMESSLMT,
  60. Intel10_32 (intel mkl v10 32 bit),
  61. Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model),
  62. Intel10_64lp_seq (intel mkl v10 64 bit, sequential code, lp64 model),
  63. Intel( older versions of mkl 32 and 64 bit),
  64. ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic")
  65. if(NOT BLASEXT_FIND_QUIETLY)
  66. message(STATUS "In FindBLASEXT")
  67. message(STATUS "If you want to force the use of one specific library, "
  68. "\n please specify the BLAS vendor by setting -DBLA_VENDOR=blas_vendor_name"
  69. "\n at cmake configure.")
  70. message(STATUS "List of possible BLAS vendor: Goto, ATLAS PhiPACK, CXML, "
  71. "\n DXML, SunPerf, SCSL, SGIMATH, IBMESSL, IBMESSLMT, Intel10_32 (intel mkl v10 32 bit),"
  72. "\n Intel10_64lp (intel mkl v10 64 bit, lp thread model, lp64 model),"
  73. "\n Intel10_64lp_seq (intel mkl v10 64 bit, sequential code, lp64 model),"
  74. "\n Intel( older versions of mkl 32 and 64 bit),"
  75. "\n ACML, ACML_MP, ACML_GPU, Apple, NAS, Generic")
  76. endif()
  77. if (NOT BLAS_FOUND)
  78. # First try to detect two cases:
  79. # 1: only SEQ libs are handled
  80. # 2: both SEQ and PAR libs are handled
  81. find_package_blas()
  82. endif ()
  83. # detect the cases where SEQ and PAR libs are handled
  84. if(BLA_VENDOR STREQUAL "All" AND
  85. (BLAS_mkl_core_LIBRARY OR BLAS_mkl_core_dll_LIBRARY)
  86. )
  87. set(BLA_VENDOR "Intel")
  88. if(BLAS_mkl_intel_LIBRARY)
  89. set(BLA_VENDOR "Intel10_32")
  90. endif()
  91. if(BLAS_mkl_intel_lp64_LIBRARY)
  92. set(BLA_VENDOR "Intel10_64lp")
  93. endif()
  94. if(NOT BLASEXT_FIND_QUIETLY)
  95. message(STATUS "A BLAS library has been found (${BLAS_LIBRARIES}) but we"
  96. "\n have also potentially detected some multithreaded BLAS libraries from the MKL."
  97. "\n We try to find both libraries lists (Sequential/Multithreaded).")
  98. endif()
  99. set(BLAS_FOUND "")
  100. elseif(BLA_VENDOR STREQUAL "All" AND BLAS_acml_LIBRARY)
  101. set(BLA_VENDOR "ACML")
  102. if(NOT BLASEXT_FIND_QUIETLY)
  103. message(STATUS "A BLAS library has been found (${BLAS_LIBRARIES}) but we"
  104. "\n have also potentially detected some multithreaded BLAS libraries from the ACML."
  105. "\n We try to find both libraries lists (Sequential/Multithreaded).")
  106. endif()
  107. set(BLAS_FOUND "")
  108. elseif(BLA_VENDOR STREQUAL "All" AND BLAS_essl_LIBRARY)
  109. set(BLA_VENDOR "IBMESSL")
  110. if(NOT BLASEXT_FIND_QUIETLY)
  111. message(STATUS "A BLAS library has been found (${BLAS_LIBRARIES}) but we"
  112. "\n have also potentially detected some multithreaded BLAS libraries from the ESSL."
  113. "\n We try to find both libraries lists (Sequential/Multithreaded).")
  114. endif()
  115. set(BLAS_FOUND "")
  116. endif()
  117. # Intel case
  118. if(BLA_VENDOR MATCHES "Intel*")
  119. ###
  120. # look for include path if the BLAS vendor is Intel
  121. ###
  122. # gather system include paths
  123. unset(_inc_env)
  124. if(WIN32)
  125. string(REPLACE ":" ";" _inc_env "$ENV{INCLUDE}")
  126. else()
  127. string(REPLACE ":" ";" _path_env "$ENV{INCLUDE}")
  128. list(APPEND _inc_env "${_path_env}")
  129. string(REPLACE ":" ";" _path_env "$ENV{C_INCLUDE_PATH}")
  130. list(APPEND _inc_env "${_path_env}")
  131. string(REPLACE ":" ";" _path_env "$ENV{CPATH}")
  132. list(APPEND _inc_env "${_path_env}")
  133. string(REPLACE ":" ";" _path_env "$ENV{INCLUDE_PATH}")
  134. list(APPEND _inc_env "${_path_env}")
  135. endif()
  136. list(APPEND _inc_env "${CMAKE_PLATFORM_IMPLICIT_INCLUDE_DIRECTORIES}")
  137. list(APPEND _inc_env "${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}")
  138. set(ENV_MKLROOT "$ENV{MKLROOT}")
  139. if (ENV_MKLROOT)
  140. list(APPEND _inc_env "${ENV_MKLROOT}/include")
  141. endif()
  142. list(REMOVE_DUPLICATES _inc_env)
  143. # find mkl.h inside known include paths
  144. set(BLAS_mkl.h_INCLUDE_DIRS "BLAS_mkl.h_INCLUDE_DIRS-NOTFOUND")
  145. if(BLAS_INCDIR)
  146. set(BLAS_mkl.h_INCLUDE_DIRS "BLAS_mkl.h_INCLUDE_DIRS-NOTFOUND")
  147. find_path(BLAS_mkl.h_INCLUDE_DIRS
  148. NAMES mkl.h
  149. HINTS ${BLAS_INCDIR})
  150. else()
  151. if(BLAS_DIR)
  152. set(BLAS_mkl.h_INCLUDE_DIRS "BLAS_mkl.h_INCLUDE_DIRS-NOTFOUND")
  153. find_path(BLAS_mkl.h_INCLUDE_DIRS
  154. NAMES mkl.h
  155. HINTS ${BLAS_DIR}
  156. PATH_SUFFIXES include)
  157. else()
  158. set(BLAS_mkl.h_INCLUDE_DIRS "BLAS_mkl.h_INCLUDE_DIRS-NOTFOUND")
  159. find_path(BLAS_mkl.h_INCLUDE_DIRS
  160. NAMES mkl.h
  161. HINTS ${_inc_env})
  162. endif()
  163. endif()
  164. mark_as_advanced(BLAS_mkl.h_INCLUDE_DIRS)
  165. ## Print status if not found
  166. ## -------------------------
  167. #if (NOT BLAS_mkl.h_INCLUDE_DIRS AND MORSE_VERBOSE)
  168. # Print_Find_Header_Status(blas mkl.h)
  169. #endif ()
  170. set(BLAS_INCLUDE_DIRS "")
  171. if(BLAS_mkl.h_INCLUDE_DIRS)
  172. list(APPEND BLAS_INCLUDE_DIRS "${BLAS_mkl.h_INCLUDE_DIRS}" )
  173. endif()
  174. ###
  175. # look for libs
  176. ###
  177. # if Intel 10 64 bit -> look for sequential and multithreaded versions
  178. if(BLA_VENDOR MATCHES "Intel10_64lp*")
  179. ## look for the sequential version
  180. set(BLA_VENDOR "Intel10_64lp_seq")
  181. if(NOT BLASEXT_FIND_QUIETLY)
  182. message(STATUS "Look for the sequential version Intel10_64lp_seq")
  183. endif()
  184. find_package_blas()
  185. if(BLAS_FOUND)
  186. set(BLAS_SEQ_LIBRARIES "${BLAS_LIBRARIES}")
  187. else()
  188. set(BLAS_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES-NOTFOUND}")
  189. endif()
  190. ## look for the multithreaded version
  191. set(BLA_VENDOR "Intel10_64lp")
  192. if(NOT BLASEXT_FIND_QUIETLY)
  193. message(STATUS "Look for the multithreaded version Intel10_64lp")
  194. endif()
  195. find_package_blas()
  196. if(BLAS_FOUND)
  197. set(BLAS_PAR_LIBRARIES "${BLAS_LIBRARIES}")
  198. else()
  199. set(BLAS_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES-NOTFOUND}")
  200. endif()
  201. else()
  202. if(BLAS_FOUND)
  203. set(BLAS_SEQ_LIBRARIES "${BLAS_LIBRARIES}")
  204. else()
  205. set(BLAS_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES-NOTFOUND}")
  206. endif()
  207. endif()
  208. # ACML case
  209. elseif(BLA_VENDOR MATCHES "ACML*")
  210. ## look for the sequential version
  211. set(BLA_VENDOR "ACML")
  212. find_package_blas()
  213. if(BLAS_FOUND)
  214. set(BLAS_SEQ_LIBRARIES "${BLAS_LIBRARIES}")
  215. else()
  216. set(BLAS_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES-NOTFOUND}")
  217. endif()
  218. ## look for the multithreaded version
  219. set(BLA_VENDOR "ACML_MP")
  220. find_package_blas()
  221. if(BLAS_FOUND)
  222. set(BLAS_PAR_LIBRARIES "${BLAS_LIBRARIES}")
  223. else()
  224. set(BLAS_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES-NOTFOUND}")
  225. endif()
  226. # IBMESSL case
  227. elseif(BLA_VENDOR MATCHES "IBMESSL*")
  228. ## look for the sequential version
  229. set(BLA_VENDOR "IBMESSL")
  230. find_package_blas()
  231. if(BLAS_FOUND)
  232. set(BLAS_SEQ_LIBRARIES "${BLAS_LIBRARIES}")
  233. else()
  234. set(BLAS_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES-NOTFOUND}")
  235. endif()
  236. ## look for the multithreaded version
  237. set(BLA_VENDOR "IBMESSLMT")
  238. find_package_blas()
  239. if(BLAS_FOUND)
  240. set(BLAS_PAR_LIBRARIES "${BLAS_LIBRARIES}")
  241. else()
  242. set(BLAS_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES-NOTFOUND}")
  243. endif()
  244. else()
  245. if(BLAS_FOUND)
  246. # define the SEQ libs as the BLAS_LIBRARIES
  247. set(BLAS_SEQ_LIBRARIES "${BLAS_LIBRARIES}")
  248. else()
  249. set(BLAS_SEQ_LIBRARIES "${BLAS_SEQ_LIBRARIES-NOTFOUND}")
  250. endif()
  251. set(BLAS_PAR_LIBRARIES "${BLAS_PAR_LIBRARIES-NOTFOUND}")
  252. endif()
  253. if(BLAS_SEQ_LIBRARIES)
  254. set(BLAS_LIBRARIES "${BLAS_SEQ_LIBRARIES}")
  255. endif()
  256. # extract libs paths
  257. # remark: because it is not given by find_package(BLAS)
  258. set(BLAS_LIBRARY_DIRS "")
  259. string(REPLACE " " ";" BLAS_LIBRARIES "${BLAS_LIBRARIES}")
  260. foreach(blas_lib ${BLAS_LIBRARIES})
  261. if (EXISTS "${blas_lib}")
  262. get_filename_component(a_blas_lib_dir "${blas_lib}" PATH)
  263. list(APPEND BLAS_LIBRARY_DIRS "${a_blas_lib_dir}" )
  264. else()
  265. string(REPLACE "-L" "" blas_lib "${blas_lib}")
  266. if (EXISTS "${blas_lib}")
  267. list(APPEND BLAS_LIBRARY_DIRS "${blas_lib}" )
  268. else()
  269. get_filename_component(a_blas_lib_dir "${blas_lib}" PATH)
  270. if (EXISTS "${a_blas_lib_dir}")
  271. list(APPEND BLAS_LIBRARY_DIRS "${a_blas_lib_dir}" )
  272. endif()
  273. endif()
  274. endif()
  275. endforeach()
  276. if (BLAS_LIBRARY_DIRS)
  277. list(REMOVE_DUPLICATES BLAS_LIBRARY_DIRS)
  278. endif ()
  279. # check that BLAS has been found
  280. # ---------------------------------
  281. include(FindPackageHandleStandardArgs)
  282. if(BLA_VENDOR MATCHES "Intel*")
  283. if(BLA_VENDOR MATCHES "Intel10_64lp*")
  284. if(NOT BLASEXT_FIND_QUIETLY)
  285. message(STATUS "BLAS found is Intel MKL:"
  286. "\n we manage two lists of libs, one sequential and one parallel if found"
  287. "\n (see BLAS_SEQ_LIBRARIES and BLAS_PAR_LIBRARIES)")
  288. message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES")
  289. endif()
  290. find_package_handle_standard_args(BLAS DEFAULT_MSG
  291. BLAS_SEQ_LIBRARIES
  292. BLAS_LIBRARY_DIRS
  293. BLAS_INCLUDE_DIRS)
  294. if(BLAS_PAR_LIBRARIES)
  295. if(NOT BLASEXT_FIND_QUIETLY)
  296. message(STATUS "BLAS parallel libraries stored in BLAS_PAR_LIBRARIES")
  297. endif()
  298. find_package_handle_standard_args(BLAS DEFAULT_MSG
  299. BLAS_PAR_LIBRARIES)
  300. endif()
  301. else()
  302. if(NOT BLASEXT_FIND_QUIETLY)
  303. message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES")
  304. endif()
  305. find_package_handle_standard_args(BLAS DEFAULT_MSG
  306. BLAS_SEQ_LIBRARIES
  307. BLAS_LIBRARY_DIRS
  308. BLAS_INCLUDE_DIRS)
  309. endif()
  310. elseif(BLA_VENDOR MATCHES "ACML*")
  311. if(NOT BLASEXT_FIND_QUIETLY)
  312. message(STATUS "BLAS found is ACML:"
  313. "\n we manage two lists of libs, one sequential and one parallel if found"
  314. "\n (see BLAS_SEQ_LIBRARIES and BLAS_PAR_LIBRARIES)")
  315. message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES")
  316. endif()
  317. find_package_handle_standard_args(BLAS DEFAULT_MSG
  318. BLAS_SEQ_LIBRARIES
  319. BLAS_LIBRARY_DIRS)
  320. if(BLAS_PAR_LIBRARIES)
  321. if(NOT BLASEXT_FIND_QUIETLY)
  322. message(STATUS "BLAS parallel libraries stored in BLAS_PAR_LIBRARIES")
  323. endif()
  324. find_package_handle_standard_args(BLAS DEFAULT_MSG
  325. BLAS_PAR_LIBRARIES)
  326. endif()
  327. elseif(BLA_VENDOR MATCHES "IBMESSL*")
  328. if(NOT BLASEXT_FIND_QUIETLY)
  329. message(STATUS "BLAS found is ESSL:"
  330. "\n we manage two lists of libs, one sequential and one parallel if found"
  331. "\n (see BLAS_SEQ_LIBRARIES and BLAS_PAR_LIBRARIES)")
  332. message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES")
  333. endif()
  334. find_package_handle_standard_args(BLAS DEFAULT_MSG
  335. BLAS_SEQ_LIBRARIES
  336. BLAS_LIBRARY_DIRS)
  337. if(BLAS_PAR_LIBRARIES)
  338. if(NOT BLASEXT_FIND_QUIETLY)
  339. message(STATUS "BLAS parallel libraries stored in BLAS_PAR_LIBRARIES")
  340. endif()
  341. find_package_handle_standard_args(BLAS DEFAULT_MSG
  342. BLAS_PAR_LIBRARIES)
  343. endif()
  344. else()
  345. if(NOT BLASEXT_FIND_QUIETLY)
  346. message(STATUS "BLAS sequential libraries stored in BLAS_SEQ_LIBRARIES")
  347. endif()
  348. find_package_handle_standard_args(BLAS DEFAULT_MSG
  349. BLAS_SEQ_LIBRARIES
  350. BLAS_LIBRARY_DIRS)
  351. endif()