lokstok
lokstok

Reputation: 241

CUDA: Using shared memory across different kernels

Is this possible?
I am trying to define a shared memory array in one kernel and then I need to use those values in a different kernel.

I tried declaring the

extern __shared__ float sharedMem[];

outside all functions and then wrote to it in one kernel and tried to access it in a different kernel. The sharedMem array is written to properly in the first kernel, but when I try to access it in the second kernel, the values are all 0. So I am guessing this won't work or I am doing something wrong.

Can someone please help me out on this?

Upvotes: 3

Views: 2321

Answers (1)

jmilloy
jmilloy

Reputation: 8355

You are correct, shared memory does not persist across kernel calls. Instead you must use global memory (or texture memory) and load it into shared memory in each kernel call.

Upvotes: 4

Related Questions