Skip to content

Commit

Permalink
revise CUDA cmake options
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTimothyAldenDavis committed Dec 20, 2023
1 parent 50114d9 commit 2eac6e5
Show file tree
Hide file tree
Showing 75 changed files with 238 additions and 223 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- cuda: with
cuda-pkgs: "nvidia-cuda-dev nvidia-cuda-toolkit"
cuda-cmake-flags:
-DENABLE_CUDA=On
-DSUITESPARSE_USE_CUDA=ON
-DCUDAToolkit_INCLUDE_DIR="/usr/include"
-DCMAKE_CUDA_COMPILER_LAUNCHER="ccache"
- compiler: gcc
Expand All @@ -71,7 +71,7 @@ jobs:
cuda: with
cuda-pkgs: "nvidia-cuda-dev nvidia-cuda-toolkit"
cuda-cmake-flags:
-DENABLE_CUDA=On
-DSUITESPARSE_USE_CUDA=ON
-DCUDAToolkit_INCLUDE_DIR="/usr/include"
-DCMAKE_CUDA_COMPILER_LAUNCHER="ccache"
openmp: with
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
-DBLA_VENDOR="OpenBLAS" \
-DNSTATIC=ON \
-DCOMPACT=ON \
-DENABLE_CUDA=ON \
-DSUITESPARSE_USE_CUDA=ON \
-DCUDAToolkit_INCLUDE_DIR="/usr/include" \
..
echo "::endgroup::"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/root-cmakelists.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- cuda: with
cuda-pkgs: "nvidia-cuda-dev nvidia-cuda-toolkit"
cuda-cmake-flags:
-DENABLE_CUDA=ON
-DSUITESPARSE_USE_CUDA=ON
-DCUDAToolkit_INCLUDE_DIR="/usr/include"
-DCMAKE_CUDA_COMPILER_LAUNCHER="ccache"
- compiler: gcc
Expand All @@ -57,7 +57,7 @@ jobs:
cuda: with
cuda-pkgs: "nvidia-cuda-dev nvidia-cuda-toolkit"
cuda-cmake-flags:
-DENABLE_CUDA=ON
-DSUITESPARSE_USE_CUDA=ON
-DCUDAToolkit_INCLUDE_DIR="/usr/include"
-DCMAKE_CUDA_COMPILER_LAUNCHER="ccache"
link: static
Expand Down Expand Up @@ -232,7 +232,7 @@ jobs:
# - openmp: with
# cuda: with
# cuda-cmake-flags:
# -DENABLE_CUDA=ON
# -DSUITESPARSE_USE_CUDA=ON
# -DCMAKE_CUDA_COMPILER_LAUNCHER="ccache"

env:
Expand Down
25 changes: 14 additions & 11 deletions CHOLMOD/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ set ( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
${PROJECT_SOURCE_DIR}/cmake_modules
${PROJECT_SOURCE_DIR}/../SuiteSparse_config/cmake_modules )

option ( ENABLE_CUDA "ON (default): enable CUDA acceleration, OFF: do not use CUDA" ON )

option ( SUITESPARSE_USE_CUDA "ON (default): enable CUDA acceleration for SuiteSparse, OFF: do not use CUDA" ON )
option ( CHOLMOD_USE_CUDA "ON (default): enable CUDA acceleration for CHOLMOD, OFF: do not use CUDA" ON )
option ( CHOLMOD_GPL "ON (default): enable GPL-licensed modules, OFF: do not use any CHOLMOD GPL-licensed modules" ON )

if ( NOT CHOLMOD_GPL )
# CHOLMOD_GPL: if OFF, do not include any GPL-licensed module
set ( CHOLMOD_MATRIXOPS OFF )
set ( CHOLMOD_MODIFY OFF )
set ( CHOLMOD_SUPERNODAL OFF )
set ( ENABLE_CUDA OFF )
set ( CHOLMOD_USE_CUDA OFF )
add_compile_definitions ( NGPL )
endif ( )

