memset on host

I have following code in my host function:

int P,Q;

P = SIZE; Q = SIZE;

Real* A;

A = (Real*)malloc(sizeof(Real)PQ);

memset( A, 0, sizeof(Real)PQ );

cuda_kernel<<<Dg,Db>>>(A);

free(A);

the kernel just simply set some value to A. I ran the code and saw the value been set to A successfully

then I comment the “cuda_kernel<<<Dg,Db>>>(A);” line from the code and execute the program again. I expect to see 0 as initial value of A but strangely I found A still holds the value that “cuda_kernel” gave it.

I think the memset function didn’t work in this case. But I really dont know why.

Could anybody give me an clue of this.

Thanks

This code should not work. You cannot pass a host pointer to a kernel. Very likely if you checked for errors after cuda_kernel, you would find an unspecified launch failure because of this. You should take a look at the programming guide again to see how the example program allocates and passes memory to the kernel.