I have some questions with the right use of cudaMalloc. Suppose I have a double pointer to float and allocate memory on CPU using malloc, which is something like this:
float **array;
array = (float**)malloc(sizeof(float*) * 4);
for( i = 0; i < 4; i++)
array[indexI] = (float*)malloc(sizeof(float)*10);
...
//Fill the array with some stuff
...
Now if I want to allocate memory on the GPU for that kind of array what should I do? I have something like this:
float **d_array;
cudaMalloc((void**)d_array, sizeof(float*)*4);
for( i = 0; i < 4; i++)
cudaMalloc((void**)&d_array[i], sizeof(float)*10);
Finally to copy from array to d_array and put it on GPU-Memory, should I do something like the following?
for( i = 0; i < 4; i++)
cudaMemcpy(&d_array[i], array[i], sizeof(float)*10, cudaMemcpyHostToDevice);
This is some of my code, but when I compile it, it gives me some errors
pprRGB2CMYK.cu(69): warning: variable "d_array" is used before its value is set
./essai.cu(24): Warning: Cannot tell what pointer points to, assuming global memory space
./essai.cu(24): Warning: Cannot tell what pointer points to, assuming global memory space
./essai.cu(24): Warning: Cannot tell what pointer points to, assuming global memory space
./essai.cu(26): Warning: Cannot tell what pointer points to, assuming global memory space
./essai.cu(27): Warning: Cannot tell what pointer points to, assuming global memory space
./essai.cu(28): Warning: Cannot tell what pointer points to, assuming global memory space
./essai.cu(29): Warning: Cannot tell what pointer points to, assuming global memory space
./essai.cu(29): Warning: Cannot tell what pointer points to, assuming global memory space
./essai.cu(43): Warning: Cannot tell what pointer points to, assuming global memory space
./essai.cu(44): Warning: Cannot tell what pointer points to, assuming global memory space
./essai.cu(45): Warning: Cannot tell what pointer points to, assuming global memory space
./essai.cu(46): Warning: Cannot tell what pointer points to, assuming global memory space
pprRGB2CMYK.cu(69): warning: variable "d_array" is used before its value is set
Any ideas?