Try to Debug CUDA code launched by Python script (interfaced by Cython) Updated

As titled stated I have been trying to get this working in VSCode, and long-story short is, I already got it working for CLI cuda-gdb (and debug and switch focus etc.), so I know the debugging symbols are there. I just want to get it working in VSCode so I have can finally have a graphical IDE for programming. Please let me know if it is possible, i feel like I am very close to getting it to work, any help or pointer will be greatly appreciated.

Situation: compiled CUDA code and packed into a dynamic library exposing to Python via Cython framework, can already debug it using cuda-gdb (thanks to this post: Debugger for python & C/C++ CUDA)

Now want to make it work in NSight VSCode so I can finally get it working (using Ubuntu + 1660Ti)

After setting the breakpoints in both the host AND device codes. I tried to configure it 3 ways (now 4) in launch.json (after running sudo echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope), to get it to hit any breakpoint.

  1. 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

  1. 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

  1. 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):

"NVIDIA (R) CUDA Debugger
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]"

Again, any help would be greatly appreciated.

Additional trial,

  1. 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: Now it runs the python script correctly, 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 debug symbol can be picked up by the VSCode IDE. And the cuda-gdb prove the debugging symbols is here, but somehow when invoking the cuda-gdb in “type” in launch.json, the debugger is not launched correctly in VSCode for it to pick up and break at the device code lines.

Tried packaging the python script and libraries into one executable using pyInstaller, but it did not retain the debug symbols. When invoking the cuda-gdb it did not find any debug symbol.

Emailed the Nvidia support as well as the VSCode team but have not heard any thing back yet. Currently is building test functions in C++ and launching the executable directly in VSCode but would rather be able to launch them with python scripts via Cython.

If any one knows any hints or someone that I can refer too would be much appreciated.