Receving Wrong Output for Simple Cuda Program -Newbie

Hi … I am a newbie interested in learning cuda, so I wrote a simple program to add two numbers. However, I am receiving the wrong output. I am receiving 0.

#include <stdio.h>
#include <cuda.h>

global void add(int *a, int *b, int *c){

*c = *a + *b;

int main(void){

int a,b,c;
int *devc, *devb, *deva;

cudaMalloc((void **) &deva, sizeof(int));
cudaMalloc((void **) &devb, sizeof(int));
cudaMalloc((void **) &devc, sizeof(int));

a = 7;
b = 2;

cudaMemcpy(deva, &a, sizeof(int),cudaMemcpyHostToDevice);
cudaMemcpy(devb, &b, sizeof(int),cudaMemcpyHostToDevice);

add<<<1,1>>>(deva,devb, devc);

cudaMemcpy(&c, devc, sizeof(int),cudaMemcpyDeviceToHost);
printf(“2 + 7 = %d\n”, c);

return 0;

If someone could offer a solution, it would be greatly appreciated.

Check return codes of all CUDA calls for errors. Most likely you kernel is not executed at all.

Maybe your CUDA install isn’t working properly. Can you run samples from the SDK?