VSCODE无法调试Cython包装CUDA代码(但是CLI CUDA-GDB可以)
背景:在Ubuntu上运行VSCODE 20.04
已完成以下操作:
(a)编译并构建Cuda代码的Cython包装器(以共享库.SO包装);
(b)导入的python脚本所说的文件运行,可以直接从终端中的cuda-gdb进行调试(感谢此链接以及启用ptrace_scope),可以看到gpu变量并分别看到切换焦点
(c)我能够在其他CUDA代码(无包装,纯CUDA代码链接并链接到可执行文件)中设置断点本地IDE。如下所示
。在那里调试符号,可以由CUDA-GDB拾取。但是最终,我希望能够在VScode中进行调试。我已经尝试了启动中的以下4种方法。JSON(正如我为可执行文件所做的那样,但不能用于Cython-Interface Python脚本)
- 使用命令:cuda.pickprocess,然后选择python过程:
{
“name”: “CUDA C++: Attach”,
“type”: “cuda-gdb”,
“request”: “attach”,
“processId”: “${command:cuda.pickProcess}”
结果1:没有任何东西。在“调试控制台”选项卡上,没有
- 使用PS GREP查找过程ID的断点击中,将其直接放在ProcessID
{
“name”: “CUDA C++: Attach”,
“type”: “cuda-gdb”,
“request”: “attach”,
“processId”: “12345” #The Process ID = 12345
},
结果2:与1相同的过程
中。 试图调用Python可执行文件并提供Python脚本作为参数(test.py运行CUDA代码,因为已通过命令行cuda-gdb进行了验证)
{
“name”: “(gdb) Launch Python”,
“type”: “cuda-gdb”,
“request”: “launch”,
“program”: “/home/jeff/JTDev/venv/bin/python3”,
“args”:”/home/jeff/JTDev/03 Cython/JTCudaLibCython/test.py”,
“stopAtEntry”: false,
}
结果3:CUDA-GDB似乎在“ Debug Console” Tab中启动了CUDA-GDB但是它似乎没有做任何事情(如果运行脚本 + CUDA代码,则如果求和完成是否完成,则将输出):
11.7 release
Portions Copyright (C) 2007-2022 NVIDIA Corporation
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type “show copying” and “show warranty” for details.
This GDB was configured as “x86_64-pc-linux-gnu”.
Type “show configuration” for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type “help”.
Type “apropos word” to search for commands related to “word”.
[Thread debugging using libthread_db enabled]
Using host libthread_db library “/lib/x86_64-linux-gnu/libthread_db.so.1”.
[Inferior 1 (process 211846) exited with code 02]"
- 切换类型settings.json从“ cuda-gdb”到启动中的“ cppdbg”。json:
{
“name”: “(gdb) Launch 1123”,
“type”: “cppdbg”,
“request”: “launch”,
“program”: “/home/jeff/JTDev/venv/bin/python3”,
“args”: [
“/home/jeff/JTDev/03 Cython/CythonCUDA/test.py”
],
“stopAtEntry”: false,
“cwd”: “${workspaceFolder}”,
“externalConsole”: false,
“MIMode”: “gdb”,
“setupCommands”: [
{
“description”: “Enable pretty-printing for gdb”,
“text”: “-enable-pretty-printing”,
“ignoreFailures”: true
}
]
}
结果4:现在它将运行python脚本与尝试3中的python脚本,并且它将在线路上折断,而它会在线上折断(不是Cuda个体的地方)线线)。因此,VSCODE可以在此设置中运行Python脚本,并且可以通过VSCODE IDE挑选CPU调试符号。从以前可以看出,cuda-gdb证明了GPU调试符号在这里,但是在启动中以“类型”调用cuda-gdb时,cuda debugger在vscode中未正确启动,以供它拾取GPU调试符号并在设备代码线上断开。
任何帮助/技巧都将非常感谢。
Background: Running VSCode on Ubuntu 20.04
The following have been accomplished:
(a) Compiled and build the Cython wrapper for CUDA code (packaged as shared library .so);
(b) Python script importing said .so file runs, and can be debugged directly from cuda-gdb in terminal (thanks to this link as well as enabling the ptrace_scope), can see GPU variables and switch focus
(c) separately I have been able to set breakpoint in a different CUDA code (no wrapping, pure CUDA code linked and compiled to an executable) in both command-line cuda-gdb and VSCode's native IDE. As seen here in this youtube video
Problem: from (b) I know that the GPU debugging symbols are there, and can be picked up by cuda-gdb. But ultimately I would like to be able to debug in VSCode instead. I have tried the following 4 approaches in launch.json (as I have done so for the executable but cannot for the Cython-interfaced python script)
- use the command:cuda.pickProcess, and then picking the python process:
{
“name”: “CUDA C++: Attach”,
“type”: “cuda-gdb”,
“request”: “attach”,
“processId”: “${command:cuda.pickProcess}”
Result 1: nothing comes up on the Debug Console tab, no breakpoint hitting
- Using ps grep to find the process ID, put it directly in the processId
{
“name”: “CUDA C++: Attach”,
“type”: “cuda-gdb”,
“request”: “attach”,
“processId”: “12345” #The Process ID = 12345
},
Result 2: same as 1., nothing happens
3)
Trying to invoke the python executable and providing the python script as argument (test.py runs the cuda code, as it has been verified with command line cuda-gdb)
{
“name”: “(gdb) Launch Python”,
“type”: “cuda-gdb”,
“request”: “launch”,
“program”: “/home/jeff/JTDev/venv/bin/python3”,
“args”:”/home/jeff/JTDev/03 Cython/JTCudaLibCython/test.py”,
“stopAtEntry”: false,
}
Result 3: cuda-gdb appears to be launched in “DEBUG CONSOLE” tab but it seems to have not done any thing (if the script + CUDA code were run, it would have output if the summation has been finished or not):
11.7 release
Portions Copyright (C) 2007-2022 NVIDIA Corporation
GNU gdb (GDB) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type “show copying” and “show warranty” for details.
This GDB was configured as “x86_64-pc-linux-gnu”.
Type “show configuration” for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type “help”.
Type “apropos word” to search for commands related to “word”.
[Thread debugging using libthread_db enabled]
Using host libthread_db library “/lib/x86_64-linux-gnu/libthread_db.so.1”.
[Inferior 1 (process 211846) exited with code 02]"
- switching the type in settings.json from ‘cuda-gdb’ to ‘cppdbg’ in the launch.json:
{
“name”: “(gdb) Launch 1123”,
“type”: “cppdbg”,
“request”: “launch”,
“program”: “/home/jeff/JTDev/venv/bin/python3”,
“args”: [
“/home/jeff/JTDev/03 Cython/CythonCUDA/test.py”
],
“stopAtEntry”: false,
“cwd”: “${workspaceFolder}”,
“externalConsole”: false,
“MIMode”: “gdb”,
“setupCommands”: [
{
“description”: “Enable pretty-printing for gdb”,
“text”: “-enable-pretty-printing”,
“ignoreFailures”: true
}
]
}
Result 4: Now it will run the python script unlike in attempt 3, and it will break at the line leaving the kernel (not where the CUDA individual thread lines). So the VSCode Can run Python script in this setting, and the CPU debug symbol can be picked up by the VSCode IDE. As seen from before, cuda-gdb proves the GPU debugging symbols is here, but somehow when invoking the cuda-gdb in “type” in launch.json, the cuda debugger is not launched correctly in VSCode for it to pick up the GPU debugging symbol and break at the device code lines.
Any help/tips are greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保使用调试符号信息编译CU文件。
尝试使用
-G -G -O0
标志Make sure to compile cu file with debug symbol info.
Try using
-G -g -O0
flag我对您的配置候选者进行了一些调整,并设法获得了工作配置,可以在其中逐步进入python的Vscode中的CUDA内核,并使用
pip install
interage也很重要,对我的经验也很重要。 PIP安装您的软件包以下:
I tweaked a bit your configuration candidates and managed to get a working configuration where I can step into CUDA kernels in VSCode from python and using a .so library compiled with
pip install
Also, in my experience is important to pip install your package following: