You have some incorrect pointer usage in the host code. d_array is a device pointer to an array of int. h_array is a host pointer to an array of device pointers. They cannot be used interchangeably, and d_array cannot be passed to your kernel function. Further to that, you seem to be assuming that sizeof(int) is the same as sizeof(int *). On 64 bit host platforms, that isn’t true.
Why do you think iam assuming that sizeof(int) == sizeof(int*) ?
Is there a way to get it work? I though there is a way because in the forum its mentioned that you have to have to create each “layer” separate to create a structure which consist of pointers of pointers.
It might be worth doing a bit of reading up on pointers in C/C++ then, because until you can understand it, you are probably going to struggle in solving this problem.
Because that is what this code implies:
cudaMemcpy(d_array, h_array, sizeof(int*) * N, cudaMemcpyHostToDevice);
d_array is a device pointer to an array of int. h_array is a host array of device pointers (int *). The types and sizes of those two arrays are not necessarily equivalent.
Yes there is. You might find this post useful. Otherwise I am not sure I can explain it differently.
Yes there is. You might find this post useful. Otherwise I am not sure I can explain it differently.
I want to have an array of pointers which each an array of int but the sizes of theses arrays are not equal and not constant so they can change. So construct one big array 1d/2d doesnt help. because if array[i] becomes double in size. I have to shift all the data behind the array[i]. Also i become so big(1024+) that I cannot create simple arrays. And if I have the right understanding your code is only using one array for all the same size atoms.
in c++ i would do something like this:
int arrayofmatrices** = new int*[N];
for(int i = 0; i < N; i++)
*arrayofmatrices[i] = new int[rand()%100];