我试图按照此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