Creating a shared vector with block size?
I need to create a shared vector, with the same size as the block.
__global__ func()开发者_StackOverflow
{
const int size = blockDim.x;
__shared__ float* Vec[size];
..
}
I get this error
error : expression must have a constant value
I cannot understand where is the problem, sinceblockDim.x
is "constant" for each block threads??
Here's how you do it
_shared_ float Vec[size];
remove the star (*)
As far as I know, CUDA does not support variable length arrays (which is what you're trying to do here, regardless of the presence of the keyword const
).
If you look at section B.16 of the CUDA C Programming Guide, there's some text on how to specify a size for an extern
declared shared array. Although it's a bit more complicated, this is the syntax on how to specify execution-time sized shared arrays. The way you're doing it won't work.
You have to have a compiler that supports C99 to use variable-length arrays. It would seem your compiler doesn't support VLAs, so you have to have an integer constant expression for your array size.
精彩评论