pointer as function parameters


Is there any way to transfer single variables from device memory to host memory without memcpy? Working with pointers as function parameters is not possible, ins’t it?

Thanks in advance!

Anything you can pass by value in C will be transferred to the GPU without a cudaMemcpy() call. This includes floats, ints, small structs (if you pass by value) and pointers. Note that when you call a global function with a pointer argument, CUDA is moving the address stored in the pointer to the card, not the memory the pointer points to. (There is a limit of 256 bytes for kernel arguments, so you can’t pass huge structs up to the card.)

Using pointers as function parameters is completely supported (and very common), but you have to pass device addresses, not host addresses. This is why a lot of CUDA code uses the variable name prefixes “h_” and “d_” to distinguish pointers which hold host and device addresses.