我使用的推力找到一个阵列,C的总和,但我不断收到编译器错误“错误:expresion必须具有类类型”使用了CUDA的推力库阵列减少
float tot = thrust::reduce(c.begin(), c.end());
这是不工作的代码行,c是浮点数组,并且是2个其他数组的元素和。
干杯
我使用的推力找到一个阵列,C的总和,但我不断收到编译器错误“错误:expresion必须具有类类型”使用了CUDA的推力库阵列减少
float tot = thrust::reduce(c.begin(), c.end());
这是不工作的代码行,c是浮点数组,并且是2个其他数组的元素和。
干杯
C应该一个thrust
类型,如thrust::host_vector
或thrust::device_vector
。
它也可以是一个指针 – talonmies 2012-04-16 20:26:29
在Thrust github page上有一个推力::减速的例子。你不能在普通的旧数组上调用.begin(),因为它不是一个对象的实例,即它没有意义。作为一个例子,它就像在下面的代码中调用数组“b”上的.begin()。
int main(void)
{
thrust::host_vector<float> a(10);
float b[10];
thrust::fill(a.begin(), a.end(), 1.0);
thrust::fill(b, b+10, 2.0);
cout << "a: " << thrust::reduce(a.begin(), a.end()) << endl;
cout << "b: " << thrust::reduce(b, b+10) << endl;
return 0;
}
有可能将指针传递给thrust::reduce
。 如果你有一个指向主机内存中的数组,你可以这样做:
float tot = thrust::reduce(c, c + N); // N is the length of c in words
如果你的指针是在设备内存中的数组,你需要将它转换为thrust::device_ptr
第一:
thrust::device_ptr<float> cptr = thrust::device_pointer_cast(c);
float tot = thrust::reduce(cptr, cptr + N); // N is the length of c in words
“浮动阵列”?你不是指C风格的数组''float c []',是吗? – leftaroundabout 2012-04-16 16:19:31