我正在使用CUDA和Thrust。我发现输入thrust::transform [plus/minus/divide]
乏味,所以我只想重载一些简单的操作符。为Thrust重载“+”运算符,有什么想法?
这将是真棒,如果我能做到:
thrust::[host/device]_vector<float> host;
thrust::[host/device]_vector<float> otherHost;
thrust::[host/device]_vector<float> result = host + otherHost;
下面是+
一个例子片段:
template <typename T>
__host__ __device__ T& operator+(T &lhs, const T &rhs) {
thrust::transform(rhs.begin(), rhs.end(),
lhs.begin(), lhs.end(), thrust::plus<?>());
return lhs;
}
然而,thrust::plus<?>
没有正确过载,或者我没有做它正确地......一个或另一个。 (如果为此重载简单的操作符是个不好的主意,请解释原因)。最初,我认为我可以用typename T::iterator
之类的东西超载?
占位符,但那不起作用。
我不知道如何使矢量和类型的矢量迭代器的类型过载+
运算符。这有意义吗?
感谢您的帮助!
'>'是什么意思? – Elazar
@Elazar这意味着我不知道该放什么。也许某种类型的'T :: iterator'类型或其他类型。 –
我刚编辑它 –