using cuda shared memory several times

Hi,

I am trying to use same buffer several times, but get an error in cudamemcpy in the second attempt

I use a static variable:
unsigned char * g_ImgC = NULL;

and init it once:
if (g_ImgC == NULL)
checkCudaErrors(cudaMalloc((void**)&g_ImgC, size));

and then copy the memory to the buffer:
checkCudaErrors(cudaMemcpy(g_ImgC, ImgC, size, cudaMemcpyHostToDevice));

I dont call the cudaFree at all.

I saw that it really depends when I call the second memecpy,
if for example I call it on the same function, even after the kernel run, it works well,

but when the cu code function returns to the CPP code it will always fail,
looks like that the device is resting itself and memory inst used any more.

will appreciate an example of how it can be done.

Thanks!!

  1. Run your code under cuda-memcheck. It looks suspiciously like you have a problem inside your kernel rather than with the cudaMemcpy() - the cudaMemcpy() is just the first opportunity for CUDA to hand you an error code.
  2. Post a self-contained sample that reproduces the problem. From a vague description we can only play a guessing-game.