小Z起起伏伏后,打算入门CUDA开发,入门第一步当然是开发环境的搭建,这里把我踩过的坑分享出来,这里linux服务器已安装好nVidia,并且vscode能够通过ssh连接服务器,我在这里只贴出怎么搭建win端通过vscode连接导linux服务器实现cuda开发的过程。
1. 下载好插件
2.通过ssh连接好服务器
Remote->ssh
3.建立一个cuda工程
这一步中,需要在工程文件夹内再建立一个.vscode文件夹,并且要写好配置文件,这一步经常容易报错。
1)ctrl+shift+p自动创建c_cpp_properties.json
code:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
// 新增本地下载的cuda库路径
"/usr/local/cuda-11.7/include"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++98",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
2)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": "CUDA C++: Launch",
"type": "cuda-gdb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"preLaunchTask": "mynvcc",
},
{
"name": "CUDA C++: Attach",
"type": "cuda-gdb",
"request": "attach"
}
]
}
3)创建一个tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "mynvcc", //与launch.json的preLaunchTask保持一致
"type": "shell",
"command": "nvcc",
"args": ["-g","-G","-o","${fileDirname}/${fileBasenameNoExtension}","${file}"]
}
]
}
4.可以运行啦
#include <iostream>
int main(int argc, char **argv)
{
printf("cuda test\n");
getchar();
return 0;
}