I\'m new to CUDA/C and new to stack overflow. This is my first question.
I\'m trying to allocate memory dynamically in a kernel function, but the results are unexpec
I don't know anything about CUDA but these are severe bugs:
int**
to void**
. They are not compatible types. Casting doesn't solve the problem, but hides it.&d_numbers
gives the address of a pointer to pointer which is wrong. It is of type int***
.Both of the above bugs result in undefined behavior. If your program somehow seems to works in some condition, that's just by pure (bad) luck only.
In-kernel memory allocation draws memory from a statically allocated runtime heap. At larger sizes, you are exceeding the size of that heap and then your two kernels are attempting to read and write from uninitialised memory. This produces a runtime error on the device and renders the results invalid. You would already know this if you either added correct API error checking on the host side, or ran your code with the cuda-memcheck
utility.
The solution is to ensure that the heap size is set to something appropriate before trying to run a kernel. Adding something like this:
size_t heapsize = sizeof(int) * size_t(N_CELLE) * size_t(2*L_CELLE);
cudaDeviceSetLimit(cudaLimitMallocHeapSize, heapsize);
to your host code before any other API calls, should solve the problem.