2 + 7 = 57 Wrong calculation

Hi All,

I just started CUDA C programming on CentOS ( 64-bit), CUDA 2.3. I go with well known example of CUDA by examples book. The code is below. The problem is here. One I make 2 + 7, it shows 57. Output of this code is here.

[I@cuda_test]$ ./add_num

2 + 7 = 57

What could be the problem in my code/system/settings?

I suspect that there is a char-int data-type problem. It is because ascii for ‘9’ is 57.

Any help would be appreciated.

#include <stdio.h>

__global__ void add( int a, int b, int *c )

{

	*c = a + b;

}

int main( void )

{

	int c;

	int *dev_c;

	cudaMalloc( (void**)&dev_c, sizeof(int) ) ;	

	add<<<1,1>>>( 2, 7, dev_c );	

	cudaMemcpy( &c, dev_c, sizeof(int), cudaMemcpyDeviceToHost ) ;	

	printf( "2 + 7 = %d\n", c );

	cudaFree( dev_c );

	return 0;

}

Do you test CUDA 4.0?

your code works on my system, Fedora10 x86_64, CUDA 4.0, sm_20

I just figured out that I was using an emulator. This could be a problem. I have a tesla c1060, but I am not a superuser on the system. I need to talk the admin soon.

Thanks…