cudaMemcpy / cudaMalloc

Sorry for my english…
I have in a kernel’s function with cudaMemCopy:

cudaMemcpy(hackbuff, header, sizeof(char)*12, cudaMemcpyDeviceToDevice);

and i have the error:

calling a host function from a device/global function is
only allowed in device emulation mode
cudaMemcpy(hackbuff, header, sizeof(char)*12, cudaMemcpyDeviceToDevice);

i can’t call cudaMemcpy or cudaMalloc in the kernel function?

Thanks

Obviously you can’t. cudaMalloc-kind of functions are run on CPU and call driver to allocate memory on GPU. Kernel is invoked in SIMD multiprocessor on GPU that supports only low-level instructions (memory, math, branching emulation, etc).

So you either reserve large enough buffers in global memory and pass the pointer to your kernel and then you have to manage memory yourself or use undefined length shared memory arrays…

In short, read development guide more carefully and use principle - what is not described - is not allowed ;-)