I am using cudaMalloc and cudaMemcpy to allocate a matrix and copy into it arrays of vectors , like this:
float **pa;
cudaMalloc((void***)&pa, N*sizeof(float*)); //this seems to be ok
for(i=0; i<N; i++) {
cudaMalloc((void**) &(pa[i]), N*sizeof(float)); //this gives seg fault
cudaMemcpy (pa[i], A[i], N*sizeof(float), cudaMemcpyHostToDevice); // also i am not sure about this
}
What is wrong with my instructions? Thanks in advance
P.S. A[i] is a vector
Now i'm trying to copy a matrix from the Device to a matrix from the host:
Supposing I have **pc in the device, and **pgpu is in the host:
cudaMemcpy (pgpu, pc, N*sizeof(float*), cudaMemcpyDeviceToHost);
for (i=0; i<N; i++)
cudaMemcpy(pgpu[i], pc[i], N*sizeof(float), cudaMemcpyDeviceToHost);
= is wrong....