View Full Version : Kernel improvement?

02-15-2013, 08:09 AM
I'm passing 2 global arrays of 2D points into my kernel, and then in the kernel, i'm accessing the global arrays multiple times (and passing them into other functions).

For example:

kernel FooBar(global float2 *array1, global float2 *array2)
int i = get_global_id(0);
int j = get_global_id(1);

float pt1x = array1[i].x;
float pt1y = array1[i].y;

float pt2x = array2[j].x;
float pt2y = array2[j].y;

// do some calcs

float ans1 = SomeFunction(array1);
float ans2 = SomeFunction(array2);

// and so on.........

Is it better to copy these arrays into local memory? How does one do this? Are there any limitations i need to know about (such as memory issues?).


02-20-2013, 06:44 PM
Local memory can be helpful if one or more work-items are reading from a location in global memory multiple times. In the specific example you posted it is not clear if it will help as the OpenCL compiler will most like replace the second call to array1[i].x and array2[j].y with the value already read by the first call to these array entries stored in a register.