After looking at CUDA examples and at the manual, I still don’t find it clear when a variable is in device or host memory.
I would appreciate if you correct me if I’m wrong on the following examples:
Example 1:
float array;
cudaMalloc( (void **)&array, 10sizeof(float) );
means that “array” is allocated on the device (global memory) and read/writable from both device and host?
Example 2: device float array;
cudaMalloc( (void **)&array, 10sizeof(float) );
means that “array” is allocated on the device (global memory) and read/writable ONLY from device?
Example 3:
float *array;
array = (float )malloc( 10sizeof(float) );
means that “array” is allocated on the host and read/writable ONLY from host?
I suspect that you sometimes use it to help the compiler determine what exactly a variable is. Just a guess. Depends on what you’re doing, whether you’re declaring a function or a variable.
personally, I have never used the device qualifier. To find out what it does, I would check the programming guide, but I also think it is probably just a compiler hint.