I have an application which generates CUDA C++ source code, compiles it into PTX at runtime using NVRTC, and then creates CUDA modules from it using the CUDA driver API.
If I debug this application using cuda-gdb, it displays the kernel (where an error occured) in the backtrace, but does not show the line number.
I export the generated source code into a file, and give the directory to cuda-gdb using the --directory option. I also tried passing its file name to nvrtcCreateProgram() (name argument). I use the compile options --device-debug and --generate-line-info with NVRTC.
Is there a way to let cuda-gdb know the location of the generated source code file, and display the line number information in its backtrace?
For those who may not be familiar with
nvrtc, it is a CUDA facility that allows runtime-compilation of CUDA C++ device code. As a result, device code generated at runtime (including modifications) can be used on a CUDA GPU. There is documentation fornvrtcand there are various CUDA sample codes fornvrtc, most or all of which have_nvrtcin the file name.I was able to do kernel source-level debugging on a
nvrtc-generated kernel withcuda-gdbas follows:vectorAdd_nvrtcsample codecompileFileToPTXroutine (provided bynvrtc_helper.h) to add the--device-debugswitch during the compile-cu-to-ptx step.loadPTXroutine (provided bynvrtc_helper.h) to add theCU_JIT_GENERATE_DEBUG_INFOoption (set to 1) for thecuModuleLoadDataExload/JIT PTX-to-binary step.-goption.Here is a complete test case/session. I'm only showing the
vectorAdd.cppfile from the project because that is the only file I modified. Other project file(s) are identical to what is in the sample project: