skip to Main Content

I’m trying to debug a test program with VS CODE, CMake in Ubuntu 20. I referred mainly to the CUDA debugger document: https://docs.nvidia.com/nsight-visual-studio-code-edition/cuda-debugger/index.html.
However, I’m not sure about how to write a correct launch.json in a project based on CMake.
Here is my CMakeLists.txt

cmake_minimum_required(VERSION 3.2)
project(cudaDebug CXX CUDA)
find_package(CUDA REQUIRED)
add_executable(main main.cu)

Here is my launch.json generated by VS CODE

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "CUDA C++: Launch",
            "type": "cuda-gdb",
            "request": "launch",
            "program": "main.cu"
        },
        {
            "name": "CUDA C++: Attach",
            "type": "cuda-gdb",
            "request": "attach"
        }
    ]
}

When I press F5 to start debugging, an error information poped up:

main.cu: 346262241346234211351202243344270252346226207344273266346210226347233256345275225.

2

Answers


  1. I think you have to change the following line:

             "program": "main.cu"
    

    to

             "program": "${command:cmake.launchTargetPath}"
    

    and select the executable in VSCode (usually on the bottom row where you can also select build targets).

    Have also a look here:

    https://vector-of-bool.github.io/docs/vscode-cmake-tools/debugging.html

    Login or Signup to reply.
  2. you can try to update your cmake version to higher than 3.10, which no longer need to use find_package(CUDA)
    here is one template for vscode and cmake to use cuda-gdb
    CMakeLists.txt

    cmake_minimum_required(VERSION 3.16)
    project(your_project_name CUDA CXX C)  # enable cuda language
    set(CMAKE_CUDA_COMPILER /usr/local/cuda/bin/nvcc)
    set(CMAKE_CUDA_STANDARD 11)
    set(CMAKE_CUDA_FLAGS ${CMAKE_CUDA_FLAGS} "-g -G")  # enable cuda-gdb
    
    add_executable(${PROJECT_NAME})
    target_sources(${PROJECT_NAME} PRIVATE your_source_files)
    set_target_properties(${PROJECT_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
    

    tasks.json

    {
        "options": {
           "cwd": "${workspaceFolder}/build"  
        },
        "tasks": [
           {
              "label": "cmake",  
              "command":"cmake",  
              "args": ["-DCMAKE_BUILD_TYPE=Debug", ".."]  
           },
           {
              "label": "make",  
              "command":"make",  
           },
           {
              "label": "cmake build", 
              "dependsOn":[  
                 "cmake",
                 "make"
              ],
           }
        ],
        "version": "2.0.0"
     }
    

    launch.json

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "CUDA C++: Launch",
                "type": "cuda-gdb",
                "request": "launch",
                "program": "${workspaceFolder}/build/your_executable_file",
                "stopAtEntry": false,
                "cwd": "${workspaceFolder}",
                "preLaunchTask": "cmake build"
            }
         ]
    }
    

    wish it could help you 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search