私はCUDAカーネルを作成して、rows * colsメイン行列の各位置の3x3共分散行列を作成しています。したがって、3D行列は、* mallocに応じて割り当てられた行* cols * 9です。これを1つのインデックス値でアクセスする必要がありますオフセット配列を3D配列に計算する
3x3共分散行列の9個の値は、他の2D配列の適切な行rと列cに従って値を設定します。
つまり、3x3共分散行列の9要素にアクセスするための適切なインデックスと、値への入力である2D行列の行と列のオフセットと、適切なインデックスを計算する必要がありますストレージアレイのインデックス。
iは、以下にそれを簡素化することを試みた:
//I am calling this kernel with 1D blocks who are 512 cols x 1row. TILE_WIDTH=512
int bx = blockIdx.x;
int by = blockIdx.y;
int tx = threadIdx.x;
int ty = threadIdx.y;
int r = by + ty;
int c = bx*TILE_WIDTH + tx;
int offset = r*cols+c;
int ndx = r*cols*rows + c*cols;
if((r < rows) && (c < cols)){ //this IF statement is trying to avoid the case where a threadblock went bigger than my original array..not sure if correct
d_cov[ndx + 0] = otherArray[offset];//otherArray just contains a value that I might do some operations on to set each of the ndx0-ndx9 values in d_cov
d_cov[ndx + 1] = otherArray[offset];
d_cov[ndx + 2] = otherArray[offset];
d_cov[ndx + 3] = otherArray[offset];
d_cov[ndx + 4] = otherArray[offset];
d_cov[ndx + 5] = otherArray[offset];
d_cov[ndx + 6] = otherArray[offset];
d_cov[ndx + 7] = otherArray[offset];
d_cov[ndx + 8] = otherArray[offset];
}
Iは、I =行、J = COLS、K = 1をループCPUで計算された値、この配列を確認
。 .9結果が一致しません。言い換えれば
がd_cov [iの行を* * colsの+ J * colsの+ K]!= correctAnswer [I] [J] [K]
誰かが私にこの問題をsovleする方法上の任意のヒントを与えることはできますか?それは索引付けの問題か他の何らかの論理エラーですか?
これは間違っていると思います。宇宙の次の「飛行機」では機能しません – Derek