VS实现Cuda/C++的远程编译运行
最近想做一些论文代码的复现,需要用到写一些Cuda程序,由于自己用的电脑没有N卡,只能用服务器上的GPU,但又不想在服务器上调试,就想通过本地编写代码,在服务器上编译运行。查了一些资料,发现C++的远程编译运行比较容易,但是Cuda程序却很少有资料,现有的资料都是用Nsight做远程的Debug,还需要安装Nsight客户端,端口转发什么的,比较麻烦。经过研究,成功实现需求。
前提
本地已经安装好Visual studio,并且通过Remote-ssh插件配置好远程连接服务器。远程服务器上的Cuda环境已经安装好。
工具
.1.C/C++插件 一定要通过VS安装到服务器上,直接安装不行就通过 Install from VSIX安装。 2.Nsight Visual Studio Code Edition 插件 同样要安装到服务器上。
C++/Cuda运行
C++对应:g++ build and debug active file Cuda对应:CUDA C++: Launch
创建launch.json
内容如下: { “version”: “0.2.0”, “configurations”: [
{
"name": "CUDA C++: Launch",
"type": "cuda-gdb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "nvcc build active file",
"postDebugTask": "delete nvcc output file",
},
{
"name": "g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"postDebugTask": "delete output file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
在这里插入代码片
创建task.json
内容如下:
{
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-std=c++11",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "delete output file",
"command": "rm",
"args": [
"${fileDirname}/${fileBasenameNoExtension}"
],
"presentation": {
"reveal": "silent"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "nvcc build active file",
"command": "/usr/local/cuda-10.0/bin/nvcc",
"args": [
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "delete nvcc output file",
"command": "rm",
"args": [
"${fileDirname}/${fileBasenameNoExtension}"
],
"presentation": {
"reveal": "silent"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
测试
C++: Cuda: 搞定!!!
|