PDA

View Full Version : Global variables in OpenCL



Considerate
05-01-2010, 09:32 AM
Hello,
I was wondering, is there any possibility to use global variables in OpenCL that are consistent over several functions called from the kernel?

Let me give you an example of what I'm looking for.


uint numObjects;

__kernel mainKernel
(__global uint numberOfObjects,
/* other variables */
)
{
numObjects = numberOfObjects;
}


void doSomethingElse
(
/* variables */
)
{
int i;
for(i = 0; i < numObjects; i++)
{

}
}

I'm asking this because otherwise I have to send the variable through many functions as the doSomethingElse() function is supposed to be called from a different function and not the kernel itself.

Thank you.

//Considerate

affie
05-03-2010, 03:12 PM
Global variables can be declared in program source but they must use the "constant" address space qualifier and need to be initialized. You cannot have global variables that can be modified by kernels and where the modified values are persistent across work-groups and kernel executions. For this, you should use memory objects instead.