OpenCL do not support variable arrays in kernel. size must be know at compile time.
If the pointer size is known at runtime, create a global memory object and pass that in instead of using private memory.
I have a similar problem that should have a simple solution. I too want to be able to use kernels with varying width arrays, though I know the size when I complie the kernel. I had an idea to simply use a #define in my main code so that I only have to change the code in one place while wroking on it. However, the kernel will still not comiple. I find this strange as a #define is constant.
What I have done is simply #include "GlobalConstants.h" in the kernel. It does not complain about not finding the h-file. In the h-file I have "#define array_width 32". Still. using array_width in the kernel does not work as it is not viewed as constant. I can not see why this does not work. Am I doing something wrong or is there a reason why this approach will not work either?
do you specify include dir via -I parameter in clBuildProgram()? i pass whole kernell as #include file and my kernel which i pass to clCreateProgramFromSource is only one #include "some_file.cl"
whole source code is then in include file.
another option is pass -D array_width=32 to clBuildProgram()
Please provide a test case to replicate the problem.
Thanks nou! I didn't know I could do that. A tip for anyone else who wants to try the same:
"-D array_width=%d\0" works
"-D array_width = %d\0" does not work.
I'm using sprintf, where %d is a #define macro so that I can simply change the macro when performing some benchmarktests.
I still have a problem though...
const uint filter_size = array_width / 2;
__local float4 filter[filter_size];
does not work. When compiling I recieve:
"error: expression must have a constant value" and a " ^ " pointing at filter_size. I find this strange as everything should be seen as constant, or am I missing something?
Again, thank you for your help!
(sorry for the code below, I can't seem to remove it once I pasted it in)
const do not make variable constant expression. you can compute value of const variable at run time so compiler can't consider value of filter size as constant expression.
even const int filter_size = 16; will not work.
try #define filter_size (array_width/2)
that bracket are just for sure.
It worked! Thanks a lot! Its small things like this that make OpenCL more tedious than CUDA for me. But I'm set on learning doing things the AMD OpenCL way.
Again, thank you for your help. Much appreciated.
Oh, and a quick tip for anyone who wants to write several preprocessor options such as several constant variables. write:
"-D array_size=16 -D filter_size=32" and so on. No commas or new lines.
If you have issues that you think should be improved, please provide a quick test case and a reason why you think it should be fixed and we will look into the issue. If we decide that your issue is valid, we will fix it in our upcoming release.
OK! Thanks. Will do if I come to think of anything that isn't simply a cause of me being a novice.