can i do my memory transfer in a separate function

Hello i am trying to do my memory transfer in a different function and use them in my actual kernel call which is in different function, but i am not able to do this. the program quits abnormally.
can any one help me by telling me what to do.


You treat the memory allocations on the device just as you treat “regular” allocations on the cpu with new/malloc.

Just allocate the data on the device, keep the pointer somewhere in a global parameter/structure and pass it around any function you want.

oh… and remember to free it (like you do with delete/free) ;)


If your application is multithreaded, make sure your memory allocation happens in the same thread than the one making the kernel call.

Consider the GPUworker class for this purpose, you will find it on these forums.