171 字
1 分钟
VScode调试 CUDA+CMAKE

VScode调试 CUDA+CMAKE#

在vscode中进行运行调试cuda程序

Launch.json#

{
"version": "0.2.0",
"configurations": [
{
"name": "CUDA C++: Launch",
"type": "cuda-gdb",
"request": "launch",
"program": "${workspaceFolder}/build/gpu2dfd",
"args": "xx",
"preLaunchTask":"Build"
},
]
}

Tasks.json#

{
"version": "2.0.0",
"options": {
"cwd": "${workspaceFolder}/build" // 进入 build 文件夹
},
"tasks": [
{
// 运行 cmake .. 命令
"type": "shell",
"label": "cmake",
"command": "cmake",
"args": [
".."
]
},
{
// 运行 make 命令
"label": "make",
"group": {
"kind": "build",
"isDefault": true
},
"command": "make",
"args": [
]
},
{
"label": "Build",
"dependsOrder": "sequence", // 按列出的顺序执行任务依赖项
"dependsOn":[
"cmake",
"make"
]
}
]
}

Cmake#

# complie the FDTD CUDA code with cmake
cmake_minimum_required(VERSION 3.10)
project(GPU2DFD LANGUAGES CUDA CXX)
# set the debug mode
set(CMAKE_BUILD_TYPE Debug)
# check the cuda language
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
message(STATUS "Find CUDA !")
else()
message(FATAL_ERROR "Not found CUDA!")
endif()
set(CMAKE_CUDA_STANDARD 11)
set(CMAKE_CUDA_ARCHITECTURES 50 60 70)
# add the source file
add_executable(gpu2dfd gpu2dfd.cu)
VScode调试 CUDA+CMAKE
https://tuoyuangui.github.io/website/posts/typora/编译调试/vscode调试方法/
作者
椭圆规/tuoyuangui
发布于
2026-08-12
许可协议
CC BY-NC-SA 4.0