安装扩展
- vscode-cudacpp
代码高亮 - Nsight Visual Studio Code Edition
debug
配置文件
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/cuda-10.2/include"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++14",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "build",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"sourceFileMap": {"/build/glibc-S9d2JN": "/usr/src/glibc"}
}
]
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "nvcc",
"args":["-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}.out",
// include 头文件
"-I", "/usr/local/cuda/include",
"-I", "/usr/local/cuda-10.2/samples/common/inc",
// lib 库文件地址
"-L", "/usr/local/cuda/lib64",
"-L", "/usr/local/cuda-10.2/samples/common/lib",
"-l", "cudart",
"-l", "cublas",
"-l", "cudnn",
"-l", "curand",
"-D_MWAITXINTRIN_H_INCLUDED"
]
}
]
}
安装glibc
这是因为调试cuda时,最后提示 vscode 无法打开 libc-start.c
sudo apt install glibc-source
cd /usr/src/glibc/
sudo tar -xvf glibc-2.27.tar.xz