vscode 配置 cuda 环境

安装扩展

  1. vscode-cudacpp
    代码高亮
  2. 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
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
配置 CUDA 环境通常需要以下步骤: 1. 安装 NVIDIA 驱动程序:首先,需要确认您的显卡型号并下载对应的 NVIDIA 驱动程序。然后,通过命令行或图形界面进行驱动程序的安装。 2. 安装 CUDA Toolkit:访问 NVIDIA 官方网站下载 CUDA Toolkit 的安装包。选择与您显卡驱动程序兼容的版本,并按照安装向导进行安装。安装完成后,CUDA 相关程序将会被安装到默认目录下。 3. 设置环境变量:为了在命令行中能够使用正确版本的 CUDA,需要设置相关的环境变量。打开终端,编辑或创建一个 `.bashrc` 或 `.bash_profile` 文件,并加入以下内容: ``` export PATH=/usr/local/cuda/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH ``` 然后运行以下命令使环境变量生效: ``` source ~/.bashrc ``` 4. 配置 VSCode 插件:打开 VSCode,按下 `Ctrl + P` 输入 `ext install`,然后输入 `TensorFlow Snippets` 并安装该插件。 5. 配置 `tasks.json` 文件:在 VSCode 的文件菜单中选择 `Tasks -> Configure Tasks`,然后选择 "Create tasks.json file from template",并选择 "Others"。在新打开的 `tasks.json` 文件中,添加以下代码: ```json { "version": "2.0.0", "tasks": [ { "label": "Compile CUDA", "type": "shell", "command": "nvcc", "args": ["${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}"], "group": { "kind": "build", "isDefault": true } } ] } ``` 6. 配置 `launch.json` 文件:在 VSCode 的文件菜单中选择 "Debug -> Add Configuration",然后选择 "C++ (GDB/LLDB)"。修改新打开的 `launch.json` 文件中的 `"program"` 字段为 `${fileDirname}/${fileBasenameNoExtension}`。 至此,您已成功配置了 Linux 系统上的 VSCode CUDA 环境。现在,您可以通过将 CUDA 代码保存为 `.cu` 文件后按下 `Ctrl + Shift + B` 来进行 CUDA 编译,或者选择 "Run" 菜单中的 "Start Debugging" 来进行 CUDA 调试。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值