我有一个内核接收一个扁平的二维数组,我想每次共享内存时复制一行数组,我的内核如下所示:
__global__ void searchKMP(char *test,size_t pitch_test,int ittNbr){
int tid = blockDim.x * blockIdx.x + threadIdx.x;
int strideId = tid * 50;
int m = 50;
__shared__ char s_test[m];
int j;
//this loops over the number of lines in my 2D array
for(int k=0; k<ittNbr; k++){
//this loops to store my flattened (basically threats 1 line at a time) array into shared memory
if(threadIdx.x==0){
for(int n =0; n<50; ++n){
s_test[n] = *(((char*)test + k * pitch_test) + n);
}
}
__syncthreads();
j=0;
//this is loop to process my shared memory array against another 1D array
for(int i=strideID; i<(strideID+50); i++{
...dosomething...
(increment x if a condition is met)
...dosomething...
}
__syncthreads();
if(x!=0)
cache[0]+=x;
...dosomething...
}
尽管当我验证 x 的值时,x 的值始终在变化,或者随着线程数的变化而变化。例如,当 20 个 250 个线程块根据执行返回值 7 或 6 时,10 个 500 个线程块返回 9。我想知道问题是来自复制到共享内存中的二维扁平数组,还是在这段代码中做错了什么。