python VSCode无法调试Cython Package CUDA代码(但CLI cuda-gdb可以)

aydmsdu9  于 2022-10-30  发布在  Python
关注(0)|答案(1)|浏览(263)

背景:在Ubuntu 20.04上运行VSCode
已完成以下工作:
(a)编译并构建CUDA代码的Cython Package 器(打包为共享库.so);
(b)Python脚本导入表示.so文件运行,并且可以直接从cuda-gdb在终端进行调试(得益于this link以及启用了ptrace_scope),可以看到GPU变量并切换焦点
(c)另外,我已经能够在命令行cuda-gdb和VSCode原生IDE中的不同CUDA代码(没有 Package ,纯CUDA代码链接并编译为可执行文件)中设置断点。
问题:从(b)中我知道GPU调试符号在那里,并且可以被cuda-gdb拾取。但是最终我希望能够在VSCode中调试。我在launch.json中尝试了以下4种方法(我已经对可执行文件这样做了,但是不能对Cython接口的python脚本这样做)
1.使用命令cuda.pickProcess,然后选择python进程:

{
“name”: “CUDA C++: Attach”,
“type”: “cuda-gdb”,
“request”: “attach”,
“processId”: “${command:cuda.pickProcess}”

结果1:“调试控制台”选项卡上没有显示任何内容,没有断点命中
1.使用ps grep查找进程ID,将其直接放在processId中

{
    “name”: “CUDA C++: Attach”,
    “type”: “cuda-gdb”,
    “request”: “attach”,
    “processId”: “12345” #The Process ID = 12345
    },

结果2:与1相同,无React
3)尝试调用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”选项卡中启动,但似乎未执行任何操作(如果运行脚本+ 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]"

1.将settings.json中的类型从“cuda-gdb”切换为launch.json中的“cppdbg”:

{
“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
}
]
}

结果四:现在,它将运行python脚本(与尝试3不同),并且它将在离开内核的行处中断(CUDA个别线程所在的地方没有线).所以VSCode可以在这个设置下运行Python脚本,并且CPU调试符号可以被VSCode IDE拾取.从前面看到,cuda-gdb证明了GPU调试符号是在这里,但在launch.json的“type”中调用cuda-gdb时,cuda调试器在VSCode中没有正确启动,无法获取GPU调试符号并在设备代码行处中断。
任何帮助/提示都非常感谢。

yyyllmsg

yyyllmsg1#

确保使用调试符号信息编译cu文件,使用-G -g -O 0

相关问题