I want to use values in shared memory over multiple launches of the same kernel.
Can I do that?
3 Answers
No, you can't. Shared memory has thread block life-cycle. A variable stored in it can be accessible by all the threads belonging to one group during one __global__
function invocation.

- 1,809
- 1
- 12
- 12
-
2Shared memory has block scope life-cycle, not kernel scope. – talonmies May 16 '12 at 03:23
-
1@talonmies, Thanks! Sorry, I mean the same thing but was mistaken in terminology. I mean that instead of global memory( actual while you don't call cudaFree) there are no way to get variable between global function calls. – geek May 16 '12 at 06:11
Take a try of page-locked memory, but the speed should be much slower than graphic memory. cudaHostAlloc (void **ptr, size_t size, cudaHostAllocMapped); then send the ptr to the kernel code.

- 30
- 2
Previously you could do it in a non-standard way where you would have a unique id for each shared memory block and the next kernel would check the id and therefore carry out required processing on this shared memory block. This was hard to implement as you needed to ensure full occupancy for each kernel and deal with various corner cases. In addition, without formal support you coulf not rely on compatibility across compute device and cuda versions.

- 1
- 1