CUDA: using realloc inside the kernel

I know what the kernel can use mallocto allocate memory in the global memory of the GPU. Can I use it realloc?

+3
source share
2 answers

In the Cuda Programming Guide, when they introduce functions mallocand freeis not mentioned realloc. I would suggest that it does not exist.

If you want to know this for sure, why don't you write a simple kernel and try to use it?

+3
source

You can write your own realloc device function for your data type.

Just allocate a new space for the new array, copy the old values ​​to the new one, free up the space of the old array, return the new one with more space.

, :

__device__ MY_TYPE* myrealloc(int oldsize, int newsize, MY_TYPE* old)
{
    MY_TYPE* newT = (MY_TYPE*) malloc (newsize*sizeof(MY_TYPE));

    int i;

    for(i=0; i<oldsize; i++)
    {
        newT[i] = old[i];
    }

    free(old);
    return newT;
}

, . .

+3

All Articles