In my kernel function, I need to build an array. However, the size of this array is passed as a parameter from the host code. I could not name a constant for it since this value will be input by the users. And the code is somehow like:
__kernel void valuation(__global float *d_v, const int num)
const int num_ = num;
However, this doesn't work and it always gives a programbuild error. Any suggestions would be appriciated. Thanks,
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()
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.