You are not logged in.

#1 2020-05-12 21:33:32

stefano
Member
Registered: 2011-04-09
Posts: 287

Cmake fails to compile CUDA sample code [SOLVED]

I have the latest CUDA package installed (Cuda 10.2) and I can successfully compile all the samples it comes with.

Yet, when I try to compile a project that uses cmake KataGo, compilation fails at the configuration stage because cmake cannot compile some test code:

stefano@gorgias cpp $ cmake .
Building 'katago' executable for GTP engine and other tools
-DUSE_BACKEND=CUDA, using CUDA backend
-- The CUDA compiler identification is NVIDIA 10.2.89
-- Check for working CUDA compiler: /opt/cuda/bin/nvcc
-- Check for working CUDA compiler: /opt/cuda/bin/nvcc - broken
CMake Error at /usr/share/cmake-3.17/Modules/CMakeTestCUDACompiler.cmake:46 (message):
  The CUDA compiler

    "/opt/cuda/bin/nvcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/stefano/builds/KataGo/cpp/CMakeFiles/CMakeTmp
    
    Run Build Command(s):/usr/bin/make cmTC_0feb7/fast && /usr/bin/make  -f CMakeFiles/cmTC_0feb7.dir/build.make CMakeFiles/cmTC_0feb7.dir/build
    make[1]: Entering directory '/home/stefano/builds/KataGo/cpp/CMakeFiles/CMakeTmp'
    Building CUDA object CMakeFiles/cmTC_0feb7.dir/main.cu.o
    /opt/cuda/bin/nvcc -forward-unknown-to-host-compiler   -cudart shared    -x cu -c /home/stefano/builds/KataGo/cpp/CMakeFiles/CMakeTmp/main.cu -o CMakeFiles/cmTC_0feb7.dir/main.cu.o
    Linking CUDA executable cmTC_0feb7
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_0feb7.dir/link.txt --verbose=1
    /opt/cuda/bin/g++   CMakeFiles/cmTC_0feb7.dir/main.cu.o -o cmTC_0feb7  -lcudadevrt -lcudart_static  -L"/opt/cuda/targets/x86_64-linux/lib/stubs" -L"/opt/cuda/targets/x86_64-linux/lib" -lcudadevrt -lcudart
    /usr/bin/ld: /opt/cuda/targets/x86_64-linux/lib/libcudart_static.a(libcudart_static.a.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
    /usr/bin/ld: /usr/lib/libdl.so.2: error adding symbols: DSO missing from command line
    collect2: error: ld returned 1 exit status
    make[1]: *** [CMakeFiles/cmTC_0feb7.dir/build.make:107: cmTC_0feb7] Error 1
    make[1]: Leaving directory '/home/stefano/builds/KataGo/cpp/CMakeFiles/CMakeTmp'
    make: *** [Makefile:141: cmTC_0feb7/fast] Error 2
    
  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:49 (enable_language)

-- Configuring incomplete, errors occurred!
See also "/home/stefano/builds/KataGo/cpp/CMakeFiles/CMakeOutput.log".
See also "/home/stefano/builds/KataGo/cpp/CMakeFiles/CMakeError.log".

I am talking with the developer, and he thinks the issue may be due to a mismatch between the version of g++ and glibc used. nVidia's CUDA installation page for linux lists the accepted combinations, but it is of little help, because Arch is not supported and therefore not listed.

Anyone using the cmake/CUDA combination who may have ideas?

Last edited by stefano (2020-05-13 15:30:36)

Offline

#2 2020-05-13 02:22:33

yan12125
Member
Registered: 2017-11-01
Posts: 36

Re: Cmake fails to compile CUDA sample code [SOLVED]

I got a similar error message from another project using CUDA (onnxruntime), and the issue turns out to be that cmake 3.17 changed something. You may get some inspiration from their fix: https://github.com/microsoft/onnxruntime/pull/3362.

Offline

#3 2020-05-13 15:30:18

stefano
Member
Registered: 2011-04-09
Posts: 287

Re: Cmake fails to compile CUDA sample code [SOLVED]

Thanks for the link, very informative.
For future reference: in my particular case, I found out the problem was caused by the cmake directive "enable_language(CUDA)" which start a compilaiton of a CUDA test program but is apparently unable to find the dl library.
Adding ${CMAKE_DL_LIBS} to the target_link_library directive immediately before  enable_language solved the issue.

Offline

Board footer

Powered by FluxBB