Problem with "shared" dinamic arrays

Hello!
I write kernel and I have one problem with “shared” dinamic arraysl.

__global__ void calculate(int size, int N, float* a){
	__shared__ float arr[N*2];
//somework
}```

It returns error:
Exception in thread "main" java.io.IOException: Could not create .ptx file: fft-simple.cu
fft-simple.cu(3): error: expression must have a constant value

Please, help me. How I can create this array? The value of N defines in Java Code.

Hello

You can add this as a constant by passing it as a ‘defined’ value to the NVCC (or the KernelLauncher, which you may be using) - For example, you may call this…

k = KernelLauncher.create(fileName, functionName, true, "-DMY_SIZE=123"); // Add -D... parameter here

and then use MY_SIZE in the kernel like this:

extern "C"
__global__ void calculate(int size, float* a){
    __shared__ float arr[MY_SIZE*2];
...

Just from the tip of my head, if it does not work, I’ll have another look at this any possibly post an example.

bye

Thank you very much, Marco!
It resolved this issue. And you teached me how to create constants :wink:

You can also create constants with the “const” or “constant” keywords, but you cannot declare arrays with them!