accessing __device__ global variables

Hi,

It might be possible the following code?

device float var;

host void func1(){

float v=3;
cudaMemcpy(&var, &v, sizeof(float),cudaMemcpyHostToDevice);
}

global void func2(){

//Using var anyway…
}

The idea arises from using a global variable without calling
cudaMalloc. Is that possible?

Thanks!

var only exists on the device. You cannot take the address of var on the host. Use cudaGetSymbolAddress to get the address or use cudaMemcpyToSymbol.

Thank you!