global void foo(int &a)
{
a = 10;
}
Does “a” have multiple copies? Only one copy shared by all threads or one copy per thread?
If I modify “a” in the kernel, what will happen? For example:
int x = 1;// a variable in CPU Memory
foo<<<10,10>>>(x);// x = 1 or 10?
Does this means compiler will generate code that will automatically copy the “x” to GPU Memory and copy it back after the kernel execution?
-
Another similar situation:
struct Bar
{
int temp;
Bar(int i){temp = i;}
device int operator()(int *array)
{
array[threadId.x] = temp;// we use “temp” in a device function
}
};
This code seems work well. Does this mean “temp” is automatically copied to the GPU Memory?
Does CUDA thread has its local stack for parameters passing?
Thanks!