【发布时间】:2012-03-02 02:07:06
【问题描述】:
我一直在考虑如何使用归约在 CUDA 上执行此操作,但对于如何完成它我有点茫然。 C代码如下。要记住的重要部分——变量 precalculatedValue 取决于 both 循环迭代器。此外,变量 ngo 并不是每个 m 的值都是唯一的......例如m = 0,1,2 可能有 ngo = 1,而 m = 4,5,6,7,8 可能有 ngo = 2 等。我已经包含了循环迭代器的大小,以防它有助于提供更好的实现建议。
// macro that translates 2D [i][j] array indices to 1D flattened array indices
#define idx(i,j,lda) ( (j) + ((i)*(lda)) )
int Nobs = 60480;
int NgS = 1859;
int NgO = 900;
// ngo goes from [1,900]
// rInd is an initialized (and filled earlier) as:
// rInd = new long int [Nobs];
for (m=0; m<Nobs; m++) {
ngo=rInd[m]-1;
for (n=0; n<NgS; n++) {
Aggregation[idx(n,ngo,NgO)] += precalculatedValue;
}
}
在前面的例子中,当 precalculatedValue 只是内部循环变量的函数时,我将值保存在唯一的数组索引中,并在事后通过并行缩减(推力)将它们添加。然而,这种情况让我很困惑:m 的值并没有唯一地映射到 ngo 的值。因此,我看不出有一种方法可以使此代码高效(甚至可行)以使用减少。欢迎任何想法。
【问题讨论】:
标签: cuda nested-loops reduction accumulator