Minimal CUDA project fails to run after successful configure and build
Trying to build and run a minimal cuda project with CMake 3.8.2 on OSX El Capitan. I have attached the source file, Makefile and CMakeLists.txt. When I build with the Makefile, it runs as expected. But, if I build with cmake, resulting program fails to run. I suspect the problem is with the linking stage. CMake uses clang++. When I replace CMake's link command (that I get from running CMake with CMAKE_VERBOSE_MAKEFILE=ON
) with nvcc, it works.
Makefile
$ make
nvcc -arch=sm_30 -dc hello.cu -o hello.o
nvcc -arch=sm_30 hello.o -o hello_cuda
$ ./hello_cuda
Running...
Hello! Idx: 0
Hello! Idx: 1
Hello! Idx: 2
Hello! Idx: 3
Hello! Idx: 4
Finished...
CMake
$ mkdir build
$ cd build
$ cmake ..
-- The CXX compiler identification is AppleClang 7.3.0.7030031
-- The CUDA compiler identification is NVIDIA 8.0.61
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working CUDA compiler: /Developer/NVIDIA/CUDA-8.0/bin/nvcc
-- Check for working CUDA compiler: /Developer/NVIDIA/CUDA-8.0/bin/nvcc -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/REDACTED/minimal_cmake/build
$ make
Scanning dependencies of target hello_cuda
[ 33%] Building CUDA object CMakeFiles/hello_cuda.dir/hello.cu.o
nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
[ 66%] Linking CUDA device code /Users/REDACTED/minimal_cmake/build/CMakeFiles/hello_cuda.dir/cmake_device_link.o
nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
[100%] Linking CUDA executable hello_cuda
[100%] Built target hello_cuda
$ ./hello_cuda
Running...
0 CUDA driver version is insufficient for CUDA runtime version
Replace linker manually
$ cmake -DCMAKE_VERBOSE_MAKEFILE=ON ..
...
...
[ 66%] Linking CUDA executable hello_cuda
/Applications/CMake.app/Contents/bin/cmake -E cmake_link_script CMakeFiles/hello_cuda.dir/link.txt --verbose=1
clang++ CMakeFiles/hello_cuda.dir/hello.cu.o CMakeFiles/hello_cuda.dir/cmake_device_link.o -o hello_cuda -L"/Developer/NVIDIA/CUDA-8.0/lib" "/Developer/NVIDIA/CUDA-8.0/lib/libcudart_static.a" -lcudadevrt
$ nvcc CMakeFiles/hello_cuda.dir/hello.cu.o CMakeFiles/hello_cuda.dir/cmake_device_link.o -o hello_cuda -L"/Developer/NVIDIA/CUDA-8.0/lib" "/Developer/NVIDIA/CUDA-8.0/lib/libcudart_static.a" -lcudadevrt
nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
$ ./hello_cuda
Running...
Hello! Idx: 0
Hello! Idx: 1
Hello! Idx: 2
Hello! Idx: 3
Hello! Idx: 4
Finished...