From 1d79d7383e3d2c81842e220401104c891bad39d6 Mon Sep 17 00:00:00 2001 From: Tim Davis Date: Fri, 22 Dec 2023 05:52:51 -0600 Subject: [PATCH] SUITESPARSE_USE_STRICT --- CMakeLists.txt | 37 +++++++++++--- GraphBLAS/CMakeLists.txt | 37 ++++++++++---- GraphBLAS/Makefile | 4 +- Makefile | 4 +- cmake_modules/SuiteSparsePolicy.cmake | 69 ++++++++++++++++++++------- cmake_modules/SuiteSparseReport.cmake | 2 +- 6 files changed, 113 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ccdc75bc1..1111881158 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,10 @@ if ( NOT GRAPHBLAS_BUILD_STATIC_LIBS AND BUILD_SHARED_LIBS ) set ( BUILD_STATIC_LIBS OFF ) endif ( ) +#------------------------------------------------------------------------------- +# find CUDA +#------------------------------------------------------------------------------- + if ( SUITESPARSE_HAS_CUDA AND GRAPHBLAS_USE_CUDA ) # FOR NOW: do not compile FactoryKernels when developing the CUDA kernels set ( GRAPHBLAS_COMPACT ON ) @@ -63,13 +67,14 @@ else ( ) set ( GRAPHBLAS_HAS_CUDA OFF ) endif ( ) -include ( GraphBLAS_JIT_paths ) +# check for strict usage +if ( SUITESPARSE_USE_STRICT AND GRAPHBLAS_USE_CUDA AND NOT GRAPHBLAS_HAS_CUDA ) + message ( FATAL_ERROR "CUDA required for GraphBLAS but not found" ) +endif ( ) -#------------------------------------------------------------------------------- -# find OpenMP, CUDA, RMM, and cpu_features -#------------------------------------------------------------------------------- +include ( GraphBLAS_JIT_paths ) -if ( SUITESPARSE_HAS_CUDA AND GRAPHBLAS_USE_CUDA ) +if ( GRAPHBLAS_HAS_CUDA ) # with CUDA and RMM add_subdirectory ( CUDA ) set ( GB_CUDA GraphBLAS_CUDA ${CUDA_LIBRARIES} ) @@ -86,6 +91,9 @@ else ( ) set ( GB_RMM ) endif ( ) +#------------------------------------------------------------------------------- +# find OpenMP +#------------------------------------------------------------------------------- option ( SUITESPARSE_USE_OPENMP "ON (default): Use OpenMP if available. OFF: Do not use OpenMP" ON ) option ( GRAPHBLAS_USE_OPENMP "ON: Use OpenMP in GraphBLAS if available. OFF: Do not use OpenMP. (Default: SUITESPARSE_USE_OPENMP)" ${SUITESPARSE_USE_OPENMP} ) @@ -96,6 +104,21 @@ else ( ) set ( OpenMP_C_FOUND OFF ) endif ( ) +if ( OpenMP_C_FOUND ) + set ( GRAPHBLAS_HAS_OPENMP ON ) +else ( ) + set ( GRAPHBLAS_HAS_OPENMP OFF ) +endif ( ) + +# check for strict usage +if ( SUITESPARSE_USE_STRICT AND GRAPHBLAS_USE_OPENMP AND NOT GRAPHBLAS_HAS_OPENMP ) + message ( FATAL_ERROR "OpenMP required for GraphBLAS but not found" ) +endif ( ) + +#------------------------------------------------------------------------------- +# find cpu_features +#------------------------------------------------------------------------------- + if ( NOT GBNCPUFEAT ) # default: enable Google's cpu_features package message ( STATUS "cpu_features (by google.com): enabled " ) @@ -417,7 +440,7 @@ if ( NOT GB_CMAKE_LIBRARIES ) set ( GB_CMAKE_LIBRARIES "" ) endif ( ) -if ( OpenMP_C_FOUND ) +if ( GRAPHBLAS_HAS_OPENMP ) message ( STATUS "CMAKE OpenMP libraries: ${OpenMP_C_LIBRARIES}" ) message ( STATUS "CMAKE OpenMP include: ${OpenMP_C_INCLUDE_DIRS}" ) list ( APPEND GB_CMAKE_LIBRARIES ${OpenMP_C_LIBRARIES} ) @@ -529,7 +552,7 @@ if ( SUITESPARSE_DEMOS ) target_link_libraries ( context_demo PUBLIC ${GB_M} ${GB_CUDA} ${GB_RMM} ) target_link_libraries ( gauss_demo PUBLIC ${GB_M} ${GB_CUDA} ${GB_RMM} ) - if ( OpenMP_C_FOUND ) + if ( GRAPHBLAS_HAS_OPENMP ) target_link_libraries ( openmp_demo PUBLIC OpenMP::OpenMP_C ) target_link_libraries ( openmp2_demo PUBLIC OpenMP::OpenMP_C ) target_link_libraries ( reduce_demo PUBLIC OpenMP::OpenMP_C ) diff --git a/GraphBLAS/CMakeLists.txt b/GraphBLAS/CMakeLists.txt index 7ed719ed07..ae401f10c4 100644 --- a/GraphBLAS/CMakeLists.txt +++ b/GraphBLAS/CMakeLists.txt @@ -33,8 +33,18 @@ set ( GBMATLAB on ) set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DGBMATLAB=1 " ) include ( SuiteSparsePolicy ) + +#------------------------------------------------------------------------------- +# find CUDA +#------------------------------------------------------------------------------- + include ( GraphBLAS_JIT_paths ) +# check for strict usage +if ( SUITESPARSE_USE_STRICT AND GRAPHBLAS_USE_CUDA AND NOT GRAPHBLAS_HAS_CUDA ) + message ( FATAL_ERROR "CUDA required for GraphBLAS but not found" ) +endif ( ) + #------------------------------------------------------------------------------- # define the project #------------------------------------------------------------------------------- @@ -43,7 +53,7 @@ project ( graphblas_matlab VERSION "${GraphBLAS_VERSION_MAJOR}.${GraphBLAS_VERSION_MINOR}.${GraphBLAS_VERSION_SUB}" LANGUAGES C ) #------------------------------------------------------------------------------- -# find OpenMP and cpu_features +# find OpenMP #------------------------------------------------------------------------------- option ( SUITESPARSE_USE_OPENMP "ON (default): Use OpenMP if available. OFF: Do not use OpenMP" ON ) @@ -55,6 +65,21 @@ else ( ) set ( OpenMP_C_FOUND OFF ) endif ( ) +if ( OpenMP_C_FOUND ) + set ( GRAPHBLAS_HAS_OPENMP ON ) +else ( ) + set ( GRAPHBLAS_HAS_OPENMP OFF ) +endif ( ) + +# check for strict usage +if ( SUITESPARSE_USE_STRICT AND GRAPHBLAS_USE_OPENMP AND NOT GRAPHBLAS_HAS_OPENMP ) + message ( FATAL_ERROR "OpenMP required for GraphBLAS but not found" ) +endif ( ) + +#------------------------------------------------------------------------------- +# find cpu_features +#------------------------------------------------------------------------------- + if ( NOT GBNCPUFEAT ) # default: enable Google's cpu_features package message ( STATUS "cpu_features (by google.com): enabled " ) @@ -167,14 +192,6 @@ set_target_properties ( graphblas_matlab PROPERTIES C_STANDARD_REQUIRED ON PUBLIC_HEADER "../Include/GraphBLAS.h" ) -#------------------------------------------------------------------------------- -# select the threading library -#------------------------------------------------------------------------------- - -if ( OpenMP_C_FOUND ) - set ( USE_OPENMP true ) -endif ( ) - #------------------------------------------------------------------------------- # select the math library (not required for Microsoft Visual Studio) #------------------------------------------------------------------------------- @@ -198,7 +215,7 @@ endif ( ) # add library dependencies #------------------------------------------------------------------------------- -if ( USE_OPENMP ) +if ( GRAPHBLAS_HAS_OPENMP ) message ( STATUS "CMAKE OpenMP libraries: " ${OpenMP_C_LIBRARIES} ) message ( STATUS "CMAKE OpenMP include: " ${OpenMP_C_INCLUDE_DIRS} ) target_link_libraries ( graphblas_matlab PUBLIC ${OpenMP_C_LIBRARIES} ) diff --git a/GraphBLAS/Makefile b/GraphBLAS/Makefile index ca45f0eff1..165da86343 100644 --- a/GraphBLAS/Makefile +++ b/GraphBLAS/Makefile @@ -20,11 +20,11 @@ library: # install only in SuiteSparse/lib and SuiteSparse/include local: - ( cd build && cmake $(CMAKE_OPTIONS) -USUITESPARSE_PKGFILEDIR -DLOCAL_INSTALL=1 .. && cmake --build . --config Release -j${JOBS} ) + ( cd build && cmake $(CMAKE_OPTIONS) -USUITESPARSE_PKGFILEDIR -DSUITESPARSE_LOCAL_INSTALL=1 .. && cmake --build . --config Release -j${JOBS} ) # install only in /usr/local (default) global: - ( cd build && cmake $(CMAKE_OPTIONS) -USUITESPARSE_PKGFILEDIR -DLOCAL_INSTALL=0 .. && cmake --build . --config Release -j${JOBS} ) + ( cd build && cmake $(CMAKE_OPTIONS) -USUITESPARSE_PKGFILEDIR -DSUITESPARSE_LOCAL_INSTALL=0 .. && cmake --build . --config Release -j${JOBS} ) # compile with -g debug: diff --git a/Makefile b/Makefile index 4c4fe879e0..ff91ca7266 100644 --- a/Makefile +++ b/Makefile @@ -32,11 +32,11 @@ library: # install only in SuiteSparse/lib and SuiteSparse/include local: - ( cd build && cmake $(CMAKE_OPTIONS) -USUITESPARSE_PKGFILEDIR -DLOCAL_INSTALL=1 .. && cmake --build . --config Release -j${JOBS} ) + ( cd build && cmake $(CMAKE_OPTIONS) -USUITESPARSE_PKGFILEDIR -DSUITESPARSE_LOCAL_INSTALL=1 .. && cmake --build . --config Release -j${JOBS} ) # install only in /usr/local (default) global: - ( cd build && cmake $(CMAKE_OPTIONS) -USUITESPARSE_PKGFILEDIR -DLOCAL_INSTALL=0 .. && cmake --build . --config Release -j${JOBS} ) + ( cd build && cmake $(CMAKE_OPTIONS) -USUITESPARSE_PKGFILEDIR -DSUITESPARSE_LOCAL_INSTALL=0 .. && cmake --build . --config Release -j${JOBS} ) # enable CUDA (NOTE: not ready for production use) cuda: diff --git a/cmake_modules/SuiteSparsePolicy.cmake b/cmake_modules/SuiteSparsePolicy.cmake index 228a1bd0af..e5baa91f83 100644 --- a/cmake_modules/SuiteSparsePolicy.cmake +++ b/cmake_modules/SuiteSparsePolicy.cmake @@ -15,23 +15,23 @@ # set ( CMAKE_BUILD_TYPE Debug ) # # SUITESPARSE_USE_CUDA: if OFF, CUDA is disabled. if ON, CUDA is enabled, -# if available. +# if available. Ignored for MSVC. # Default: ON. # -# LOCAL_INSTALL: if true, "cmake --install" will install +# SUITESPARSE_LOCAL_INSTALL: if true, "cmake --install" will install # into SuiteSparse/lib and SuiteSparse/include. # if false, "cmake --install" will install into the # default prefix (or the one configured with # CMAKE_INSTALL_PREFIX). Requires cmake 3.19. # This is ignored when using the root CMakeLists.txt. # Set CMAKE_INSTALL_PREFIX instead. -# Default: false +# Default: OFF # # BUILD_SHARED_LIBS: if true, shared libraries are built. -# Default: true. +# Default: ON. # # BUILD_STATIC_LIBS: if true, static libraries are built. -# Default: true, except for GraphBLAS, which +# Default: ON, except for GraphBLAS, which # takes a long time to compile so the default for # GraphBLAS is false. # @@ -49,10 +49,10 @@ # Both settings must appear, or neither. # Default: neither are defined. # -# BLA_STATIC: if true, use static linkage for BLAS and LAPACK. -# Default: false +# BLA_STATIC: if ON, use static linkage for BLAS and LAPACK. +# Default: not set (that is, the same as OFF) # -# SUITESPARSE_ALLOW_64BIT_BLAS if true, SuiteSparse will search for both +# SUITESPARSE_USE_64BIT_BLAS if true, SuiteSparse will search for both # 32-bit and 64-bit BLAS. If false, only 32-bit BLAS # will be searched for. Ignored if BLA_VENDOR and # BLA_SIZEOF_INTEGER are defined. @@ -81,12 +81,25 @@ # installed in the subfolder `pkgconfig` of the directory # where the (static) libraries will be installed. # Default: CMAKE_INSTALL_PREFIX, or SuiteSparse/lib if -# LOCAL_INSTALL is enabled. +# SUITESPARSE_LOCAL_INSTALL is enabled. # # SUITESPARSE_INCLUDEDIR_POSTFIX : Postfix for installation target of # header from SuiteSparse. Default: suitesparse, so the # default include directory is: # CMAKE_INSTALL_PREFIX/include/suitesparse +# +# SUITESPARSE_USE_STRICT: SuiteSparse has many user-definable settings of the +# form SUITESPARSE_USE_* or (package)_USE_* for some +# particular package. In general, these settings are not +# strict. For example, if SUITESPARSE_USE_OPENMP is +# ON then OpenMP is preferred, but SuiteSparse can be +# used without OpenMP so no error is generated if OpenMP +# is not found. However, if SUITESPARSE_USE_STRICT is +# ON then all *_USE_* settings are treated strictly +# and an error occurs if any are set to ON but the +# corresponding package or setting is not available. The +# *_USE_SYSTEM_* settings are always treated as strict. +# Default: OFF. message ( STATUS "Source: ${CMAKE_SOURCE_DIR} ") message ( STATUS "Build: ${CMAKE_BINARY_DIR} ") @@ -108,6 +121,9 @@ include ( GNUInstallDirs ) set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake_modules ) +# strict usage +option ( SUITESPARSE_USE_STRICT "ON: treat all _USE__ settings as strict if they are ON. OFF (default): consider *_USE_* as preferences, not strict" OFF ) + # build the demos option ( SUITESPARSE_DEMOS "ON: Build the demo programs. OFF (default): do not build the demo programs." OFF ) @@ -131,10 +147,10 @@ endif ( ) # installation options if ( NOT SUITESPARSE_ROOT_CMAKELISTS AND ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.19.0" ) - # the LOCAL_INSTALL option requires cmake 3.19.0 or later - option ( LOCAL_INSTALL "Install in SuiteSparse/lib" OFF ) + # the SUITESPARSE_LOCAL_INSTALL option requires cmake 3.19.0 or later + option ( SUITESPARSE_LOCAL_INSTALL "Install in SuiteSparse/lib" OFF ) else ( ) - set ( LOCAL_INSTALL OFF ) + set ( SUITESPARSE_LOCAL_INSTALL OFF ) endif ( ) if ( SUITESPARSE_SECOND_LEVEL ) @@ -150,10 +166,10 @@ endif ( ) set ( INSIDE_SUITESPARSE OFF ) if ( NOT SUITESPARSE_ROOT_CMAKELISTS ) # determine if this Package is inside the SuiteSparse folder - if ( LOCAL_INSTALL ) + if ( SUITESPARSE_LOCAL_INSTALL ) # if you do not want to install local copies of SuiteSparse # packages in SuiteSparse/lib and SuiteSparse/, set - # LOCAL_INSTALL to false in your CMake options. + # SUITESPARSE_LOCAL_INSTALL to false in your CMake options. if ( SUITESPARSE_SECOND_LEVEL ) # the package is normally located at the 2nd level inside SuiteSparse # (SuiteSparse/GraphBLAS/GraphBLAS/ for example) @@ -169,7 +185,7 @@ if ( NOT SUITESPARSE_ROOT_CMAKELISTS ) endif ( ) if ( NOT INSIDE_SUITESPARSE ) - message ( FATAL_ERROR "Unsupported layout for local installation. Correct the directory layout or unset LOCAL_INSTALL." ) + message ( FATAL_ERROR "Unsupported layout for local installation. Correct the directory layout or unset SUITESPARSE_LOCAL_INSTALL." ) endif ( ) endif ( ) @@ -178,7 +194,7 @@ endif ( ) set ( SUITESPARSE_INCLUDEDIR_POSTFIX "suitesparse" CACHE STRING "Postfix for installation target of header from SuiteSparse (default: \"suitesparse\")" ) -if ( LOCAL_INSTALL ) +if ( SUITESPARSE_LOCAL_INSTALL ) if ( INSIDE_SUITESPARSE ) # ../lib and ../include exist: the package is inside SuiteSparse. # find ( REAL_PATH ...) requires cmake 3.19. @@ -242,6 +258,12 @@ if ( SUITESPARSE_USE_FORTRAN ) endif ( ) else ( ) message ( STATUS "Fortran: not enabled" ) + set ( SUITESPARSE_HAS_FORTRAN OFF ) +endif ( ) + +# check for strict usage +if ( SUITESPARSE_USE_STRICT AND SUITESPARSE_USE_FORTRAN AND NOT SUITESPARSE_HAS_FORTRAN ) + message ( FATAL_ERROR "Fortran required for SuiteSparse but not found" ) endif ( ) # default C-to-Fortran name mangling if Fortran compiler not found @@ -259,8 +281,14 @@ endif ( ) # find CUDA #------------------------------------------------------------------------------- -option ( SUITESPARSE_USE_CUDA "Enable CUDA acceleration for SuiteSparse" ON ) -if ( SUITESPARSE_USE_CUDA AND NOT MSVC ) +if ( MSVC ) + # do not attempt to use CUDA on MSVC + set ( SUITESPARSE_USE_CUDA OFF ) +else ( ) + option ( SUITESPARSE_USE_CUDA "ON (default): enable CUDA acceleration for SuiteSparse, OFF: do not use CUDA" ON ) +endif ( ) + +if ( SUITESPARSE_USE_CUDA ) # try finding CUDA check_language ( CUDA ) @@ -304,3 +332,8 @@ else ( ) message ( STATUS "CUDA: not enabled" ) endif ( ) +# check for strict usage +if ( SUITESPARSE_USE_STRICT AND SUITESPARSE_USE_CUDA AND NOT SUITESPARSE_HAS_CUDA ) + message ( FATAL_ERROR "CUDA required for SuiteSparse but not found" ) +endif ( ) + diff --git a/cmake_modules/SuiteSparseReport.cmake b/cmake_modules/SuiteSparseReport.cmake index f18c55d1e2..50e3465abb 100644 --- a/cmake_modules/SuiteSparseReport.cmake +++ b/cmake_modules/SuiteSparseReport.cmake @@ -14,7 +14,7 @@ message ( STATUS "SuiteSparse CMAKE report for: ${CMAKE_PROJECT_NAME}" ) message ( STATUS "------------------------------------------------------------------------" ) if ( NOT SUITESPARSE_ROOT_CMAKELISTS ) message ( STATUS "inside common SuiteSparse root: ${INSIDE_SUITESPARSE}" ) - message ( STATUS "install in SuiteSparse/lib and SuiteSparse/include: ${LOCAL_INSTALL}" ) + message ( STATUS "install in SuiteSparse/lib and SuiteSparse/include: ${SUITESPARSE_LOCAL_INSTALL}" ) endif ( ) message ( STATUS "build type: ${CMAKE_BUILD_TYPE}" ) message ( STATUS "BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}" )