PDA

View Full Version : initialize global variables



sanderbeckers
03-18-2011, 03:44 AM
Is there any way to initialize a global variable with a value that is passed on from the host?
The reason is that otherwise you need to pass the variable as an argument to every function which uses it, meaning that functions will have a huge amount of arguments. Also, it seems intuitive that it would slow down the program if the host has to pass on the variable each time a kernel uses it.
A simple example is:

host code:
y=1;

device code:
__constant int x=y;

__kernel void func()
{
int z;
z=x;
}

david.garcia
03-18-2011, 05:46 AM
No, it's not possible. Variables at global scope must be initialized with literals. In order to have __constant variables whose value comes from the host you need to pass them as kernel arguments as you say.