0

How do I properly link my project to a TPL (CHOLMOD) that employs CUDA?

I want to link my CMake project to CHOLMOD (libcholmod.so). CHOLMOD was compiled separately with -GPU_BLAS, which is simply a flag that enables GPU functionality. The CHOLMOD library comes with several demos that allow the user to test that the library is functioning and working properly with the GPU. These tests all pass, and monitoring the GPU activity confirms these passes.

Now, I want to link my CMake project to gain access to libcholmod.so. I have done this with a simple FindCholmod.cmake file:

FIND_LIBRARY(CHOLMOD_LIBRARIES NAMES libcholmod.so PATHS /usr/local/SuiteSparse/lib)

FIND_LIBRARY(AMD_LIBRARY NAMES amd libamd PATHS /usr/local/SuiteSparse/lib)
FIND_LIBRARY(CAMD_LIBRARY NAMES camd libcmd PATHS /usr/local/SuiteSparse/lib)
FIND_LIBRARY(COLAMD_LIBRARY NAMES colamd libcolamd PATHS /usr/local/SuiteSparse/lib)
FIND_LIBRARY(CCOLAMD_LIBRARY NAMES ccolamd libccolamd PATHS /usr/local/SuiteSparse/lib) 
FIND_LIBRARY(SUITESPARSE_LIBRARY NAMES SuiteSparse libsuitesparseconfig.so 
PATHS /usr/local/SuiteSparse/lib)

FIND_PATH(CHOLMOD_INCLUDE_DIR cholmod.h PATH /usr/local/SuiteSparse/include)

MESSAGE(STATUS "FOUND CHOLDMOD " ${CHOLMOD_LIBRARIES})

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cholmod DEFAULT_MSG CHOLMOD_LIBRARIES 
CHOLMOD_INCLUDE_DIR AMD_LIBRARY CAMD_LIBRARY COLAMD_LIBRARY CCOLAMD_LIBRARY 
SUITESPARSE_LIBRARY)
MARK_AS_ADVANCED(CHOLMOD_LIBRARIES CHOLMOD_INCLUDE_DIR AMD_LIBRARY CAMD_LIBRARY COLAMD_LIBRARY CCOLAMD_LIBRARY SUITESPARSE_LIBRARY)

FindCublas.cmake (where I've ensured I am finding the same libraries used during CHOLMOD compilation):

FIND_LIBRARY(CUBLAS_LIBRARY NAMES libcublas.so PATHS /usr/lib/x86_64-linux-gnu )
FIND_LIBRARY(CUDART_LIBRARY NAMES libcudart.so PATHS /usr/lib/x86_64-linux-gnu )
FIND_PATH(CUDA_INCLUDE_DIR cuda.h PATHS /usr/local/cuda-8.0/include)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CuBlas  DEFAULT_MSG  CUBLAS_LIBRARY CUDART_LIBRARY CUDA_INCLUDE_DIR)

MARK_AS_ADVANCED(CUBLAS_LIBRARY CUDART_LIBRARY CUDA_INLUCDE_DIR)

Of course I have similar FindMetis, FindOpenBlas, and FindLapack files. I then link everything:

SET(LINKLIBS  "${LINKLIBS};${CHOLMOD_LIBRARIES};${AMD_LIBRARY};${CAMD_LIBRARY};${COLAMD_LIBRARY};${CCOLAMD_LIBRARY};${OPENBLAS_LIBRARY};${METIS_LIBRARY};${LAPACK_LIBRARY};${CUBLAS_LIBRARY};${CUDART_LIBRARY};${SUITESPARSE_LIBRARY}")
INCLUDE_DIRECTORIES(${METIS_INCLUDE_DIR} ${CHOLMOD_INCLUDE_DIR} ${CUDA_INCLUDE_DIR})

Using this method, I can successfully gain access to CHOLMOD library of functions within my CMake project. In fact, it runs well, but it is just not accessing the GPU despite my following the CHOLMOD userguide to set export CHOLMOD_USE_GPU=1 and in cpp Common->useGPU=1.

My question is, how do I properly link my project to a TPL (CHOLMOD) that employs CUDA? My project contains no cuda code, beyond the link to the precompiled libcholmod.so. Do I need to set my CMake compiler to NVCC, even though libcholmod.so is already compiled with NVCC?

Additional CHOLMOD details: CHOLMOD uses some rules to decide if a matrix should be factorized on the GPU or not: CHOLMOD_ND_ROW_LIMIT, CHOLMOD_ND_COL_LIMIT, CHOLMOD_POTRF_LIMIT, CHOLMOD_GPU_SKIP I have ensured that my test matrix satisfies these criteria.

talonmies
  • 70,661
  • 34
  • 192
  • 269
  • AFAIK for using CUDA with CMake there is FindCUDA script (`find_package(CUDA)`) and then using `cuda_add_executable` etc. instead just `add_executable` ... but have no personal experience with that so far. – EmDroid Jul 28 '17 at 22:01
  • nvcc isn't a compiler, and no, you don't need to use it – talonmies Jul 29 '17 at 04:19
  • Great! Any idea why I can't access GPU functionality through the linked library then? – trickleboast Jul 29 '17 at 16:57
  • Do you think that is a realistic question to ask? – talonmies Jul 30 '17 at 09:15
  • @talonmies Actually, yes. I am trying to identify why I am able to use the entirety of the CHOLMOD library except for the GPU functionality. According to CHOLMOD User Guide, the only change that should be made to access GPU is to set the environment variable `export CHOLMOD_USE_GPU=1` or within the cpp script set `Common->useGPU=1`. I have done both but still, the GPU is not being activated. So what is the proper way to link to a TPL that employs CUDA? – trickleboast Jul 30 '17 at 16:50
  • @axalis Do I need to use the FindCUDA.cmake script even if my project does not contain any .cu files? – trickleboast Jul 30 '17 at 17:15
  • If you are only compiling plain C++ code and linking against a pre-built library which includes CUDA, you do not need to use the CUDA toolchain and you do not need to use any of the CMake CUDA hackery. None of this is required. And none of it will have any bearing on your underlying question regarding CHOLMOD. – talonmies Jul 31 '17 at 08:40
  • You are not making this mistake, are you? https://stackoverflow.com/questions/32015860/cannot-use-cholmod-with-cuda-acceleration-in-my-own-code – talonmies Jul 31 '17 at 14:00
  • @talonmies Well, I am glad this was not a library linking issue. Actually yes, I was making that mistake. I apologize for missing that question, thank you very much for your help. – trickleboast Jul 31 '17 at 20:05
  • 1
    Possible duplicate of [Cannot use CHOLMOD with CUDA acceleration in my own code](https://stackoverflow.com/questions/32015860/cannot-use-cholmod-with-cuda-acceleration-in-my-own-code) – talonmies Jul 31 '17 at 20:15

0 Answers0