4

how do I prevent cuda-gdb from optimizing out any value ( whether device or host, local or global )? I have checked nvidia forums but most of them are years old and there seems to be not a solution for old cuda versions, but is there one for the newest one (cuda 9.2 and sm 61)?

I am using flags described in nvidia's documentation:

-g - "Generate debug information for host code."

-G - "Generate debug information for device code. Turns off all optimizations. Don't use for profiling; use -lineinfo instead."

  • The only thing that should be necessary is a debug build. However, you will still need to inspect the variable when it is actually in scope. It is not necessarily in scope from the point at which it is declared. You may have to step forward until the variable is actually used in a meaningful way. – Robert Crovella Oct 16 '18 at 00:37
  • @RobertCrovella I have built using `nvcc` and and `-g -G` flags. Also, I have made sure i am in scope. Are there any other possible flags to turn off optimization? – Cucumber Mellon U. Oct 16 '18 at 00:42
  • none that I am aware of – Robert Crovella Oct 16 '18 at 00:45
  • I had the same problem. I specified "-G" in compilation flags, but a variable was still shown as "optimized out" in cuda-gdb. – Ziqi Fan Feb 07 '22 at 15:37

1 Answers1

2

how do I prevent cuda-gdb from optimizing out any value

The cuda-gdb is not optimizing anything; it is just interpreting the debug info that the compiler (nvcc) put into the binary.

If the compiler chose not to describe location of some variable, then there is nothing cuda-gdb can do to recover that info. This would generally be a quality of debugging info issue with nvcc.

It's possible that nvcc did describe the location you are after, but cuda-gdb is failing to handle that description, in which case it's a bug in cuda-gdb.

In either case, you can't really do anything about it, other than complaining to NVidia.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Are there any workarounds to prevent nvcc from optimizing out the values (other than the typical methods in g++ or gcc)? – Cucumber Mellon U. Oct 16 '18 at 05:06
  • @CucumberMellonU. Unless there are optimization flags you didn't tell us about, optimizing out the values likely has *nothing* to do with your problem. – Employed Russian Oct 16 '18 at 06:00
  • `nvcc -arch=sm_61 -std=c++11 --use_fast_math -maxregcount 128 inputFile.cu -lz -Xcompiler -fPIC -shared -o output.so` are all the flags. do you think any of these may cause all the values form being displayed? – Cucumber Mellon U. Oct 17 '18 at 00:47
  • @CucumberMellonU. Can you get your story to be self-consistent? Your question includes `-g` and `-G`, but these flags are missing from your "are all the flags" comment. Do you use `-G`, or don't you? – Employed Russian Oct 17 '18 at 00:57
  • Oh right, sorry. I took them out last night to check performence and forgot to include them here. `nvcc -arch=sm_61 -std=c++11 --use_fast_math -g -G -maxregcount 128 inputFile.cu -lz -Xcompiler -fPIC -shared -o output.so` – Cucumber Mellon U. Oct 17 '18 at 01:28
  • 1
    @CucumberMellonU. Ok, there is nothing "optimizing" about the flags you are using; my answer stands: (more likely) `nvcc` chose to not describe the variable, or `cuda-gdb` doesn't understand the description. – Employed Russian Oct 17 '18 at 02:26