PDA

View Full Version : Global writable parameters passing



jbasic
10-08-2009, 02:31 AM
How do you pass a parameter, that is one element of global array, so that the called function has ability to write back to that global element?


void Auxiliary(__global SomeStruct element)
{
element.something = ...;
}
__kernel void Kernel(__global SomeStruct *data)
{
Auxiliary ( data[get_global_id(0)] );
}

Is this valid :lol: ? Are variable references or pointer to one struct element available?
It's really ugly to pass the whole global array and item id to Auxiliary function...

dbs2
10-08-2009, 03:14 AM
As long as you keep the memory type (global, local, private, constant) in mind, you can just pass around pointers as you do in C. E.g., just pass the function a pointer to the struct and then de-reference it there.

jbasic
10-08-2009, 12:47 PM
Can I use the -> operator or I must do (*element).something ?

Are variable references available ?

void Auxiliary(__global SomeStruct &element)
{
element.something = ...;
}

(Sorry for asking, but I have to since I'm writing OpenCL code blindly, with no access to OpenCL enabled hardware to test it atm.)

dbs2
10-10-2009, 06:58 AM
I know both AMD and Apple have OpenCL that will run on your CPU, so you should be able to play around with it regardless of your graphics card. In general I suggest people start working with OpenCL on the CPU because it is far more forgiving for debugging. (And you can often get printf and a bit of gdb to work, although neither are officially supported.)

jbasic
10-10-2009, 10:20 AM
Unfortunately OpenCL (AMD/ATI's implementation) support X86 CPU w/ SSE 3.x or later. My historic Intel P4 doesn't meet the minimal requirement. And OpenCL specs are cheap on words considering pointers (or support of variable references) in OpenCL. Can you feel my pain?