Search code examples
c++ccudagpu-shared-memory

allocating shared memory


i am trying to allocate shared memory by using a constant parameter but getting an error. my kernel looks like this:

__global__ void Kernel(const int count)
{
    __shared__ int a[count];
}

and i am getting an error saying

error: expression must have a constant value

count is const! Why am I getting this error? And how can I get around this?


Solution

  • const doesn't mean "constant", it means "read-only".

    A constant expression is something whose value is known to the compiler at compile-time.