Hello,
I need to process relatively large two-dimensional array.
It appears that I cannot use “traditional” method to create such array
cuComplex A[m][n];
I am using pointers instead:
const int m = 5;
const int n = 5;
cuComplex **A = (cuComplex **) malloc(m * sizeof(cuComplex *));
for (i = 0; i < m; i++)
A[i] = (cuComplex *) malloc((n) * sizeof(cuComplex));
Let say I have created in this way 5x5 array on a host:
0.771321 0.588131 , 0.020752 0.897714 , 0.633648 0.891531 , 0.748804 0.815838 , 0.498507 0.035890
0.224797 0.691758 , 0.198063 0.378681 , 0.760531 0.518511 , 0.169111 0.657951 , 0.088340 0.193850
0.685360 0.272316 , 0.953393 0.718606 , 0.003948 0.783004 , 0.512192 0.850328 , 0.812621 0.775245
0.612526 0.036664 , 0.721755 0.116694 , 0.291876 0.751281 , 0.917774 0.239218 , 0.714576 0.254806
0.542544 0.857626 , 0.142170 0.949779 , 0.373341 0.561687 , 0.674134 0.178781 , 0.441833 0.770252
I want to copy this array to the device
cuComplex *d_A = NULL;
cudaStat1 = cudaMalloc((void**) &d_A, sizeof(cuComplex) * (m) * (n));
assert(cudaSuccess == cudaStat1);
cudaStat1 = cudaMemcpy(d_A, *A, sizeof(cuComplex) * (m) * (n),
cudaMemcpyHostToDevice);
assert(cudaSuccess == cudaStat1);
Now I want to verify if the array was copied successfully. I reset array A to 0
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
A[i][j].x = 0.0;
A[i][j].y = 0.0;
}
}
and copy it from the device to host:
cudaStat1 = cudaMemcpy(*A, d_A, sizeof(cuComplex) * 1 * (lda+0) * (n+0),
cudaMemcpyDeviceToHost);
assert(cudaSuccess == cudaStat1);
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
printf(" , %f %f", A[i][j].x, A[i][j].y );
}
printf("\n");
}
However, in the printout i see that not all elements were copied back (check the last row):
0.771321 0.588131 , 0.020752 0.897714 , 0.633648 0.891531 , 0.748804 0.815838 , 0.498507 0.035890
0.224797 0.691758 , 0.198063 0.378681 , 0.760531 0.518511 , 0.169111 0.657951 , 0.088340 0.193850
0.685360 0.272316 , 0.953393 0.718606 , 0.003948 0.783004 , 0.512192 0.850328 , 0.812621 0.775245
0.612526 0.036664 , 0.721755 0.116694 , 0.291876 0.751281 , 0.917774 0.239218 , 0.714576 0.254806
0.542544 0.857626 , <b>0.000000 0.000000 , 0.000000 0.000000 , 0.000000 0.000000 , 0.000000 0.000000</b>
How do I fix this issue?