Amin
Amin

Reputation: 381

How to use shared memory between kernel launches in CUDA?

I want to use values in shared memory over multiple launches of the same kernel.
Can I do that?

Upvotes: 1

Views: 1385

Answers (3)

fflannery
fflannery

Reputation: 1

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.

Upvotes: 0

perise
perise

Reputation: 30

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.

Upvotes: 0

geek
geek

Reputation: 1839

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.

Upvotes: 3

Related Questions