Expand All @@ -60,9 +60,12 @@ if ( NOT HAVE_SSIZE_T )
add_compile_definitions ( NO_SSIZE_T )
endif ( )

if ( SUITESPARSE_CUDA )
if ( SUITESPARSE_HAS_CUDA AND CHOLMOD_USE_CUDA )
# CHOLMOD with CUDA
enable_language ( CUDA CXX )
set ( CHOLMOD_HAS_CUDA ON )
else ( )
set ( CHOLMOD_HAS_CUDA OFF )
endif ( )

#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -303,7 +306,7 @@ if ( BUILD_SHARED_LIBS )
PUBLIC_HEADER "Include/cholmod.h"
WINDOWS_EXPORT_ALL_SYMBOLS ON )

if ( SUITESPARSE_CUDA )
if ( CHOLMOD_HAS_CUDA )
set_target_properties ( CHOLMOD PROPERTIES CUDA_SEPARABLE_COMPILATION ON )
set_target_properties ( CHOLMOD PROPERTIES POSITION_INDEPENDENT_CODE ON )
endif ( )
Expand Down Expand Up @@ -335,7 +338,7 @@ if ( BUILD_STATIC_LIBS )
OUTPUT_NAME cholmod_static )
endif ( )

if ( SUITESPARSE_CUDA )
if ( CHOLMOD_HAS_CUDA )
set_target_properties ( CHOLMOD_static PROPERTIES CUDA_SEPARABLE_COMPILATION on )
set_target_properties ( CHOLMOD_static PROPERTIES POSITION_INDEPENDENT_CODE on )
endif ( )
Expand Down Expand Up @@ -486,13 +489,13 @@ if ( CHOLMOD_PARTITION )
endif ( )

# CHOLMOD_CUDA
if ( SUITESPARSE_CUDA )
if ( CHOLMOD_HAS_CUDA )
if ( BUILD_SHARED_LIBS )
target_compile_definitions ( CHOLMOD PUBLIC "SUITESPARSE_CUDA" )
target_compile_definitions ( CHOLMOD PUBLIC "CHOLMOD_HAS_CUDA" )
endif ( )
set ( CHOLMOD_CFLAGS "${CHOLMOD_CFLAGS} -DSUITESPARSE_CUDA" )
set ( CHOLMOD_CFLAGS "${CHOLMOD_CFLAGS} -DCHOLMOD_HAS_CUDA" )
if ( BUILD_STATIC_LIBS )
target_compile_definitions ( CHOLMOD_static PUBLIC "SUITESPARSE_CUDA" )
target_compile_definitions ( CHOLMOD_static PUBLIC "CHOLMOD_HAS_CUDA" )
endif ( )
if ( BUILD_SHARED_LIBS )
target_link_libraries ( CHOLMOD PRIVATE CUDA::nvrtc CUDA::cudart_static CUDA::cublas )
Expand Down Expand Up @@ -525,7 +528,7 @@ endif ( )
# find CUDA
#-------------------------------------------------------------------------------

if ( SUITESPARSE_CUDA )
if ( CHOLMOD_HAS_CUDA )
# with CUDA
add_subdirectory ( GPU )
message ( STATUS "CUDA libraries: " ${CUDA_LIBRARIES} )
Expand Down
12 changes: 6 additions & 6 deletions CHOLMOD/Check/cholmod_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,32 +623,32 @@ int CHOLMOD(gpu_stats)
int print = Common->print ;
double cpu_time, gpu_time ;

