simply put:
__device test(int x)
{
x++;
}
//kernel code:
r1 = 0;
test(r1);
// does r1 = 1 or r1 = 0 after this call?
simply put:
__device test(int x)
{
x++;
}
//kernel code:
r1 = 0;
test(r1);
// does r1 = 1 or r1 = 0 after this call?
Seriously? The standard C argument model applies, of course.
I’m not sure, but i think if you need to do something like that you need to use a int pointer. Do something like this:
simply put:
__device test(int *x)
{
*x++;
}
//kernel code:
int r1 = 0;
test(&r1);
The compiler understands pass by reference. You can make the parameter int &x if you want the parameter to be modifiable, but without the ugly pointer dereferencing.
So if I understand correctly the right away of doing this operation is:
__device test(int x)
{
x++;
}
//kernel code:
int r1 = 0;
test(&r1);
Is that it?
No. C++ introduced the concept of references so that pointer dereferencing is not required for modifiable arguments. So the function definition becomes
__device test(int & x)
{
x++;
}
Any good reference book on C++ (I like Stroustrup’s “The C++ Programming Language”) has lots of detail on the semantics of references.
I have problems with call-by-reference in CUDA 2.2 (look here: forum entry).
Can anybody please try to confirm this?
Thx,
Marcel