JCuda global shared memory causing errors

182 views Asked by At

I'm trying to do something very very simple with shared memory in jcuda. My kernel:

__shared__ int testMe;

extern "C"
__global__ void test() {
  testMe = 5;
}

Making shared memory global allows me to use it in device functions, unfortunately, I can't even declare shared memory global. Cuda just crashes with kernel cannot launch issue. I've also tried doing:

extern __shared__ int test

However nvcc compiler gives, cannot externally link shared memory error. I really want to get this to work to make writing kernels easier, but I don't see a way.

1

There are 1 answers

3
Klaus On

You can't define static shared memory at translation unit scope, you have to declare it at kernel scope. If you do so, your shared memory will be the same memory for every thread in the same block. If you want to use memory that is same for every thread in all blocks, you have to use global memory (call cudaMalloc() in host-code and pass a pointer of the memory to your kernel).