Variable value changing mid-function

I have a device function that reads an array index from a global array to access another global array. The array index read in is maintained inside the function and is initially set to -1. This value is local to the thread and is not read by other threads. However, the global array is being accessed by other threads.

Although, the code initially reads in the correct value, in the middle of the function it gets reset back to -1 without the code explicitly doing so. This creates errors in the program causing it to end.

I am having difficulty getting cuda-gdb to break at this point.

The odd thing is the program runs with cuda memcheck with no error!

Any idea on why this is happening or how I can debug and figure out why this is going on?

Hi @user151847
Thank you for your report! Could you provide a bit more details to help us identify the issue:

  • Could you share the kernel code (or the minimal CUDA kernel example, which reproduces the issue)?

Although, the code initially reads in the correct value, in the middle of the function it gets reset back to -1 without the code explicitly doing so.

  • How do you detect that the array index (local variable?) is re-set to -1?

I am having difficulty getting cuda-gdb to break at this point.

  • Could you provide more details here? (e.g. log of cuda-gdb commands and command outputs)

Thank you for your response. Turned out that there was incorrect indexing leading to invalid memory accesses that were producing the incorrect values.

However, cuda-memcheck failed to detect these and I used if statements combined with cuda-gdb to debug.