__global__ void sum(const float * __restrict__ indata, float * __restrict__ outdata) {
unsigned int tid = blockIdx.x * blockDim.x + threadIdx.x;
// --- Specialize BlockReduce for type float.
typedef cub::BlockReduce<float, BLOCKSIZE> BlockReduceT;
// --- Allocate temporary storage in shared memory
__shared__ typename BlockReduceT::TempStorage temp_storage;
float result;
if(tid < N) result = BlockReduceT(temp_storage).Sum(indata[tid]);
// --- Update block reduction value
if(threadIdx.x == 0) outdata[blockIdx.x] = result;
return;
}
我已经成功地用cuda cub测试了约和(如上面的代码片段所示),我想基于这段代码执行两个向量的内积。但我对此有一些困惑:
我们需要inner_product的两个输入向量,需要我在对得到的新向量进行减法求和之前,对这两个输入向量进行逐个分量乘法。
发布于 2018-06-04 09:08:45
gridDim.x
)的范围可以达到2^31-1,线程编号(即blockDim.x
)的范围可以达到1024。这使您可以处理2^40个元素。如果每个元素是4个字节,这将构成(即需要) 2^42个字节。这大约是4TB (如果你考虑2个输入向量,那么就是两倍),这比目前任何GPU内存都要大得多。因此,在耗尽网格维度之前,您将耗尽GPU内存空间。请注意,您正在显示的是cub::BlockReduce
。但是,如果要对两个较大的向量进行向量点积运算,则可能需要使用cub::DeviceReduce
。
https://stackoverflow.com/questions/50672234
复制相似问题