Skip to content

Commit

Permalink
SUITESPARSE_USE_STRICT
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTimothyAldenDavis committed Dec 22, 2023
1 parent d9ddfb8 commit 1d79d73
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 40 deletions.
37 changes: 30 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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} )
Expand All @@ -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} )
Expand All @@ -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 " )
Expand Down Expand Up @@ -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} )
Expand Down Expand Up @@ -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 )
Expand Down
37 changes: 27 additions & 10 deletions GraphBLAS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
#-------------------------------------------------------------------------------
Expand All @@ -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 )
Expand All @@ -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 " )
Expand Down Expand Up @@ -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)
#-------------------------------------------------------------------------------
Expand All @@ -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} )
Expand Down
4 changes: 2 additions & 2 deletions GraphBLAS/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
69 changes: 51 additions & 18 deletions cmake_modules/SuiteSparsePolicy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand All @@ -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.
Expand Down Expand Up @@ -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} ")
Expand All @@ -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 )

Expand All @@ -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 )
Expand All @@ -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)
Expand All @@ -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 ( )
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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 )
Expand Down Expand Up @@ -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 ( )

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

0 comments on commit 1d79d73

Please sign in to comment.