Hi there, I am pretty new to building my own CUDA program with CMake, and I want to build a very simple project. Which just has one cu file, and I want to be able to debug it in VSCode (or cuda-dbg, which I have used in project developed by others before)
I have read through some of the simpler CUDA sample code and know that in order to enable the debug mode in both CPU and GPU, the nvcc compiler has to be invoked with “-g -G” flag. And indeed that works for the sample codes that came with the CUDA toolkit (of which they uses makefile directly)
I have read through the forum and stackoverflow about CUDA using CMake, and they all point to passing the CUDA_NVCC_FLAGS, which I have done so in the CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
project(mmul_tiled CUDA CXX)
enable_language(CUDA)
set(CUDA_VERBOSE_BUILD ON)
find_package(CUDA REQUIRED)
set(CUDA_NVCC_FLAGS "-G;-g;")
add_executable(
mmul_cached_tiles
mmul_source.cu)
set_target_properties(mmul_cached_tiles PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
And invoked the following command in the ‘build’ directory:
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CUDA_COMPILER=/usr/local/cuda-11.4/bin/nvcc ..
And then invoke the make command:
make VERBOSE=1
But i have observed that from the log, the nvcc compiler being called with just the ‘-g’ flag, instead of both ‘-g -G’, thus I can only debug the CPU code but not the GPU code:
[ 33%] Building CUDA object CMakeFiles/mmul_cached_tiles.dir/mmul_source.cu.o
/usr/local/cuda-11.4/bin/nvcc -forward-unknown-to-host-compiler -g -std=c++14 -MD -MT CMakeFiles/mmul_cached_tiles.dir/mmul_source.cu.o -MF CMakeFiles/mmul_cached_tiles.dir/mmul_source.cu.o.d -x cu -dc "/home/jefftam/JTDev/cuda_course_linux/03 mmul_cached_tiles/mmul_source.cu" -o CMakeFiles/mmul_cached_tiles.dir/mmul_source.cu.o
[ 66%] Linking CUDA device code CMakeFiles/mmul_cached_tiles.dir/cmake_device_link.o
/opt/cmake-3.21.2-linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/mmul_cached_tiles.dir/dlink.txt --verbose=1
/usr/local/cuda-11.4/bin/nvcc -forward-unknown-to-host-compiler -g -Xcompiler=-fPIC -Wno-deprecated-gpu-targets -shared -dlink CMakeFiles/mmul_cached_tiles.dir/mmul_source.cu.o -o CMakeFiles/mmul_cached_tiles.dir/cmake_device_link.o -lcudadevrt -lcudart_static -lrt -lpthread -ldl
[100%] Linking CUDA executable mmul_cached_tiles
/opt/cmake-3.21.2-linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/mmul_cached_tiles.dir/link.txt --verbose=1
/usr/bin/g++ CMakeFiles/mmul_cached_tiles.dir/mmul_source.cu.o CMakeFiles/mmul_cached_tiles.dir/cmake_device_link.o -o mmul_cached_tiles -lcudadevrt -lcudart_static -lrt -lpthread -ldl -L"/usr/local/cuda-11.4/targets/x86_64-linux/lib/stubs" -L"/usr/local/cuda-11.4/targets/x86_64-linux/lib"
Attached the CMakeLists.txt, CMakError.log and CMakeOutput.log and the copy of the Make log:
CMakeLists.txt (734 Bytes)
CMakeError.log (3.2 KB)
CMakeOutput.log (83.6 KB)
MakeVerbose.log (3.3 KB)
Appreciate any help at all, been stuck on this for a while.
Best,
JT