I have an OpenCL code that works perfect on my MAC. But when I port it to an EC2 g2.2xlarge instance, it gives the
Exception
ERROR: clBuildProgram(-11)
Now after a lot of debugging, I found out that the kernel has a syntax error. After narrowing it down further, I found that the error is in the following line:
int size_a = POP_SIZE / 4 / numberOfDevices;
int aliveIndividualsIndex[size_a];
If I try:
int aliveIndividualsIndex[40];
then it works on the EC2 Instance too.
Why is there a difference between how a MAC and EC2 instance are handling the same kernel code? Why is one of them recognizing the code and why is the other one giving a syntax error? How do I fix it? Because I need to use [size_a].
Both of them are using OpenCL 1.2. If you need any more information about the versions of gcc or g++ or anything else, please ask, I'll provide them.
The size of arrays within OpenCL kernels should be known at compile time. As such, to solve your problem, make
numberOfDevices
a compile time constant by passing it to the build options of the clBuildProgram() function with the"-D name=definition"
option, e.g.:It may also be necessary to make
size_a
a constant in your kernel source code, e.g.:You can now declare the array within the kernel: