【发布时间】:2014-02-20 12:06:17
【问题描述】:
我一直在尝试在设备向量上使用推力函数 reduce_by_key。在文档中,他们给出了关于 host_vectors 而不是任何设备向量的示例。我遇到的主要问题是存储函数的返回值。更具体地说,这里是我的代码:
thrust::device_vector<int> hashValueVector(10)
thrust::device_vector<int> hashKeysVector(10)
thrust::device_vector<int> d_pathId(10);
thrust::device_vector<int> d_freqError(10); //EDITED
thrust::pair<thrust::detail::normal_iterator<thrust::device_ptr<int> >,thrust::detail::normal_iterator<thrust::device_ptr<int> > > new_end; //THE PROBLEM
new_end = thrust::reduce_by_key(hashKeysVector.begin(),hashKeysVector.end(),hashValueVector.begin(),d_pathId.begin(),d_freqError.begin());
我尝试在定义中首先将它们声明为 device_ptr,因为对于 host_vectors,它们也在文档的定义中使用了指针。但是当我尝试这样做时出现编译错误,然后我阅读了错误声明并将声明转换为上述声明,编译正常,但我不确定这是否是正确的定义方式。
我还有其他标准/干净的声明方式(“new_end”变量)吗?如果我的问题在某处不清楚,请发表评论。
编辑:我已经编辑了 d_freqError 的声明。应该是 int 我写错了 hashElem,抱歉。
【问题讨论】:
标签: cuda return-value device reduce thrust