I am just beginning CUDA and C and I am trying to do simple addition. When I try to print the result, I am getting the following as output: " 3 + 4 is 1"
To compile the code, I am running the command "nvcc test.cu" which generates a.out
Thanks for your help.
Here is test.cu:
#include <stdio.h>                                                                                 
__global__ void add(int a, int b, int *c){                                                         
         *c = a + b;                                                                                
}                                                                                                  
int main(){                                                                                                                                                                                         
        int a,b,c;                                                                                 
        int *dev_c;                                                                                
        a=3;                                                                                       
        b=4;                                                                                       
        cudaMalloc((void**)&dev_c, sizeof(int));                                                   
        add<<<1,1>>>(a,b,dev_c);                                                                   
        cudaMemcpy(&c, dev_c, sizeof(int), cudaMemcpyDeviceToHost);                                
        printf("%d + %d is %d\n", a, b, c);                                                        
        cudaFree(dev_c);
        return 0;                                                                                  
}  
 
     
    