How to setup a cmake project with cuda debugging support in vscode - Ubuntu 20.04, Nvidia RTX 2080 Max Q, driver 470, cuda toolkit 11.5


After several attempts, I still cannot get cmake+cuda+cuda-gdb to work in vscode.
I have installed C++ plugin as well as the Nsight Code plugin.
The breakpoint never hits inside the cuda kernel.

It would really help if you could share a demo project with this this setup.
I have seen the samples, but I do not want to use Makefiles and need to really understand what is really needed to get it working.

Attached is one of the many setups and configs I have attempted.
cuda-xx1.7z (631.6 KB)

Best Regards

Thanks for your submission, Sambit. I have filed an issue against our Visual Studio Code support to investigate your issues with CMake. My team has recently increased its staffing for Visual Studio Code support, and I will ensure that this use case gets reviewed within the next thirty days.

Is there any update on this? It’s been more than 60 days now!!!

Best Regards

Hi Sambit, note that in VS Code the build system and launch configuration are independent. Looking at your project, I believe the issue is that your build script is not configured to generate debug symbols. The best way to do this would be to add this to your CMakeLists.txt file:


You could also do it this way:

target_compile_options(testapp PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-g -G>)

Please try updating this configuration and give it another shot, thanks.


Thank you for the prompt response. However, to save time and be sure that I have the best solution, would it be possible to supply a full demo cmake project that I can just import into vscode and test the debug features?
It would really help me get going quickly.

Something as simple as just printing a 1000 element array or even just a hello world where I can set break points and check would be sufficient.

Best Regards

I have the same issue. The suggestion to add to cmake

target_compile_options(testapp PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:-g -G>)

did not work for me (the project builds and runs but does not stop at any breakpoints set inside a kernel function.

Any update on getting an example demo cmake project to build and debug in vscode with or where to find one?

Can you try setting logFile in your launch.json with an absolute path, reproduce the problem, and then send the log file? Also can you send a project that reproduces the issue and then I can try to identify what needs to be changed to make it work?

I fixed my issue. So in my CmakeLists.txt I was using the cuda_add_exectuable command and this somehow prevented debugging kernel functions from working. Is this deprecated now? Instead use the normal add_executable cmake command.

I added an example minimal project here with the .vscode launch script and a script.

This is a copy of the CMakeLists.txt that worked for me.

cmake_minimum_required(VERSION 3.16)
project(gpu_overlap CUDA CXX C)  # enable cuda language
set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
    set(CMAKE_CUDA_FLAGS ${CMAKE_CUDA_FLAGS} "-g -G")  # enable cuda-gdb

target_sources(${PROJECT_NAME} PRIVATE

Nvidia should just add a minimal example to GitHub - NVIDIA/cuda-samples: Samples for CUDA Developers which demonstrates features in CUDA Toolkit showing how to use cmake and cuda-gdb.