Problema with EmulationMode and NotEmulationMode

Hi. I’m new of Cuda. Sorry for my bad english, however…

I write an simple code:

[codebox]global void AssegnazioneIntero(int* interoDaAssegnare, int intero_cuda)


*interoDaAssegnare = intero_cuda;


int main(int argc, char* argv)


int intero = 0;

AssegnazioneIntero<<<1,2>>>(&intero, 10);

return 0;



In emulation mode this code assign to variable “intero” value “10”. This is correct solution

In NOT emulation mode this code assign nothing value to variable “intero”. After the call function “AssegnazioneIntero” the variable “intero” has value 0.

Why? Why don’t enter in cuda code in NOT emulation mode? Enter but not work in good way? I wrong something?

Dear DrGonzo,

After looking your source code, I think that the mistake you are doing has to do with the variable declaration for the CUDA device. Keep in mind that the CUDA device (GPU) and the CPU do not share the same memory, but the GPU and CPU have their own separate memory which each can only access. So I think that in your case you should declare a pointer, lets say * intero_d (d for device) you should allocate some memory space for it on the GPU memory using cudaMalloc ( (void **) &intero_d , size), where size is the intero_d’s size in bytes and can be found using the sizeof() function and you should also copy your intero value (which resides on the host/CPU memory) to the CUDA memory address intero_d pointer is pointing, using cudaMemcpy (for more information look in the CUDA programming guide). After that you should call the CUDA kernel using the intero_d pointer since this pointer points to a value on the GPU’s RAM. The result should be stored somewhere (either you can store it to the *intero_d , or you can use an other pointer, but remember that you will have to allocate space for it too). Also dont forget to tranfer back the results from the CUDA device to your host CPU memory using the cudaMemcpy command again.

I am a new user to CUDA too, so I would suggest you to take a look here ( There is a similar CUDA program which accesses and modifies array elements and has alot of explanations about every step of the CUDA code. I believe that after reading it you will be able to solve your problem.

Hope this helps.

THANK YOU. You save me. However i don’t understand because in emulation-mode code this code work in good way. It must give me error, otherwise is useless.

I think that emulation-mode serve to debug in cuda-code to see the error-code, and then…when the code is correctly… start code in NOT emulation-mode to see performance.

If emulation-mode operate in different mode to NOT emulation-mode don’t help the programmer to see error…

Don’t you believe?

Sorry for my bad english… :whistling: