hi everyone, i just started learning cuda…
i want to define a variable on the device memory so that i can use in my kernal
so my host function contains … the following line
int main(int argc, char* argv)
{
//////////// device int correctBool = 1 ;
/////////////////////
}
i got the following error while compilng…
[b]error[/b]: a function scope variable cannot be declared with "__device__" inside a host function
[b] error[/b] : a "__device__" variable declaration is not allowed inside a function body
can anybody help me out with this…
it may be the most trivial thing for u guys…
but i’m stuck…
thnx in advance…
For values which won’t change, declare them constant at file scope. For variables that could change, you can declare global memory symbols at file scope and read their addresses and update their values via the symbol runtime api functions. Both are discussed in the programming guide,
int main(int argc, char* argv)
{
correctBool = 12; // This assignment should not work for a variable allocated in device memory, but now it is working.
cudaMemset(&correctBool, 0, sizeof(int)); //Memset will fail
if (cudaSuccess != cudaGetLastError())
{
printf("Memset Failed\n");
}
}
Which means ‘correctBool’ is not getting allocated in device memory using this method.