0

In CUDA, when I delcare an array in constant memory like below

__device__ __constant__ float A[n];

does the size n need to be a constant?

I guess is yes, because the compiler needs to know if the size n exceeds the constant memory size or not. Is that right?

einpoklum
  • 118,144
  • 57
  • 340
  • 684
chaohuang
  • 3,965
  • 4
  • 27
  • 35

1 Answers1

3

Yes, it needs to be constant. The reason for this is that it is a static allocation, so the compiler needs to know the size at compile-time.

And, yes, the compiler does check the size against what is available.

Community
  • 1
  • 1
Robert Crovella
  • 143,785
  • 11
  • 213
  • 257