我想使用std :: bind2nd与推力。我有用主机指针编译的代码,但没有使用设备指针。我认为他们是相同的,应该在两种情况下都能工作。使用std :: bind2nd与推力
// this compiles fine
thrust::host_vector<unsigned int> h_vec(nwords);
thrust::host_vector<unsigned int> h_map(nwords);
thrust::host_vector<unsigned int> h_out1(nwords);
thrust::copy_if(h_vec.begin(), h_vec.end(), h_map.begin(), h_out1.begin(),
std::bind2nd(thrust::equal_to<int>(),1));
// this compilation fails with the error below
thrust::device_vector<unsigned int> d_map(nwords);
thrust::device_vector<unsigned int> d_vec(nwords);
thrust::device_vector<unsigned int> d_out1(nwords);
thrust::copy_if(d_vec.begin(), d_vec.end(), d_map.begin(), d_out1.begin(),
std::bind2nd(thrust::equal_to<int>(),1));
当我尝试调用第二copy_if与bind2nd我得到的错误如下:
/opt/cuda/include/thrust/detail/internal_functional.h(99): warning: calling a
__host__ function from a __host__ __device__ function is not allowed
是否有另一种方式来使用适配器推力二元函数?我看到一些人在网上的例子中使用“thrust :: bind2nd”,但我无法在我们的任何头文件中找到它。
对此操作使用占位符表达式'thrust :: placeholders :: _ 1 == 1',而不是尝试使用类似'bind2nd'的东西。 – 2013-03-01 19:42:01
这也是一个好主意。谢谢。 – 2013-03-01 21:40:00