0

my cmake seems to be having trouble finding the cuda compiler. Finding cuda as a package is successful, however the CMAKE_CUDA_COMPILER is set to false. The following output is generated by cmake:

-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Build type not specified, using Release
-- Looking for a CUDA compiler
-- Looking for a CUDA compiler - NOTFOUND
-- CUDA Support disabled.
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found CUDA: /usr/local/cuda-10.2 (found suitable exact version "10.2") 
-- Found GDAL: /usr/lib/libgdal.so (found version "2.2.3") 
-- Found Boost: /usr/include (found version "1.65.1") found components:  filesystem system 
-- Found EXIV2: /usr/lib/x86_64-linux-gnu/libexiv2.so  
-- Checking for module 'eigen3'
--   Found eigen3, version 3.3.9
-- Found eigen: /usr/local/include/eigen3  
-- Found Boost: /usr/include (found suitable version "1.65.1", minimum required is "1.40.0") found components:  system filesystem thread date_time iostreams serialization chrono atomic regex 
-- Checking for module 'libopenni'
--   Found libopenni, version 1.5.4.0
-- Found openni: /usr/lib/libOpenNI.so  
-- Checking for module 'libopenni2'
--   Found libopenni2, version 2.2.0.3
-- Found OpenNI2: /usr/lib/libOpenNI2.so  
-- Could NOT find ensenso (missing: ENSENSO_LIBRARY ENSENSO_INCLUDE_DIR) 
** WARNING ** io features related to ensenso will be disabled
-- Could NOT find DAVIDSDK (missing: DAVIDSDK_LIBRARY DAVIDSDK_INCLUDE_DIR) 
** WARNING ** io features related to davidSDK will be disabled
-- Could NOT find DSSDK (missing: _DSSDK_LIBRARIES) 
** WARNING ** io features related to dssdk will be disabled
** WARNING ** io features related to pcap will be disabled
** WARNING ** io features related to png will be disabled
-- Found Boost: /usr/include (found version "1.65.1") found components:  system filesystem 
-- CUDA not found. Skipping PSL package...
-- Found OpenCV: /usr/local (found version "3.3.1") 
-- Found Eigen3: /usr/local/include/eigen3 (Required is at least version "2.91.0") 
-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so   
-- Found OpenMP_C: -fopenmp (found version "4.5") 
-- Found OpenMP_CXX: -fopenmp (found version "4.5") 
-- Found OpenMP: TRUE (found version "4.5")  
-- Configuring done
-- Generating done

Relevant lines are:

-- Looking for a CUDA compiler - NOTFOUND
-- CUDA Support disabled.
-- Found CUDA: /usr/local/cuda-10.2 (found suitable exact version "10.2") 

The code I use inside CMake 3.15.7 to check for cuda:

check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
    enable_language(CUDA)
    message(STATUS "CUDA Support enabled.")

    include(FindCUDA)
    set(CUDA_ARCH_LIST Auto CACHE STRING  "List of CUDA architectures (e.g. Pascal, Volta, etc) or \
                                           compute capability versions (6.1, 7.0, etc) to generate code for. \
                                           Set to Auto for automatic detection (default).")
    cuda_select_nvcc_arch_flags(CUDA_ARCH_FLAGS ${CUDA_ARCH_LIST})
    list(APPEND CUDA_NVCC_FLAGS ${CUDA_ARCH_FLAGS})
else()
    message(STATUS "CUDA Support disabled.")
endif()

What is going on? I'd swear it worked at some point. But now it isn't anymore. nvcc --version and nvidia-smi give reasonable outputs. My .bashrc looks like this:

export CPATH=/usr/local/cuda-10.2/include:$CPATH
export PATH=/usr/local/cuda-10.2/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
talonmies
  • 70,661
  • 34
  • 192
  • 269
Alex Pander
  • 95
  • 1
  • 9
  • 1
    1. The output doesn't correspond to your `CMakeLists.txt` file. For example, you can't find Boost without looking for it. 2. Get CMake 3.21 . No reason to use an older version when the new ones are easily usable by downloading the binary. They're quite tolerant of specific idiosyncracies of your system and you typically don't need to build them yourself. – einpoklum Aug 27 '21 at 09:57
  • This is not the whole CMakeLists.txt of course. only the relevant part for cuda lookup. But I will checkout 3.21. Thanks! – Alex Pander Aug 27 '21 at 10:27
  • So please provide an actual CMakeLists.txt file and the actual output you get, or we won't be able to verify what you see. – einpoklum Aug 27 '21 at 13:57
  • @einpoklum The file is long and the rest not important...Anyway, I think I found the problem. I installed cuda 10.2 with one gcc version and changed the gcc version at some later point. This version seems to be causing issues! – Alex Pander Aug 27 '21 at 15:36
  • I meant, keep a short file and provide its output... – einpoklum Aug 27 '21 at 15:55

1 Answers1

0

Okay, I found the issue. Every CUDA version only supports a specific gcc version. Compatibility can be found here: https://stackoverflow.com/a/46380601/9299366

After installation of CUDA at some point I changed my default gcc version resulting in this odd behaviour of cmake not being able to detect cuda despite nvcc and nvidia-smi properly working. I purged CUDA and the Nvidia driver completely, set a valid gcc version and reinstalled CUDA + driver. It seems to be working fine now.

Alex Pander
  • 95
  • 1
  • 9