我正在尝试将2d数组复制到GPU但我得到的是零而不是我的数组。
2d数组在主机上创建为double **类型,指向1d数组的指针数组如下所示。
//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);
}
}
我写这篇文章是为了使用cuda将其复制到GPU。
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");
}
我已经开始在主机3 x 3上使用小数组,其值低于
0.000000, 0.000000, 0.000000
2.000000, 0.000000, 0.000000
2.000000, 3.000000, 0.000000
我得到的输出只是零
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
0.000000 0.000000 0.000000
任何想法我做错了..