compiler-errors - 带置换迭代器的推力删除不起作用

标签 compiler-errors cuda permutation thrust erase

我有一个device_vectorA。我有一个MapM。我想使用Map M删除A的元素。
我尝试以下方式,但是它给出了编译错误“没有实例的重载函数...”

#include <thrust/sequence.h>
#include <thrust/execution_policy.h>
#include <thrust/iterator/permutation_iterator.h>
#include <thrust/fill.h>

void erase_value_using_map( thrust::device_vector<int>& A, thrust::device_vector<int> Map)
{

A.erase(thrust::make_permutation_iterator(A.begin(), Map.begin()),
        thrust::make_permutation_iterator(A.begin(), Map.end()));

}

int main(int argc, char * argv[])
{
thrust::device_vector<int> A(20);
thrust::sequence(thrust::device, A.begin(), A.end(),0);  // x components of the 'A' vectors

thrust::device_vector<int> Map(10);
Map[0]=2;Map[1]=4;Map[2]=8;Map[3]=10;Map[4]=11;Map[5]=13;Map[6]=15;Map[7]=17;Map[8]=19;Map[9]=6;

erase_value_using_map(A, Map);

return 0;
}

错误信息:
error: no instance of overloaded function "thrust::device_vector<T, Alloc>::erase [with T=int, Alloc=thrust::device_malloc_allocator<int>]" matches the argument list
            argument types are: (thrust::permutation_iterator<thrust::detail::normal_iterator<thrust::device_ptr<int>>, thrust::detail::normal_iterator<thrust::device_ptr<int>>>, thrust::permutation_iterator<thrust::detail::normal_iterator<thrust::device_ptr<int>>, thrust::detail::normal_iterator<thrust::device_ptr<int>>>)
            object type is: thrust::device_vector<int, thrust::device_malloc_allocator<int>>

最佳答案

我找到了使用gather(由talonmies建议)并调整大小的解决方案。

#include <thrust/gather.h>
#include <thrust/device_vector.h>
#include <thrust/execution_policy.h>

int main()
{

thrust::device_vector<int> d_values(10);
d_values[0]=0;d_values[1]=10;d_values[2]=20;d_values[3]=30;d_values[4]=40;
d_values[5]=50;d_values[6]=60;d_values[7]=70;d_values[8]=80;d_values[9]=90;

thrust::device_vector<int> d_map(7);
d_map[0]=0;d_map[1]=2;d_map[2]=4;d_map[3]=6;d_map[4]=8;d_map[5]=1;d_map[6]=3;

thrust::device_vector<int> d_output(10);
thrust::gather(thrust::device,
               d_map.begin(), d_map.end(),
               d_values.begin(),
               d_output.begin());

d_output.resize(d_map.size());

return 0;
}

关于compiler-errors - 带置换迭代器的推力删除不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53809928/

相关文章:

objective-c - 使用未声明的标识符

c++ - cuda内核执行被cpu代码延迟

CUDA:为什么按位运算符有时比逻辑运算符快?

c++ - 使用推力的 ODE 求解器的 CUDA 编程

python - 生成列表中每个单词的所有组合和排列

algorithm - 线性时间常数空间置换生成器

c# - 如何返回包含给定*部分*组合的所有组合?

c++ - 如何修复此错误 'no matching function for call' ?

java - 无法解析符号 Intent - 是否导入 Intent

java - 表达式的目标类型必须是函数式接口(interface)——为什么需要这个?