我已经阅读了Mark Harris的优化CUDA并行压缩的文章,我发现它非常有用,但我仍然无法理解1或2个概念。 这是写在第18页:并行还原
//First add during load
// each thread loads one element from global to shared mem
unsigned int tid = threadIdx.x;
unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
sdata[tid] = g_idata[i];
__syncthreads();
优化代码:随着2个负荷和减少1ST ADD:
// perform first level of reduction,
// reading from global memory, writing to shared memory
unsigned int tid = threadIdx.x; ...1
unsigned int i = blockIdx.x*(blockDim.x*2) + threadIdx.x; ...2
sdata[tid] = g_idata[i] + g_idata[i+blockDim.x]; ...3
__syncthreads(); ...4
我无法理解线2条;如果我有256个元素,并且如果我选择128作为块大小,那么为什么我将它乘以2?请解释如何确定块大小?
感谢您的回复。我试图理解这个解决方案,但是如果你能让我知道元素的总数是多少;以及每个块处理多少个元素?另外如果你能让我知道,最初我们正在处理4个块的元素,现在有相同数量的元素,但有2个块? – robot
:H 为什么每个线程只能计算2个元素?由于共有16个元素和4个线程/块,每个块的2个线程将计算4个元素。 – robot
感谢您的回复。如果前2个块的每个线程将计算2个元素,那么最后2个块的每个线程将执行什么操作? – robot