#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
P2 ("%s", "\nCHOLMOD GPU/CPU statistics:\n") ;
#else
P2 ("%s", "\nCHOLMOD BLAS statistics:\n") ;
#endif
P2 ("SYRK CPU calls %12.0f", (double) Common->CHOLMOD_CPU_SYRK_CALLS) ;
P2 (" time %12.4e\n", Common->CHOLMOD_CPU_SYRK_TIME) ;
#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
P2 (" GPU calls %12.0f", (double) Common->CHOLMOD_GPU_SYRK_CALLS) ;
P2 (" time %12.4e\n", Common->CHOLMOD_GPU_SYRK_TIME) ;
#endif
P2 ("GEMM CPU calls %12.0f", (double) Common->CHOLMOD_CPU_GEMM_CALLS) ;
P2 (" time %12.4e\n", Common->CHOLMOD_CPU_GEMM_TIME) ;
#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
P2 (" GPU calls %12.0f", (double) Common->CHOLMOD_GPU_GEMM_CALLS) ;
P2 (" time %12.4e\n", Common->CHOLMOD_GPU_GEMM_TIME) ;
#endif
P2 ("POTRF CPU calls %12.0f", (double) Common->CHOLMOD_CPU_POTRF_CALLS) ;
P2 (" time %12.4e\n", Common->CHOLMOD_CPU_POTRF_TIME) ;
#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
P2 (" GPU calls %12.0f", (double) Common->CHOLMOD_GPU_POTRF_CALLS) ;
P2 (" time %12.4e\n", Common->CHOLMOD_GPU_POTRF_TIME) ;
#endif
P2 ("TRSM CPU calls %12.0f", (double) Common->CHOLMOD_CPU_TRSM_CALLS) ;
P2 (" time %12.4e\n", Common->CHOLMOD_CPU_TRSM_TIME) ;
#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
P2 (" GPU calls %12.0f", (double) Common->CHOLMOD_GPU_TRSM_CALLS) ;
P2 (" time %12.4e\n", Common->CHOLMOD_GPU_TRSM_TIME) ;
#endif
Expand All @@ -659,7 +659,7 @@ int CHOLMOD(gpu_stats)
gpu_time = Common->CHOLMOD_GPU_SYRK_TIME + Common->CHOLMOD_GPU_TRSM_TIME +
Common->CHOLMOD_GPU_GEMM_TIME + Common->CHOLMOD_GPU_POTRF_TIME ;

#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
P2 ("time in the BLAS: CPU %12.4e", cpu_time) ;
P2 (" GPU %12.4e", gpu_time) ;
P2 (" total: %12.4e\n", cpu_time + gpu_time) ;
Expand Down
2 changes: 1 addition & 1 deletion CHOLMOD/Config/CHOLMODConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ include ( CMakeFindDependencyMacro )
set ( _dependencies_found ON )

# Look for NVIDIA CUDA toolkit
if ( @SUITESPARSE_CUDA@ AND NOT CUDAToolkit_FOUND )
if ( @CHOLMOD_HAS_CUDA@ AND NOT CUDAToolkit_FOUND )
find_dependency ( CUDAToolkit @CUDAToolkit_VERSION_MAJOR@ )
if ( NOT CUDAToolkit_FOUND )
set ( _dependencies_found OFF )
Expand Down
6 changes: 3 additions & 3 deletions CHOLMOD/Config/cholmod.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ int cholmod_l_version (int version [3]) ;

// Define buffering parameters for GPU processing
#ifndef SUITESPARSE_GPU_EXTERN_ON
#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
#include <cublas_v2.h>
#endif
#endif
Expand Down Expand Up @@ -832,7 +832,7 @@ typedef struct cholmod_common_struct
int64_t gpuFlops ; // Number of flops performed by the GPU
int gpuNumKernelLaunches ; // Number of GPU kernel launches

