[resolve]It will be wrong to divide the result by using the variable

Example

__global__ void test(double *result)
{
	/*double num1 = 424;
	double num2 = 112;*/
    *result = 424.0 / 112.0; //<--- there
 }

int main()
{
	double result, *dev_result;
	cudaMalloc((void**)&dev_result, sizeof(double));
	test<<<1, 1>>>(dev_result);
	cudaMemcpy(&result, dev_result, sizeof(double), cudaMemcpyDeviceToHost);
	cudaFree(dev_result);
	printf("%.16f\n", result);
	system("PAUSE");
    return 0;
}


It will be right for the result of 3.7857142857142856.

Example 2

__global__ void test(double *result)
{
	double num1 = 424;
	double num2 = 112;
    *result = num1 / num2; //<---there
 }

int main()
{
	double result, *dev_result;
	cudaMalloc((void**)&dev_result, sizeof(double));
	test<<<1, 1>>>(dev_result);
	cudaMemcpy(&result, dev_result, sizeof(double), cudaMemcpyDeviceToHost);
	cudaFree(dev_result);
	printf("%.16f\n", result);
	system("PAUSE");
    return 0;
}


But changing to use the variable, it will be incorrect for the result of 3.7857143878936768.

3.7857142857142856 //right
3.7857143878936768 //incorrect

why?

Environment
OS : Windows 7 64bit
CUDA version : CUDA 5.5
graphics card : Nvidia GTX650
programming software : visual studio 2010

I get the same (correct) result either way, compiling for a cc2.0 device. What OS are you using? What is your compile command? What is your CUDA version?

My guess is you are on windows, and are compiling for a cc1.0 - cc1.2 architecture, which is giving you a message when you compile:

warning : Double is not supported. Demoting to float.

In that case, there is a difference between the 2 formulations.

If you compile for cc1.3 or newer architecture, you will not get that message, and you will see no difference numerically between the two cases.

Environment
OS : Windows 7 64bit
CUDA version : CUDA 5.5
graphics card : Nvidia GTX650
programming software : visual studio 2010

and I have warning : Double is not supported. Demoting to float.

what should I do?

Your device is cc3.0 capable. Change the code generation target to one that includes cc3.0, and rebuild your app.

This question/answer:

http://stackoverflow.com/questions/14411435/how-to-set-cuda-compiler-flags-in-visual-studio-2010

shows how to modify the code generation target. (Don’t use the method indicated in the question - it is wrong. That is why the question was asked. Use the method indicated in the answer given by RoBiK.)

Change that setting to “compute_30,sm_30”

And if you want to remove the demotion warning, remove any other entries, if there are any.

thank you