I get “warning: Variable is not live at this point. Returning garbage value.” in cuda-gdb while examing a variable pointer that was passed as parameter.
Basically I do this:
[font=“Courier New”]float a;
foo(&a);[/font]
Then when stepping into [font=“Courier New”]foo()[/font], “[font=“Courier New”]print a[/font]” and “[font=“Courier New”]print *a[/font]” give a warning.
The local variable can also not be printed after returning from the function.
The following program works correctly and prints “10”.
[codebox]#include <stdio.h>
#include “cutil_inline.h”
device void foo(float *local) {
*local = 10;
}
global void TestKernel(float *result) {
float local;
local = 5;
foo(&local);
*result = local;
}
int main(int argc, char** argv) {
cudaSetDevice(cutGetMaxGflopsDeviceId());
float *result_d;
cutilSafeCall(cudaMalloc((void**)&result_d, sizeof(float)));
TestKernel<<<1, 1>>>(result_d);
cudaThreadSynchronize();
float result_h;
cutilSafeCall(cudaMemcpy(&result_h, result_d, sizeof(float), cudaMemcpyDeviceToHost));
printf("%g\n", result_h);
cudaThreadExit();
return 0;
}[/codebox]
Compiled with:
[font=“Courier New”]nvcc -gencode arch=compute_20,code=sm_20 -g -G \
-I~/NVIDIA_GPU_Computing_SDK/C/common/inc/ \
test.cu -o test.cuda[/font]
[codebox]Breakpoint 1, TestKernel <<<(1,1),(1,1,1)>>> (result_d=0x5120000) at test.cu:10
10 local = 5;
(cuda-gdb) s
[Current CUDA Thread <<<(0,0),(0,0,0)>>>]
TestKernel <<<(1,1),(1,1,1)>>> (result_d=0x5120000) at test.cu:11
11 foo(&local);
(cuda-gdb) p local
$3 = 5
(cuda-gdb) s
[Current CUDA Thread <<<(0,0),(0,0,0)>>>]
TestKernel <<<(1,1),(1,1,1)>>> (result_d=0x5120000) at test.cu:5
5 *local = 10;
(cuda-gdb) p local
warning: Variable is not live at this point. Returning garbage value.
$4 = (const @global float * @register) 0x4
(cuda-gdb) s
[Current CUDA Thread <<<(0,0),(0,0,0)>>>]
TestKernel <<<(1,1),(1,1,1)>>> (result_d=0x5120000) at test.cu:12
12 *result_d = local;
(cuda-gdb) p local
warning: Variable is not live at this point. Returning garbage value.
$5 = (const @global float * @register) 0x41200000
[/codebox]
[font=“Courier New”]/proc/version
Linux version 2.6.18-194.3.1.el5 (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)) #1 SMP Thu May 13 13:08:30 EDT 2010
/proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module 195.36.24 Thu Apr 22 19:10:14 PDT 2010
GCC version: gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)[/font]
CUDA SDK Version 3.0 Release
R195 Driver Release
Videocard: GTX 480