I have some general parameters declared as a global (__constant) struct, like so:
typedef struct
{
int a;
int b;
float c;
/// blah blah
} SomeParams;
__constant SomeParams Parameters;
in the kernel, I need to use it like so:
__kernel void Foo()
{
int a = Parameters.a;
/// do something useful...
}
I’m not sure how I can initialize the value of Parameters from the host before I execute the kernel.
I have no problem creating buffers, etc for kernel arguments, but since this isn’t a kernel argument, what do I need to do?
I’m using the Cloo C#/OpenCL bindings, but even a raw CL API would be helpful.
As far as I know (but I wouldn’t swear by this), you can’t initialize variables from the host code that are declared in that way (with one exception, see below). You could declare a variable and initialize it like this:
You could also do something like this:
Kernel:
__constant float width = WIDTHHost: Build the kernel with a
-Dbuild parameter defining the value ofWIDTH.What I have done in the past is have the constant variable as a kernel parameter.
Then you can allocate and set the value just like any other kernel argument.