我試圖按照此tutorial -cuda共享內存覆蓋?
我想在本教程中解釋了工作效率不高的「雙緩衝的一個」寫在CUDA並行前綴掃描。
這是我有:
// double buffered naive.
// d = number of iterations, N - size, and input.
__global__ void prefixsum(int* in, int d, int N)
{
//get the block index
int idx = blockIdx.x*blockDim.x + threadIdx.x;
// allocate shared memory
extern __shared__ int temp_in[], temp_out[];
// copy data to it.
temp_in[idx] = in[idx];
temp_out[idx] = 0;
// block until all threads copy
__syncthreads();
int i = 1;
for (i; i<=d; i++)
{
if (idx < N+1 && idx >= (int)pow(2.0f,(float)i-1))
{
// copy new result to temp_out
temp_out[idx] += temp_in[idx - (int)pow(2.0f,(float)i-1)] + temp_in[idx];
}
else
{
// if the element is to remain unchanged, copy the same thing
temp_out[idx] = temp_in[idx];
}
// block until all theads do this
__syncthreads();
// copy the result to temp_in for next iteration
temp_in[idx] = temp_out[idx];
// wait for all threads to do so
__syncthreads();
}
//finally copy everything back to global memory
in[idx] = temp_in[idx];
}
你能指出這有什麼錯呢?我已經爲我認爲應該發生的事情寫下評論。
這是內核調用 -
prefixsum<<<dimGrid,dimBlock>>>(d_arr, log(SIZE)/log(2), N);
這是網格和塊分配:
dim3 dimGrid(numBlocks);
dim3 dimBlock(numThreadsPerBlock);
的問題是,我沒有得到正確的輸出這是比任何輸入8個元素長。
你可以添加你的內核調用嗎?那確切的問題是什麼? – 2012-01-18 21:57:07
'dimGrid'和'dimBlock'的值是什麼? – flipchart 2012-01-19 05:48:16