如果觉得本篇文章对您的学习起到帮助作用,请 点赞 + 关注 + 评论 ,留下您的足迹💪💪💪
本文主要介绍VScode下的CUDA编程配置,因此记录以备日后查看,同时,如果能够帮助到更多人,也不胜荣幸。
文章目录
- 一、创建compile_commands.json
- 1、cmake中使用
- 2、make中使用
 
- 二、安装必要的插件
- 1.远程连接ssh
- 2.C/C++
- 3.C/C++ Extension Pack
- 4.Nsight Visual Studio Code Edition
- 5. vscode-cudacpp
 
- 三、配置c_cpp_properties.json
- 四、配置setting.json
- 五、配置tasks.json
- 六、配置launch.json
一、创建compile_commands.json
compile_commands.json 文件能够有效提高一些工具(比如vscode)的代码跳转、补全等功能。
1、cmake中使用
cmake工程生成 compile_commands.json 文件比较简单:
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1
2、make中使用
安装bear:
sudo apt-get install bear
执行:
bear -- make -j8
会生成compile_commands.json文件
二、安装必要的插件
1.远程连接ssh

2.C/C++

3.C/C++ Extension Pack

4.Nsight Visual Studio Code Edition

5. vscode-cudacpp

三、配置c_cpp_properties.json
Ctrl+Shift+P搜索C/C++:Edit Configurations(JSON),点击进入:
 
 随后生成.vscode文件:
 
 c_cpp_properties.json配置为如下所示:
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c17",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "linux-gcc-x64",
            "configurationProvider": "ms-vscode.makefile-tools",
            "compileCommands": "${workspaceFolder}/compile_commands.json"
        }
    ],
    "version": 4
}
“compileCommands”: "${workspaceFolder}/compile_commands.json"为新添加的内容。
配置路径也可以在includePath中进行配置:
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/cuda/include/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c17",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "linux-gcc-x64",
            "configurationProvider": "ms-vscode.makefile-tools"
        }
    ],
    "version": 4
}
四、配置setting.json
在.vscode文件夹中创建setting.json文件,添加内容:
{
    "files.associations": {
        "*.cu":"cuda-cpp"
    }
}
参考查询网址vscode language identifier
五、配置tasks.json
1.Ctrl+Shift+P搜索Tasks:Configures Task,点击进入:
 
 2.选择 使用模板创建tasks.json文件(可能是英文形式)
 
 3.选择Others
 
 最终tasks.json文件内容:
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "make",
            "type": "shell",
            "command": "make -j16"
        }
    ]
}
六、配置launch.json
1.Ctrl+Shift+P搜索Debug:Add Configuration,点击进入:
  2.选择 CUDA C++(CUDA-GDB)
2.选择 CUDA C++(CUDA-GDB)
 
 生成launch.json文件。
增加"program": “${workspaceFolder}/cudaAPP”,cudaAPP是编译出的可执行文件。
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "CUDA C++: Launch",
            "type": "cuda-gdb",
            "request": "launch",
            "program": "${workspaceFolder}/cudaAPP"
        },
        {
            "name": "CUDA C++: Attach",
            "type": "cuda-gdb",
            "request": "attach"
        }
    ]
}
如果您觉得这篇文章对你有帮助,记得 点赞 + 关注 + 评论 三连,您只需动一动手指,将会鼓励我创作出更好的文章,快留下你的足迹吧💪💪💪










![[cpp primer随笔] 11. 内联函数与constexpr函数](https://img-blog.csdnimg.cn/img_convert/c8395f15cdd43169426332c33b764ec6.png)





![[开源]基于Vue+ElementUI+G2Plot+Echarts的仪表盘设计器](https://img-blog.csdnimg.cn/img_convert/ba16656a7f59c266e90251a1f7b8d20f.png)


