View Full Version : Passing a global parameter from kernel into a function

01-29-2013, 06:00 AM
I'm just playing around with OpenCL and trying to get some simple c++ routines adapted for opencl.

Basically - i'm trying to do something of the kind:

// function prototype
int CL_TestFunction(float2 *pts)

// opencl kernel
kernel void CL_TestKernel(global float2 *pts)
// so let's do some stuff
int id = get_global_id(0);
// blah
float x = pts[id].x;
float y = pts[id].y;
// and then let's use a c style function, which passes in the array of float2
int num = CL_TestFunction(pts);

int CL_TestFunction(float2 *pts)
// do some things in here:
return 0;

Now - the problem i'm getting is when i try passing in the pts array into the CL_TestFunction. I get a build error.
When i've used other functions, which don't use the global parameters, it's absolutely fine (to my knowledge anyway).

So - i'm guessing that i'm unable to do this. So - is there a way around this? I imagine i'm missing the point somewhat in regards global variables etc, so any help would be really appreciated.
The code i'm working on is a lot more complicated than what i've displayed above, so there are good reasons (to me) for trying to pass the pts array.

Hope that makes some sort of sense.

01-30-2013, 12:02 AM
Ran into the same problem without any solution. I think it is because this funktion will loose the qualifier global. But I'm not really shure. I think i found someting in the spec, regarding that topic

01-30-2013, 01:38 AM
Your function should be declared as "CL_TestFunction(global float2 *pts)"

Without an explicit address space qualifier, a pointer is considered as private, so "CL_TestFunction(float2 *pts)" really means "CL_TestFunction(private float2 *pts)".

01-30-2013, 02:34 AM
Thanks, i got that to build!

Now to sort the rest of it out :)