Pointer arithmetics and cudaMemcpy


i want to transfer data between two memory blocks using cudaMemcpy:

   void* hostMem;

    ::cudaMallocHost(&hostMem, 10);

    void* devMem;

    ::cudaMalloc(&devMem, 10);

   ::cudaMemcpy(((char*)(devMem))+2, ((char*)(hostMem))+5, 4, cudaMemcpyHostToDevice);

is it ok to mix host and device pointer arithmetics as in the example above or will i run into problems?

my first tests worked, but i just want to make sure…

thanks, tomschi

Tomshci -

This should be fine. Pointer arithmetic behaves very well with CUDA.

thanks for quick reply,

did i miss something about that in the CUDA manual or somewhere else?

Not sure. But CUDA is essentially enhanced C, so this will work just fine.

That being said, if you tried to dereference one of the device pointers, you would either get garbage, or you’d segfault. The pointers live in the host side, but the memory that the pointers point to lives on the graphics device.