Changing from float to double generate wrong result Help needed, I am frustrated

It’s not caused by conversion since I change all the variables together with the constants and there’s no conversion from integer to float/double. And I am sure it’s not because of the small difference made from functions like sin() or pow(). The wired thing is if I compile with the debug option (-G) or emulation mode, it gives correct result. It’s beyond my knowledge. Anyone can point me what kind of thing may cause this problem? Thx.

I am using CUDA 2.3 with driver 190.18 under Ubuntu 9.04 64bit. The card is a 295GTX.

I am wondering if it might be related to the bug found in the driver. It happened to me once that even cudaMalloc can’t run and reboot bring it back to normal.

[topic=“97379”]cuda 2.2 bug?[/topic]

How exactly is the result “wrong”?

Some thing like:

F_dd[i]=F_dd[i]+Fn+Fs; gives 291.0 when using nvcc -G or float variables compare to 500.4 when using nvcc and double.

Although I can identify which part of the code goes wrong ( the above line), it’s very unlikely the line itself cause the problem since I’ve using it for a long time on CPU version.

F_dd is defined as:

VecR *F_dd

cudaMalloc((void *) &F_d,3(N+1)*sizeof(double));

and Fn Fs is also defined as VecR inside global function

Where VecR is define like:

host device class VecR



    double x;

    double y;

    double z;

host device VecR operator +(VecR vb)


    VecR result;

    result.x= x+vb.x;

    result.y= y+vb.y;

    result.z= z+vb.z;

    return result;



Thanks for reply.

are you compiling with -arch sm_13?

Your problem seems close to this one:

[topic=“103726”]different output when compiled for emulation, device, and device with -g -G[/topic]

So you can try the proposed workaround (-Xopencc -O0) and see if it helps…

(maybe I should bet something real this time, like a beer ;))


It works! I really appreciate. I own you a beer.

And thanks for all you guys.