want to allocate memory inside kernel


I have an application in which I need to allocate memory inside kernel as and when some thread needs it. but as it turned out cudaMalloc cannot be used as it is a host function. So can anyone suggest that how to do that.

You can’t. Since this is a very common question, maybe you could please explain in greater detail why would you need such a feature?

You can static allocate array inside kernel, this array will allocate in local memory. but you can not dynamic allocate memory inside kernel (by using cudaMalloc() or some functions like this).

for example:

[b]global void kernel(…) {

int array[100];


This array has 100 integer elements and allocated in local memory.