From 95ceb0a09f105e54e442e3b40572a0f4616b2d10 Mon Sep 17 00:00:00 2001 From: jjwilke Date: Tue, 17 Dec 2019 15:51:08 -0800 Subject: [PATCH] Initial support for SuperLU TPL: Issue #545 --- cmake/Dependencies.cmake | 2 +- cmake/KokkosKernels_config.h.in | 2 ++ cmake/Modules/FindTPLSUPERLU.cmake | 36 ++++++++++++++++++++++++++++ cmake/Modules/superlu_test.cc | 17 +++++++++++++ cmake/compile_tests/superlu_test.cpp | 18 ++++++++++++++ cmake/kokkoskernels_tpls.cmake | 3 +++ 6 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 cmake/Modules/FindTPLSUPERLU.cmake create mode 100644 cmake/Modules/superlu_test.cc create mode 100644 cmake/compile_tests/superlu_test.cpp diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 7eef4784a0..b901a6e7b5 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -1,5 +1,5 @@ TRIBITS_PACKAGE_DEFINE_DEPENDENCIES( LIB_REQUIRED_PACKAGES KokkosCore KokkosContainers KokkosAlgorithms - LIB_OPTIONAL_TPLS quadmath MKL BLAS LAPACK CUSPARSE MAGMA + LIB_OPTIONAL_TPLS quadmath MKL BLAS LAPACK CUSPARSE MAGMA SuperLU TEST_OPTIONAL_TPLS yaml-cpp ) diff --git a/cmake/KokkosKernels_config.h.in b/cmake/KokkosKernels_config.h.in index a5e5b37a3e..22ff27bdd3 100644 --- a/cmake/KokkosKernels_config.h.in +++ b/cmake/KokkosKernels_config.h.in @@ -89,6 +89,8 @@ #cmakedefine KOKKOSKERNELS_ENABLE_TPL_CUBLAS /* MAGMA */ #cmakedefine KOKKOSKERNELS_ENABLE_TPL_MAGMA +/* SUPERLU */ +#cmakedefine KOKKOSKERNELS_ENABLE_TPL_SUPERLU /* if MKL, BLAS is also defined */ #if defined(KOKKOSKERNELS_ENABLE_TPL_MKL) diff --git a/cmake/Modules/FindTPLSUPERLU.cmake b/cmake/Modules/FindTPLSUPERLU.cmake new file mode 100644 index 0000000000..32d8ed2993 --- /dev/null +++ b/cmake/Modules/FindTPLSUPERLU.cmake @@ -0,0 +1,36 @@ +#This assume SuperLU >= 5.0. We don't worry about older versions. +KOKKOSKERNELS_FIND_IMPORTED(SUPERLU LIBRARY superlu HEADER supermatrix.h) +SET(SUPERLU_LIBS KokkosKernels::SUPERLU) +IF (TARGET KokkosKernels::BLAS) #This is an interface library + #I don't like doing this since it breaks the abstraction of + #a target is just a thing we link to. CMake doesn't allow + #us to pass in interface targets to try_compile + GET_TARGET_PROPERTY(SUPERLU_BLAS_LIBS KokkosKernels::BLAS INTERFACE_LINK_LIBRARIES) + LIST(APPEND SUPERLU_LIBS ${SUPERLU_BLAS_LIBS}) +ENDIF() +IF (TARGET KokkosKernels::LAPACK) + #I don't like doing this since it breaks the abstraction of + #a target is just a thing we link to try_compile + GET_TARGET_PROPERTY(SUPERLU_LAPACK_LIBS KokkosKernels::LAPACK INTERFACE_LINK_LIBRARIES) + LIST(APPEND SUPERLU_LIBS ${SUPERLU_LAPACK_LIBS}) +ENDIF() + +TRY_COMPILE(SUPERLU_COMPILE_SUCCEEDS) + ${KOKKOSKERNELS_TOP_BUILD_DIR}/tpl_tests + ${KOKKOSKERNELS_TOP_SOURCE_DIR}/cmake/compile_tests/superlu_test.cpp + LINK_LIBRARIES ${SUPERLU_LIBS} +) + +IF (NOT SUPERLU_COMPILE_SUCCEEDS) + MESSAGE(WARNING "SuperLU failed to correctly compile test." + " The most likely failure is missing or incorrect BLAS libraries" + " Please ensure that KokkosKernels is built with same BLAS as SuperLU") + IF (TARGET KokkosKernels::BLAS) + MESSAGE(WARNING "KokkosKernels is using BLAS: ${SUPERLU_BLAS_LIBS}") + ENDIF() + IF (TARGET KokkosKernels::LAPACK) + MESSAGE(WARNING "KokkosKernels is using LAPACK: ${SUPERLU_LAPACK_LIBS}") + ENDIF() + INCLUDE(FindPackageHandleStandardArgs) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(TPLSUPERLU DEFAULT_MSG SUPERLU_CORRECT) +ENDIF() diff --git a/cmake/Modules/superlu_test.cc b/cmake/Modules/superlu_test.cc new file mode 100644 index 0000000000..a3ef4d0ae3 --- /dev/null +++ b/cmake/Modules/superlu_test.cc @@ -0,0 +1,17 @@ +#include + +int main() +{ + GlobalLU_t lu; + superlu_options_t opt; + SuperMatrix M; + int *i; + double *d; + void *v; + char *c; + SuperLUStat_t stat; + mem_usage_t mem; + + dgsisx(&opt,&M,i,i,i,c,d,d,&M,&M,v,*i,&M,&M,d,d,&lu,&mem,&stat,i); + return 0; +} diff --git a/cmake/compile_tests/superlu_test.cpp b/cmake/compile_tests/superlu_test.cpp new file mode 100644 index 0000000000..a838298492 --- /dev/null +++ b/cmake/compile_tests/superlu_test.cpp @@ -0,0 +1,18 @@ +#include + +int main() +{ + GlobalLU_t lu; + superlu_options_t opt; + SuperMatrix M; + int *i; + double *d; + void *v; + char *c; + SuperLUStat_t stat; + mem_usage_t mem; + + dgsisx(&opt,&M,i,i,i,c,d,d,&M,&M,v,*i,&M,&M,d,d,&lu,&mem,&stat,i); + return 0; +} + diff --git a/cmake/kokkoskernels_tpls.cmake b/cmake/kokkoskernels_tpls.cmake index 63345ec9d1..292a88c611 100644 --- a/cmake/kokkoskernels_tpls.cmake +++ b/cmake/kokkoskernels_tpls.cmake @@ -403,6 +403,8 @@ ENDIF() KOKKOSKERNELS_ADD_TPL_OPTION(CUBLAS ${CUBLAS_DEFAULT} "Whether to enable CUBLAS") KOKKOSKERNELS_ADD_TPL_OPTION(CUSPARSE ${CUSPARSE_DEFAULT} "Whether to enable CUSPARSE") +KOKKOSKERNELS_ADD_TPL_OPTION(SUPERLU OFF "Whether to enable SuperLU") + IF (KOKKOSKERNELS_ENABLE_TPL_MAGMA) IF (KOKKOSKERNELS_HAS_TRILINOS) IF (F77_BLAS_MANGLE STREQUAL "(name,NAME) name ## _") @@ -427,6 +429,7 @@ IF (NOT KOKKOSKERNELS_HAS_TRILINOS) KOKKOSKERNELS_IMPORT_TPL(MKL INTERFACE) KOKKOSKERNELS_IMPORT_TPL(CUBLAS INTERFACE) KOKKOSKERNELS_IMPORT_TPL(CUSPARSE) + KOKKOSKERNELS_IMPORT_TPL(SUPERLU) ENDIF() #Convert list to newlines (which CMake doesn't always like in cache variables)