#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
// these three types are pointers defined by CUDA:
#define CHOLMOD_CUBLAS_HANDLE cublasHandle_t
#define CHOLMOD_CUDASTREAM cudaStream_t
Expand Down Expand Up @@ -4004,7 +4004,7 @@ int cholmod_l_score_comp (struct cholmod_descendant_score_t *i,
// remainder of SupernodalGPU Module
//------------------------------------------------------------------------------

#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA

#include "omp.h"
#include <fenv.h>
Expand Down
5 changes: 3 additions & 2 deletions CHOLMOD/Doc/CHOLMOD_UserGuide.tex
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,10 @@ \subsection{Compiling CHOLMOD with GPU support}
%-------------------------------------------------------------------------------

In order to support GPU processing, CHOLMOD must be compiled with the
preprocessor macro \verb'SUITESPARSE_CUDA' defined. It is enabled by default
preprocessor macro \verb'CHOLMOD_HAS_CUDA' defined. It is enabled by default
in {\tt cmake} if you have a GPU, but this can be disabled by setting this to
false when using cmake.
false when using cmake, via the cmake variables \verb'CHOLMOD_USE_CUDA'
or \verb'SUITESPARSE_USE_CUDA'.

%-------------------------------------------------------------------------------
\subsection{Enabling GPU acceleration in CHOLMOD}
Expand Down
8 changes: 4 additions & 4 deletions CHOLMOD/GPU/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ message ( STATUS "Building CHOLMOD_CUDA version: v"
include ( SuiteSparsePolicy )

enable_language ( CUDA )
set ( CMAKE_CUDA_FLAGS "-cudart=static -lineinfo -DSUITESPARSE_CUDA" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSUITESPARSE_CUDA" )
set ( CMAKE_CUDA_FLAGS "-cudart=static -lineinfo -DCHOLMOD_HAS_CUDA" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCHOLMOD_HAS_CUDA" )
message ( STATUS "C++ flags for CUDA: ${CMAKE_CXX_FLAGS}" )
message ( STATUS "nvcc flags for CUDA: ${CMAKE_CUDA_FLAGS}" )
file ( GLOB CHOLMOD_CUDA_SOURCES "cholmod_gpu.c" "cholmod_l_gpu.c"
Expand Down Expand Up @@ -53,7 +53,7 @@ if ( BUILD_SHARED_LIBS )
${CHOLMOD_CUDA_INCLUDES} )
set_target_properties ( CHOLMOD PROPERTIES POSITION_INDEPENDENT_CODE ON )
set_target_properties ( CHOLMOD PROPERTIES CUDA_SEPARABLE_COMPILATION ON )
target_compile_definitions ( CHOLMOD PUBLIC "SUITESPARSE_CUDA" )
target_compile_definitions ( CHOLMOD PUBLIC "CHOLMOD_HAS_CUDA" )
endif ( )

if ( BUILD_STATIC_LIBS )
Expand All @@ -62,7 +62,7 @@ if ( BUILD_STATIC_LIBS )
${CHOLMOD_CUDA_INCLUDES} )
set_target_properties ( CHOLMOD_static PROPERTIES CUDA_SEPARABLE_COMPILATION on )
set_target_properties ( CHOLMOD_static PROPERTIES POSITION_INDEPENDENT_CODE on )
target_compile_definitions ( CHOLMOD_static PUBLIC "SUITESPARSE_CUDA" )
target_compile_definitions ( CHOLMOD_static PUBLIC "CHOLMOD_HAS_CUDA" )
endif ( )

if ( BUILD_SHARED_LIBS )
Expand Down
14 changes: 7 additions & 7 deletions CHOLMOD/GPU/cholmod_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "cholmod_internal.h"

#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
#include <cuda.h>
#include <cuda_runtime.h>
#endif
Expand All @@ -41,7 +41,7 @@

static int poll_gpu (size_t s) /* TRUE if OK, FALSE otherwise */
{
#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
/* Returns TRUE if the GPU has a block of memory of size s,
FALSE otherwise. The block of memory is immediately freed. */
void *p = NULL ;
Expand Down Expand Up @@ -87,7 +87,7 @@ int CHOLMOD(gpu_memorysize) /* returns 1 on error, 0 otherwise */
return (0) ; /* not using the GPU at all */
}

#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA

/* find the total amount of free memory */
t = SuiteSparse_time ( ) ;
Expand Down Expand Up @@ -159,7 +159,7 @@ int CHOLMOD(gpu_memorysize) /* returns 1 on error, 0 otherwise */
int CHOLMOD(gpu_probe) ( cholmod_common *Common )
{

#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
int ngpus, idevice;
double tstart, tend;
struct cudaDeviceProp gpuProp;
Expand Down Expand Up @@ -201,7 +201,7 @@ int CHOLMOD(gpu_deallocate)
)
{

#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
cudaError_t cudaErr;

if ( Common->dev_mempool )
Expand Down Expand Up @@ -247,7 +247,7 @@ void CHOLMOD(gpu_end)
cholmod_common *Common
)
{
#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
int k ;

/* ------------------------------------------------------------------ */
Expand Down Expand Up @@ -354,7 +354,7 @@ void CHOLMOD(gpu_end)
int CHOLMOD(gpu_allocate) ( cholmod_common *Common )
{

#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA

int k;
size_t fdm, tdm;
Expand Down
2 changes: 1 addition & 1 deletion CHOLMOD/GPU/cholmod_gpu_kernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// SPDX-License-Identifier: GPL-2.0+
//------------------------------------------------------------------------------

#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA

#include <stdio.h>
#include "SuiteSparse_config.h"
Expand Down
2 changes: 1 addition & 1 deletion CHOLMOD/GPU/t_cholmod_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/* === include files and definitions ======================================== */
/* ========================================================================== */

#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA

#include <string.h>
#include "cholmod_template.h"
Expand Down
6 changes: 3 additions & 3 deletions CHOLMOD/Include/cholmod.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ int cholmod_l_version (int version [3]) ;

// Define buffering parameters for GPU processing
#ifndef SUITESPARSE_GPU_EXTERN_ON
#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
#include <cublas_v2.h>
#endif
#endif
Expand Down Expand Up @@ -832,7 +832,7 @@ typedef struct cholmod_common_struct
int64_t gpuFlops ; // Number of flops performed by the GPU
int gpuNumKernelLaunches ; // Number of GPU kernel launches

#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
// these three types are pointers defined by CUDA:
#define CHOLMOD_CUBLAS_HANDLE cublasHandle_t
#define CHOLMOD_CUDASTREAM cudaStream_t
Expand Down Expand Up @@ -4004,7 +4004,7 @@ int cholmod_l_score_comp (struct cholmod_descendant_score_t *i,
// remainder of SupernodalGPU Module
//------------------------------------------------------------------------------

#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA

#include "omp.h"
#include <fenv.h>
Expand Down
2 changes: 1 addition & 1 deletion CHOLMOD/Include/cholmod_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@

#ifndef CHOLMOD_INT64
// GPU acceleration only available for the CHOLMOD_INT64 case (int64)
#undef SUITESPARSE_CUDA
#undef CHOLMOD_HAS_CUDA
#endif

//------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions CHOLMOD/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ global:

# enable CUDA (this is the default, if CUDA is available)
cuda:
( cd build && cmake $(CMAKE_OPTIONS) -DENABLE_CUDA=1 .. && cmake --build . --config Release -j$(JOBS) )
( cd build && cmake $(CMAKE_OPTIONS) -DCHOLMOD_USE_CUDA=1 .. && cmake --build . --config Release -j$(JOBS) )

# disable CUDA
nocuda:
( cd build && cmake $(CMAKE_OPTIONS) -DENABLE_CUDA=0 .. && cmake --build . --config Release -j$(JOBS) )
( cd build && cmake $(CMAKE_OPTIONS) -DCHOLMOD_USE_CUDA=0 .. && cmake --build . --config Release -j$(JOBS) )

debug:
( cd build && cmake $(CMAKE_OPTIONS) -DCMAKE_BUILD_TYPE=Debug .. && cmake --build . --config Debug -j${JOBS} )
Expand Down
2 changes: 1 addition & 1 deletion CHOLMOD/Supernodal/cholmod_super_numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

#define DOUBLE
#ifdef CHOLMOD_INT64
#ifdef SUITESPARSE_CUDA
#ifdef CHOLMOD_HAS_CUDA
#include "cholmod_gpu_kernels.h"
#define REAL
#include "../GPU/t_cholmod_gpu.c"
Expand Down
Loading

0 comments on commit 2eac6e5

Please sign in to comment.