I am trying to copy 2d array to GPU but I get zeros instead of my array.
The 2d array was created on host as double ** type which array of pointers to 1d array as following.
//on host code
double** 2dArray;
2dArray = (double**) malloc(arraySizeX*sizeof(double*));
for (int i = 0; i < arraySizeX; i++)
2dArray[i] = (double*) malloc(arraySizeY*sizeof(double));
for (int i = 0; i < arraySizeX; i++)
for (int j = 0; j < arraySizeX; j++)
2dArray[i][j] = 0;
// fill Symmetric matrix 2dArray
for (int i = 0; i < MATRIX_SIZE; i++) {
for (int j = 0; j <= i; j ++) {
2dArray[i][j] = (double)min(i+1,j+1);
}
}
And I wrote this to copy it to GPU using cuda.
double *d_A;
cudaMalloc( (void**)&d_A, (arraySizeX*arraySizeY)*sizeof(double) );
cudaMemcpy(d_A, 2dArray, (arraySizeX * arraySizeY) * sizeof(double) , cudaMemcpyHostToDevice);
cudakernel<<<1,1>>>(d_A,arraySizeX, arraySizeY); // using 1 thread just to print values.
cuda code.
__global__ void cudakernel( double *d_A, arraySizeX, arraySizeY )
{
cuPrintf("in device\n");
for (int i = 0; i < arraySizeX * arraySizeY; i++) {
if(i%3==0)
cuPrintf("\n");
cuPrintf("%lf ",d_A[i]);
}
cuPrintf("\n");
}
I have started with small array on host 3 x 3 with below values
0.000000, 0.000000, 0.000000
2.000000, 0.000000, 0.000000
2.000000, 3.000000, 0.000000
and the output I get is simply zeros
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
Any ideas what I did wrong..