[llvm-dev] [CUDA] Lost debug information when compiling CUDA code

Yuanfeng Peng via llvm-dev llvm-dev at lists.llvm.org
Tue Jun 13 23:59:36 PDT 2017


Hi,


I needed to debug some CUDA code in my project; however, although I used -g when compiling the source code, no source-level information is available in cuda-gdb or cuda-memcheck.  


Specifically, below is what I did:


1) For a CUDA file a.cu, generate IR files: clang++ -g -emit-llvm --cuda-gpu-arch=sm_35 -c a.cu;
2) Instrument the device code a-cuda-nvptx64-nvidia-cuda-sm_35.bc (generated in the previous step), inserting a call to a hook function before each device memory access.  The hook function is defined in another file, b.cu.  Let's say we get a file named intrumented-a-device.bc after this step;
3) Generate IR files for b.cu: clang++ -g -emit-llvm --cuda-gpu-arch=sm_35 -c b.cu;
4) Link instrumented-a.device.bc with the device code generated for b.cu: llvm-link intrumented-a-device.bc b-cuda-nvptx64-nvidia-cuda-sm_35.bc -o ab-device.bc;
5) Use llc, ptxas & fatbinary on ab-device.bc to get ab-device.ptx, ab-device.o & ab-device.fatbin;
6) Call clang again the generate the host object file ab.o, with ab-device.o & ab-device.fatbin embedded;
7) Link against libraries and get the final binary: a.out.


The binary a.out fails with an exception I when run it; but when I try to debug it with cuda-gdb or cuda-memcheck, no source information was available.  Why?


Thanks!
Yuanfeng Peng
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170614/1bfdd28e/attachment.html>


More information about the llvm-dev mailing list