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 fornvrtc
and there are various CUDA sample codes fornvrtc
, most or all of which have_nvrtc
in the file name.I was able to do kernel source-level debugging on a
nvrtc
-generated kernel withcuda-gdb
as follows:vectorAdd_nvrtc
sample codecompileFileToPTX
routine (provided bynvrtc_helper.h
) to add the--device-debug
switch during the compile-cu-to-ptx step.loadPTX
routine (provided bynvrtc_helper.h
) to add theCU_JIT_GENERATE_DEBUG_INFO
option (set to 1) for thecuModuleLoadDataEx
load/JIT PTX-to-binary step.-g
option.Here is a complete test case/session. I'm only showing the
vectorAdd.cpp
file from the project because that is the only file I modified. Other project file(s) are identical to what is in the sample project: