Skip to content

Commit

Permalink
initial TPL implementation of CBLAS/LAPACKE
Browse files Browse the repository at this point in the history
  • Loading branch information
jjwilke committed Dec 20, 2019
1 parent 3f74cb6 commit a656bff
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 24 deletions.
15 changes: 15 additions & 0 deletions cmake/Modules/FindTPLCBLAS.cmake
Original file line number Diff line number Diff line change
@@ -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()
15 changes: 15 additions & 0 deletions cmake/Modules/FindTPLLAPACKE.cmake
Original file line number Diff line number Diff line change
@@ -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()
65 changes: 42 additions & 23 deletions cmake/kokkoskernels_tpls.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -130,38 +132,43 @@ 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()


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()

Expand All @@ -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})
Expand Down Expand Up @@ -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})
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmake/kokkoskernels_tribits.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a656bff

Please sign in to comment.