【发布时间】:2013-01-08 18:49:32
【问题描述】:
我在 CUDA 中有以下类函子
class forSecondMax{
private:
int toExclude;
public:
__device__ void setToExclude(int val){
toExclude = val;
}
__device__ bool operator ()
(const DereferencedIteratorTuple& lhs, const DereferencedIteratorTuple& rhs)
{
using thrust::get;
//if you do <=, returns last occurence of largest element. < returns first
if (get<0>(lhs)== get<2>(lhs) /*&& get<0>(rhs) == get<2>(rhs)*/ && get<0>(lhs) != toExclude/* && get<0>(rhs)!= toExclude */) return get<1>(lhs) < get<1>(rhs); else
return true ;
}
};
有没有办法从主机设置 toExclude 的值?
【问题讨论】:
-
为什么不定义一个构造函数呢?这将是在对象实例化期间设置数据成员的规范方式,这在使用因此仿函数时发生在主机上......
-
@talonmies:你能看看这个问题stackoverflow.com/questions/14006148/…