minimizing data transfers from cpu to gpu

I want to copy an array to gpu the first time a kernel is called,and from thereon I just want to change one element of the array(from host), every time the kernel is called.I am new to CUDA C.Can you please suggest me a way out ?

You can use mapped memory so that host and GPU can operate directly on the array without having to copy the array back and forth. Something like


var_type *ptr_array_on_host;

var_type *ptr_array_on_GPU;


tAllocMapped);//allocates memory on host side visible to GPU, replacing a malloc or calloc memory allocation on host side

cudaGetDevicePointer((void *)ptr_array_on_GPU,(void)ptr_array_on_host,0);//gets GPU pointer to host side memory


//call kernel

while (something)





That should do it. Though you need have a device capable of allocating mapped memory, reading the device properties should show you if it is possible. Anyway a good option is to browse through Dr. Dobb’s tutorials on CUDA Dr Dobbs on mapped memory