im a newer ,and i wanna to know may malloc mem on device ,thanks.and why.
No, you cannot dynamically allocate memory from device code. However, you can preallocate a large chunk of memory and write your own routines that allocate and deallocate from this space.
not using ‘malloc’ as such, use ‘cudaMalloc’, this will allocate memory that exists on the device.
i.e.
float* device_buffer;
CUDA_SAFE_CALL(cudaMalloc((void**)&device_buffer,number_of_elements*sizeof(float)));
remember, you cannot directly access this memory on the host without copying over it first.