Why wouldn’t it be possible? of course it is… thats what tmurray said - its just like malloc/free or new/delete in regular c/c++ code.
The question is, and I think no-one really understands what you really ask, is why do you ask this? or what you’re tring to
With every “copy memoryX back to CPU” you’re PCI-e bounded and this might be your bottle-neck.
Question is why you need this and if it can be avoided… otherwise you’ll have to pay this device->host penalty.
edit- oh, one more potentialy misconception. You dont allocate/free memory from within the kernel code. You do it
outside the kernel, on the host side and then pass the device pointer to the kernel to operate on it.