Disable register optimizations / "value optimized out" problem


is there any possibility to completely turn off those optimizations, that produce the “value optimized out” errors when printing a variable while debugging with cuda-gdb? I tried

nvcc -g -G -O0 -Xcicc -O0 -Xptxas -O0 -maxrregcount 0

an I wrote “volatile” before every variable declaration in the code but I’m still getting “value optimized out” in the debugger. Is it correct, that this message appears because the variable value isn’t “live” (= stored in registers)? And how can I prevent the compiler from storing variable values in registers then?

Thx in advance

Currently it is not possible to avoid those messages with compiler switches. You may use prints at the end of your kernel to print the value - this way the compiler will be forced to keep the variable around for longer.


thanks for your reply. Yes, I’m aware of the fact that you can use some workarounds to get the variable values (printf or some useless assignments that prevent the compiler from optimizing these values out). But I was hoping that there’s a possibility to see every variable in the debugger without changing the code (because that’s what debuggers are for, right?). If I have to use printf anyway, I don’t need a debugger…

I have a similar problem. I was trying to run merge sort which is from CUDA SDK in the debug mode. There was a function called binarySearch in that kernel thats been called many times. The fact is, whenever I try to read value of the variables in that function, I got value optimized out. For example, I try to see what the return value of the binary search is but I can never see it through the debugger. In the Makefile if I understand correctly that if I use -g -G, there would be any O options added.

This is a common problem. The compiler could save all the variables to memory all the time to make sure no variable is optimized out, but, by doing so, some applications could run out of memory. Those applications would run properly at -O2 but fail at -G -g. Moreover, the applications would be noticeably slower.

The next release of the CUDA toolkit (after 5.5) will include several changes to mitigate the issue though. The number of “liveness holes” should be reduced.

Has this issue been addressed? I use Cuda 7.5 and have put the -g -G parameters in my Makefile.

I see a SIGSEGV in a printf () statement in the kernel and it crashes there while I attempt to dereference a pointer stored in a local variable. cuda-gdb says variables are optimized out.