如何调试由cmake在VIsual Studio Code中构建的CUDA程序?



我试图调试一个测试程序与VS CODE, CMake在Ubuntu 20。我主要参考了CUDA调试器文档:https://docs.nvidia.com/nsight-visual-studio-code-edition/cuda-debugger/index.html。然而,我不确定如何写一个正确的发布。基于CMake. json的项目。这是我的CMakeLists.txt

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

这是我的发射。VS CODE生成的json

{
"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"
}
]
}

当我按F5开始调试时,弹出错误信息:

main.cu: 346262241346234211351202243344270252346226207344273266346210226347233256345275225.

我认为你必须更改以下行:

"program": "main.cu"

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

并选择VSCode中的可执行文件(通常在底部行,您也可以选择构建目标)。

也看看这里:

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

你可以尝试更新你的cmake版本到3.10以上,不再需要使用find_package(CUDA)
这里有一个模板为vscode和cmake使用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"
}
]
}

希望它能帮助你:)

相关内容

  • 没有找到相关文章

最新更新