From a656bff88e2c7bccb93a61bce6f17e8df6904022 Mon Sep 17 00:00:00 2001 From: jjwilke Date: Thu, 19 Dec 2019 16:30:27 -0800 Subject: [PATCH] initial TPL implementation of CBLAS/LAPACKE --- cmake/Modules/FindTPLCBLAS.cmake | 15 +++++++ cmake/Modules/FindTPLLAPACKE.cmake | 15 +++++++ cmake/kokkoskernels_tpls.cmake | 65 +++++++++++++++++++----------- cmake/kokkoskernels_tribits.cmake | 2 +- 4 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 cmake/Modules/FindTPLCBLAS.cmake create mode 100644 cmake/Modules/FindTPLLAPACKE.cmake diff --git a/cmake/Modules/FindTPLCBLAS.cmake b/cmake/Modules/FindTPLCBLAS.cmake new file mode 100644 index 0000000000..b02ba8de65 --- /dev/null +++ b/cmake/Modules/FindTPLCBLAS.cmake @@ -0,0 +1,15 @@ +IF (DEFINED CBLAS_LIBRARIES) + #we were given the exact list of libraries to find + KOKKOSKERNELS_FIND_IMPORTED(CBLAS INTERFACE + LIBRARIES ${CBLAS_LIBRARIES} + LIBRARY_PATHS ${CBLAS_LIBRARY_DIRS} + HEADERS cblas.h + HEADER_PATHS ${CBLAS_INCLUDE_DIRS}) +ELSE() + #we need to find one of the valid versions from the list below + KOKKOSKERNELS_FIND_IMPORTED(CBLAS + LIBRARY cblas blas blis openblas + LIBRARY_PATHS ${CBLAS_LIBRARY_DIRS} + HEADERS cblas.h + HEADER_PATHS ${CBLAS_INCLUDE_DIRS}) +ENDIF() diff --git a/cmake/Modules/FindTPLLAPACKE.cmake b/cmake/Modules/FindTPLLAPACKE.cmake new file mode 100644 index 0000000000..a167a2a5cd --- /dev/null +++ b/cmake/Modules/FindTPLLAPACKE.cmake @@ -0,0 +1,15 @@ +IF (DEFINED LAPACKE_LIBRARIES) + #we were given the exact list of libraries to find + KOKKOSKERNELS_FIND_IMPORTED(LAPACKE INTERFACE + LIBRARIES ${LAPACKE_LIBRARIES} + LIBRARY_PATHS ${LAPACKE_LIBRARY_DIRS} + HEADERS lapacke.h + HEADER_PATHS ${LAPACKE_INCLUDE_DIRS}) +ELSE() + #we need to find one of the valid versions from the list below + KOKKOSKERNELS_FIND_IMPORTED(LAPACKE + LIBRARY lapacke openblas + LIBRARY_PATHS ${LAPACKE_LIBRARY_DIRS} + HEADERS lapacke.h + HEADER_PATHS ${LAPACKE_INCLUDE_DIRS}) +ENDIF() diff --git a/cmake/kokkoskernels_tpls.cmake b/cmake/kokkoskernels_tpls.cmake index 63345ec9d1..caf4a9854b 100644 --- a/cmake/kokkoskernels_tpls.cmake +++ b/cmake/kokkoskernels_tpls.cmake @@ -31,6 +31,8 @@ MACRO(kokkoskernels_create_imported_tpl NAME) SET(TPL_IMPORTED_NAME KokkosKernels::${NAME}) ENDIF() + SET(TPL_${NAME}_IMPORTED_NAME ${TPL_IMPORTED_NAME}) + IF (KOKKOSKERNELS_HAS_TRILINOS) #TODO: we need to set a bunch of cache variables here ELSEIF (TPL_INTERFACE) @@ -130,30 +132,35 @@ MACRO(kokkoskernels_find_header VAR_NAME HEADER TPL_NAME) ENDIF() ENDMACRO() -MACRO(kokkoskernels_find_library VAR_NAME LIB TPL_NAME) +MACRO(kokkoskernels_find_library VAR_NAME TPL_NAME) CMAKE_PARSE_ARGUMENTS(TPL "ALLOW_SYSTEM_PATH_FALLBACK" "" - "PATHS" + "PATHS;LIBRARY_NAMES" ${ARGN}) SET(${LIB}_FOUND FALSE) SET(HAVE_CUSTOM_PATHS FALSE) IF(NOT ${LIB}_FOUND AND DEFINED ${TPL_NAME}_ROOT) - FIND_LIBRARY(${VAR_NAME} ${LIB} PATHS ${${TPL_NAME}_ROOT}/lib ${${TPL_NAME}_ROOT}/lib64 NO_DEFAULT_PATH) + FIND_LIBRARY(${VAR_NAME} + NAMES ${TPL_LIBRARY_NAMES} + PATHS ${${TPL_NAME}_ROOT}/lib ${${TPL_NAME}_ROOT}/lib64 NO_DEFAULT_PATH) SET(HAVE_CUSTOM_PATHS TRUE) ENDIF() IF(NOT ${LIB}_FOUND AND DEFINED KOKKOSKERNELS_${TPL_NAME}_DIR) #we got root paths, only look in these paths and nowhere else - FIND_LIBRARY(${VAR_NAME} ${LIB} + FIND_LIBRARY(${VAR_NAME} + NAMES ${TPL_LIBRARY_NAMES} PATHS ${KOKKOSKERNELS_${TPL_NAME}_DIR}/lib ${KOKKOSKERNELS_${TPL_NAME}_DIR}/lib64 NO_DEFAULT_PATH) SET(HAVE_CUSTOM_PATHS TRUE) ENDIF() IF (NOT ${LIB}_FOUND AND TPL_PATHS) #we got custom paths, only look in these paths and nowhere else - FIND_LIBRARY(${VAR_NAME} ${LIB} PATHS ${TPL_PATHS} NO_DEFAULT_PATH) + FIND_LIBRARY(${VAR_NAME} + NAMES ${TPL_LIBRARY_NAMES} + PATHS ${TPL_PATHS} NO_DEFAULT_PATH) SET(HAVE_CUSTOM_PATHS TRUE) ENDIF() @@ -161,7 +168,7 @@ MACRO(kokkoskernels_find_library VAR_NAME LIB TPL_NAME) IF (NOT HAVE_CUSTOM_PATHS OR TPL_ALLOW_SYSTEM_PATH_FALLBACK) IF (NOT ${LIB}_FOUND) #Now go ahead and look in system paths - FIND_LIBRARY(${VAR_NAME} ${LIB}) + FIND_LIBRARY(${VAR_NAME} NAMES ${TPL_LIBRARY_NAMES}) ENDIF() ENDIF() @@ -170,9 +177,11 @@ ENDMACRO() MACRO(kokkoskernels_find_imported NAME) CMAKE_PARSE_ARGUMENTS(TPL "INTERFACE;ALLOW_SYSTEM_PATH_FALLBACK" - "HEADER;LIBRARY;IMPORTED_NAME" - "HEADERS;LIBRARIES;HEADER_PATHS;LIBRARY_PATHS" + "HEADER;IMPORTED_NAME" + "LIBRARY;HEADERS;LIBRARIES;HEADER_PATHS;LIBRARY_PATHS" ${ARGN}) + #LIBRARY can be a list of possible library names + #matching the NAMES keyword to CMake find_library IF(NOT TPL_MODULE_NAME) SET(TPL_MODULE_NAME TPL${NAME}) @@ -202,10 +211,13 @@ MACRO(kokkoskernels_find_imported NAME) SET(${NAME}_LIBRARY) IF(TPL_LIBRARY) - KOKKOSKERNELS_FIND_LIBRARY(${NAME}_LIBRARY ${TPL_LIBRARY} ${NAME} ${ALLOW_PATH_FALLBACK_OPT} PATHS ${TPL_LIBRARY_PATHS}) + KOKKOSKERNELS_FIND_LIBRARY(${NAME}_LIBRARY ${NAME} ${ALLOW_PATH_FALLBACK_OPT} + LIBRARY_NAMES ${TPL_LIBRARY} + PATHS ${TPL_LIBRARY_PATHS}) ENDIF() SET(${NAME}_FOUND_LIBRARIES) + #We must find every library in this list FOREACH(LIB ${TPL_LIBRARIES}) #we want the actual name, not the name -lblas, etc SET(LIB_CLEAN ${LIB}) @@ -214,7 +226,9 @@ MACRO(kokkoskernels_find_imported NAME) STRING(SUBSTRING ${LIB} 2 -1 LIB_CLEAN) ENDIF() - KOKKOSKERNELS_FIND_LIBRARY(${LIB}_LOCATION ${LIB_CLEAN} ${NAME} ${ALLOW_PATH_FALLBACK_OPT} PATHS ${TPL_LIBRARY_PATHS}) + KOKKOSKERNELS_FIND_LIBRARY(${LIB}_LOCATION ${NAME} ${ALLOW_PATH_FALLBACK_OPT} + LIBRARY_NAMES ${LIB_CLEAN} + PATHS ${TPL_LIBRARY_PATHS}) IF(${LIB}_LOCATION) LIST(APPEND ${NAME}_FOUND_LIBRARIES ${${LIB}_LOCATION}) ELSE() @@ -248,6 +262,8 @@ MACRO(kokkoskernels_find_imported NAME) LIBRARY "${${NAME}_LIBRARY}" LINK_LIBRARIES "${${NAME}_FOUND_LIBRARIES}") ENDIF() + #This is a macro, clear variables we don't to escape + SET(TPL_MODULE_NAME) ENDMACRO() MACRO(kokkoskernels_export_imported_tpl NAME) @@ -312,15 +328,10 @@ ENDMACRO() MACRO(kokkoskernels_import_tpl NAME) CMAKE_PARSE_ARGUMENTS(TPL - "NO_EXPORT;INTERFACE" + "NO_EXPORT" "" "" ${ARGN}) - IF (TPL_INTERFACE) - SET(TPL_IMPORTED_NAME ${NAME}) - ELSE() - SET(TPL_IMPORTED_NAME KokkosKernels::${NAME}) - ENDIF() # Even though this policy gets set in the top-level CMakeLists.txt, # I have still been getting errors about ROOT variables being ignored @@ -333,11 +344,15 @@ MACRO(kokkoskernels_import_tpl NAME) IF (KOKKOSKERNELS_ENABLE_TPL_${NAME}) #Tack on a TPL here to make sure we avoid using anyone else's find FIND_PACKAGE(TPL${NAME} REQUIRED MODULE) - IF(NOT TARGET ${TPL_IMPORTED_NAME}) - MESSAGE(FATAL_ERROR "Find module succeeded for ${NAME}, but did not produce valid target ${TPL_IMPORTED_NAME}") + IF (NOT TPL_${NAME}_IMPORTED_NAME) + MESSAGE(FATAL_ERROR "Find module did not produce valid IMPORTED_NAME for ${NAME}") + ENDIF() + + IF(NOT TARGET ${TPL_${NAME}_IMPORTED_NAME}) + MESSAGE(FATAL_ERROR "Find module succeeded for ${NAME}, but did not produce valid target ${TPL_${NAME}_IMPORTED_NAME}") ENDIF() IF(NOT TPL_NO_EXPORT) - KOKKOSKERNELS_EXPORT_IMPORTED_TPL(${NAME} IMPORTED_NAME ${TPL_IMPORTED_NAME}) + KOKKOSKERNELS_EXPORT_IMPORTED_TPL(${NAME} IMPORTED_NAME ${TPL_${NAME}_IMPORTED_NAME}) ENDIF() ENDIF() ENDMACRO(kokkoskernels_import_tpl) @@ -385,6 +400,8 @@ KOKKOSKERNELS_ADD_TPL_OPTION(BLAS OFF "Whether to enable BLAS") KOKKOSKERNELS_ADD_TPL_OPTION(LAPACK ${KokkosKernels_ENABLE_TPL_BLAS} "Whether to enable LAPACK") KOKKOSKERNELS_ADD_TPL_OPTION(MKL OFF "Whether to enable MKL") KOKKOSKERNELS_ADD_TPL_OPTION(MAGMA OFF "Whether to enable MAGMA") +KOKKOSKERNELS_ADD_TPL_OPTION(CBLAS OFF "Whether to enable CBLAS") +KOKKOSKERNELS_ADD_TPL_OPTION(LAPACKE OFF "Whether to enable LAPACKE") IF (KOKKOSKERNELS_ENABLE_TPL_BLAS OR KOKKOSKERNELS_ENABLE_TPL_MKL OR KOKKOSKERNELS_ENABLE_TPL_MAGMA) ENABLE_LANGUAGE(C) @@ -422,11 +439,13 @@ ENDIF() # We need to do all the import work IF (NOT KOKKOSKERNELS_HAS_TRILINOS) - KOKKOSKERNELS_IMPORT_TPL(BLAS INTERFACE) - KOKKOSKERNELS_IMPORT_TPL(LAPACK INTERFACE) - KOKKOSKERNELS_IMPORT_TPL(MKL INTERFACE) - KOKKOSKERNELS_IMPORT_TPL(CUBLAS INTERFACE) + KOKKOSKERNELS_IMPORT_TPL(BLAS) + KOKKOSKERNELS_IMPORT_TPL(LAPACK) + KOKKOSKERNELS_IMPORT_TPL(MKL) + KOKKOSKERNELS_IMPORT_TPL(CUBLAS) KOKKOSKERNELS_IMPORT_TPL(CUSPARSE) + KOKKOSKERNELS_IMPORT_TPL(CBLAS) + KOKKOSKERNELS_IMPORT_TPL(LAPACKE) ENDIF() #Convert list to newlines (which CMake doesn't always like in cache variables) diff --git a/cmake/kokkoskernels_tribits.cmake b/cmake/kokkoskernels_tribits.cmake index ab8de3748b..7eaad67eb6 100644 --- a/cmake/kokkoskernels_tribits.cmake +++ b/cmake/kokkoskernels_tribits.cmake @@ -5,7 +5,7 @@ IF (KOKKOSKERNELS_HAS_TRILINOS) INCLUDE(TribitsETISupport) ENDIF() -MESSAGE(STATUS "The project name is: ${PROJECT_NAME}") +#MESSAGE(STATUS "The project name is: ${PROJECT_NAME}") MACRO(KOKKOSKERNELS_PACKAGE_POSTPROCESS) IF (KOKKOSKERNELS_HAS_TRILINOS)