【发布时间】:2012-09-05 15:04:56
【问题描述】:
我正在尝试使用 zip 和排列迭代器执行 thrust::reduce_by_key。
即在几个“虚拟”置换数组的压缩数组上执行此操作。
我在编写函子density_update 的语法时遇到了麻烦。
但首先是问题的设置。
这是我的函数调用:
thrust::reduce_by_key( dflagt,
dflagtend,
thrust::make_zip_iterator(
thrust::make_tuple(
thrust::make_permutation_iterator(dmasst, dmapt),
thrust::make_permutation_iterator(dvelt, dmapt),
thrust::make_permutation_iterator(dmasst, dflagt),
thrust::make_permutation_iterator(dvelt, dflagt)
)
),
thrust::make_discard_iterator(),
danswert,
thrust::equal_to<int>(),
density_update()
)
dmapt、dflagt 的类型为 thrust::device_ptr<int> 和 dvelt 、dmasst 和 danst 的类型
thrust::device_ptr<double>。
(它们是我原始 cuda 数组的推力包装器)
数组mapt 和flagt 都是索引向量,我需要从中执行来自数组dmasst 和dvelt 的聚集操作。
在缩减步骤之后,我打算将我的数据写入danswert 数组。由于在减少中使用了多个数组,显然我使用的是 zip 迭代器。
我的问题在于编写函子density_update,它是二进制运算。
struct density_update
{
typedef thrust::device_ptr<double> ElementIterator;
typedef thrust::device_ptr<int> IndexIterator;
typedef thrust::permutation_iterator<ElementIterator,IndexIterator> PIt;
typedef thrust::tuple< PIt , PIt , PIt, PIt> Tuple;
__host__ __device__
double operator()(const Tuple& x , const Tuple& y)
{
return thrust::get<0>(*x) * (thrust::get<1>(*x) - thrust::get<3>(*x)) + \
thrust::get<0>(*y) * (thrust::get<1>(*y) - thrust::get<3>(*y));
}
};
返回的值是 double 。为什么二元运算看起来像上面的仿函数是 不重要。我只想知道我将如何在语法上更正上述内容。 如上所示,代码引发了许多编译错误。我不确定我哪里出错了。
我在 Ubuntu 10.10 上的 GTX 570 上使用 CUDA 4.0
【问题讨论】:
-
如果你要发布长的、嵌套的、模板化的表达式,你能注意一下代码格式吗?您的最后几个问题非常难以阅读。你的代码越容易阅读,其他人就越容易理解它,发现错误并给你有用的答案。
-
对此我深表歉意。是的,我以后会更好地格式化我的代码。