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;
}