推力设置操作不编译[复制](thrust set operations not compiling

2019-10-29 12:41发布

这个问题已经在这里有一个答案:

  • 推力差集失败,调用从__host__ __device__功能的__host__函数编译不允许 1个回答

我试着用推力::设置一个简单的程序。 它发现两组的差异。 但是我得到的编译错误。

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

int main()
{
thrust::device_vector<int> A1(7);
thrust::device_vector<int> A2(5);

thrust::device_vector<int> result(3);

A1[0]=0;A1[1]=1;A1[2]=3;A1[3]=4;A1[4]=5;A1[5]=6;A1[6]=9;
A2[0]=1;A2[1]=3;A2[2]=5;A2[3]=7;

thrust::set_difference(thrust::device, A1.begin(), A1.end(), A2.begin(), A2.end(), result);

return 0;
}

编译错误是:

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/detail/set_operation.inl(555):警告:调用从主机 设备功能的主机功能不过程中允许检测:“推力::系统:: CUDA ::详细::详细:: set_operation_detail :: set_operation_closure :: set_operation_closure(InputIterator1,尺寸,InputIterator2,InputIterator3,InputIterator4,输出迭代,比较,SetOperation)的实例与threads_per_block = (无符号短)管128u,work_per_thread =(无符号短)15U,InputIterator1 =推力::详细:: normal_iterator,推力::系统:: CUDA ::详细:: par_t,推力:: USE_DEFAULT,推力:: USE_DEFAULT >>,大小=签署长,InputIterator2 =推力::详细:: normal_iterator>,InputIterator3 =推力::详细:: normal_iterator>,InputIterator4 =推力::详细:: normal_iterator>,输出迭代=推力:: device_vector>,比较=推力: :以下,SetOperation =推力::系统:: CUDA ::详细:: set_difference_detail :: serial_bounded_set_difference] “(578):在这里的实例化” 推力::系统:: CUDA ::详细::详细:: set_operation_detail :: set_operation_closure推力::系统:: CUDA ::详细::详细:: set_operation_detail :: make_set_operation_closure(InputIterator1,尺寸,InputIterator2,InputIterator3,InputIterator4,输出迭代,比较,SetOperation)[用threads_per_block =(无符号短)管128u,work_per_thread =(无符号短)15U,InputIterator1 =推力::详细:: normal_iterator,推力::系统:: CUDA ::详细:: par_t,推力:: USE_DEFAULT,推力:: USE_DEFAULT >>,大小=签订长,InputIterator2 =推力::详细:: normal_iterator>,InputIterator3 =推力::详细:: normal_iterator>,/usr/local/cuda/bin/../targets/ x86_64的-LINUX /包含/推力/系统/细节/通用/ set_operations.inl(51):的“输出迭代InputIterator3 =推力::详细:: normal_iterator>这里的实例化,InputIterator4 =推力::详细:: normal_iterator>,输出迭代=推力:: device_vector>,比较=推力::以下,SetOperation =推力::系统:: CUDA ::详细:: set_difference_detail :: serial_bounded_set_differe NCE] “(560):在这里的实例化” 空隙推力::系统:: CUDA ::详细::详细:: set_operation_detail :: set_operation_closure ::运算符()()const的[与threads_per_block =(无符号短)管128u,work_per_thread =(无符号短)15U,InputIterator1 =推力::详细:: normal_iterator,推力::系统:: CUDA ::详细:: par_t,推力:: USE_DEFAULT,推力:: USE_DEFAULT >>,大小=符号长,InputIterator2 =推力::详细:: normal_iterator>,InputIterator3 =推力::详细:: normal_iterator>,InputIterator4 =推力::详细:: normal_iterator>,输出迭代=推力:: device_vector>,比较=推力::以下,SetOperation =推力: :系统:: CUDA ::详细:: set_difference_detail :: serial_bounded_set_difference]”在/ usr /本地/ CUDA / bin中/../目标/ x86_64的Linux的/有/推力/系统/ CUDA /细节/细节/ launch_closure.inl( 52):这里的“空隙推力::系统:: CUDA ::详细::详细:: launch_closure_by_value(封闭)[用封=推力::系统:: CUDA ::详细::详细:: set_operation_detail :: set_operation_closure实例化<(无符号短)1 28U,(无符号短)15U,推力::详细:: normal_iterator,推力::系统:: CUDA ::详细:: par_t,推力:: USE_DEFAULT,推力:: USE_DEFAULT >>,签订长,推力::细节: :normal_iterator>,推力::详细:: normal_iterator>,推力::详细:: normal_iterator>,推力:: device_vector>,推力::以下,推力::系统:: CUDA ::详细:: set_difference_detail :: serial_bounded_set_difference> ] “/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/set_operations.inl(45):这里的实例化” 输出迭代推力:: set_difference(常量推力::详细:: execution_policy_base&,InputIterator1,InputIterator1,InputIterator2,InputIterator2,输出迭代)[与DerivedPolicy =推力::系统:: CUDA ::详细:: par_t,InputIterator1 =推力::详细:: normal_iterator>,InputIterator2 =推力::详细:: normal_iterator>,输出迭代=推力:: device_vector>]” difference.cu(15):这里推力::系统::详细::顺序::拷贝(推力::系统::详细::顺序:: execution_policy&,InputIterator的,InputIterato R,输出迭代)[与DerivedPolicy =推力::详细:: seq_t,InputIterator的推力= ::详细:: normal_iterator>,输出迭代=推力:: device_vector>]” /usr/local/cuda/bin/../targets/ x86_64的-LINUX /包含/推力/细节/ copy.inl(37):的“输出迭代推力::拷贝这里实例化(常量推力::详细:: execution_policy_base&,InputIterator的,InputIterator的,输出迭代)与系统=推力::细节:: seq_t,InputIterator的推力= ::详细:: normal_iterator>,输出迭代=推力:: device_vector>]” /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail /sequential/set_operations.h(79):此处“输出迭代推力::系统::详细::顺序:: set_difference(推力::系统::详细::顺序:: execution_policy&,InputIterator1,InputIterator1,InputIterator2的实例化, InputIterator2,输出迭代,严格弱)与DerivedPolicy =推力::详细:: seq_t,InputIterator1 =推力::详细:: normal_iterator>,InputIterator2 =推力::详细:: normal_iterator>,OutputIter ATOR =推力:: device_vector>,严格弱=推力::更少]” /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/set_operations.inl(65):这里的实例化“输出迭代推力:: set_difference(常量推力::详细:: execution_policy_base&,InputIterator1,InputIterator1,InputIterator2,InputIterator2,输出迭代,StrictWeakCompare)[与DerivedPolicy =推力::详细:: seq_t,InputIterator1 =推力::详细:: normal_iterator >,InputIterator2 =推力::详细:: normal_iterator>,输出迭代=推力:: device_vector>,StrictWeakCompare =推力::更少]” /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust /system/cuda/detail/set_difference.inl(157):这里RandomAccessIterator3的”实例推力::系统:: CUDA ::详细:: set_difference(推力::系统:: CUDA ::详细:: execution_policy&,RandomAccessIterator1, RandomAccessIterator1,RandomAccessIterator2,RandomAccessIterator2,RandomAccessIterator3,比较)[与DerivedPolicy =推力::系统:: CUDA ::详细:: par_t,冉 domAccessIterator1 =推力::详细:: normal_iterator>,RandomAccessIterator2 =推力::详细:: normal_iterator>,RandomAccessIterator3 =推力:: device_vector>,比较=推力::更少]” /usr/local/cuda/bin/../目标/ x86_64的-LINUX /包含/推力/细节/ set_operations.inl(65):的“输出迭代推力:: set_difference这里实例化(常量推力::详细:: execution_policy_base&,InputIterator1,InputIterator1,InputIterator2,InputIterator2,输出迭代,StrictWeakCompare )[用DerivedPolicy =推力::系统:: CUDA ::详细:: par_t,InputIterator1 =推力::详细:: normal_iterator>,InputIterator2 =推力::详细:: normal_iterator>,输出迭代=推力:: device_vector>,StrictWeakCompare = ::推力更少]:输出迭代推力“/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/set_operations.inl(51)这里的实例化” ::系统::详细::通用:: set_difference(推力:: execution_policy&,InputIterator1,InputIterator1,InputIterator2,InputIterator2,输出迭代) [与ExecutionPolicy =推力::系统:: CUDA ::详细:: par_t,InputIterator1 =推力::详细:: normal_iterator>,InputIterator2 =推力::详细:: normal_iterator>,输出迭代=推力:: device_vector>]” / USR /本地/ CUDA / bin中/../目标/ x86_64的Linux的/有/推力/细节/ set_operations.inl(45):“输出迭代推力:: set_difference这里实例(常量推力::详细:: execution_policy_base和, InputIterator1,InputIterator1,InputIterator2,InputIterator2,输出迭代)[与DerivedPolicy =推力::系统:: CUDA ::详细:: par_t,InputIterator1 =推力::详细:: normal_iterator>,InputIterator2 =推力::详细:: normal_iterator>输出迭代=推力:: device_vector>]” difference.cu(15):这里

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/general_copy.h(106):错误:没有操作员“++”相匹配这些操作数的操作数的类型是: ++推力:: device_vector>期间检测到:“输出迭代推力::系统::详细::顺序:: general_copy(InputIterator的,InputIterator的,输出迭代)[与InputIterator的推力= ::详细:: normal_iterator>,输出迭代=推力的实例化:: device_vector>] “/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/copy.inl(74):这里的实例化” 输出迭代推力::系统::详细::顺序:: copy_detail ::拷贝(InputIterator的,InputIterator的,输出迭代,推力::详细:: false_type)[与InputIterator的推力= ::详细:: normal_iterator>,输出迭代=推力:: device_vector>]” / USR /本地/ CUDA / bin中/../目标/ x86_64的Linux的/有/推力/系统/细节/顺序/ copy.inl(120):“输出迭代推力::系统::详细::顺序这里实例: :副本(推力::系统:: ::详细色曲 ential :: execution_policy&,InputIterator的,InputIterator的,输出迭代)[与DerivedPolicy =推力::详细:: seq_t,InputIterator的推力= ::详细:: normal_iterator>,输出迭代=推力:: device_vector>]”的/ usr /本地/ CUDA /bin/../targets/x86_64-linux/include/thrust/detail/copy.inl(37):这里的“输出迭代推力::复制实例(常量推力::详细:: execution_policy_base&,InputIterator的,InputIterator的,输出迭代)[用体系=推力::详细:: seq_t,InputIterator的推力= ::详细:: normal_iterator>,输出迭代=推力:: device_vector>]” /usr/local/cuda/bin/../targets/x86_64-linux /include/thrust/system/detail/sequential/set_operations.h(79):这里输出迭代的“实例推力::系统::详细::顺序:: set_difference(推力::系统::详细::顺序:: execution_policy &,InputIterator1,InputIterator1,InputIterator2,InputIterator2,输出迭代,严格弱)与DerivedPolicy =推力::详细:: seq_t,InputIterator1 =推力::详细:: normal_iterator>,Inpu tIterator2 =推力::详细:: normal_iterator>,输出迭代=推力:: device_vector>,严格弱=推力::更少]” /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail /set_operations.inl(65):这里的“输出迭代推力:: set_difference实例化(常量推力::详细:: execution_policy_base&,InputIterator1,InputIterator1,InputIterator2,InputIterator2,输出迭代,StrictWeakCompare)[与DerivedPolicy =推力::详细:: seq_t,InputIterator1 =推力::详细:: normal_iterator>,InputIterator2 =推力::详细:: normal_iterator>,输出迭代=推力:: device_vector>,StrictWeakCompare =推力::更少]”的/ usr /本地/ CUDA / bin /中。 ./targets/x86_64-linux/include/thrust/system/cuda/detail/set_difference.inl(157):这里RandomAccessIterator3的”实例推力::系统:: CUDA ::详细:: set_difference(推力::系统:: CUDA ::详细:: execution_policy&,RandomAccessIterator1,RandomAccessIterator1,RandomAccessIterator2,RandomAccessIterator2,RandomAccessIterator3,比较)[与 DerivedPolicy =推力::系统:: CUDA ::详细:: par_t,RandomAccessIterator1 =推力::详细:: normal_iterator>,RandomAccessIterator2 =推力::详细:: normal_iterator>,RandomAccessIterator3 =推力:: device_vector>,比较=推力: :更少]“/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/set_operations.inl(65):这里的实例化”输出迭代推力:: set_difference(常量推力::细节:: execution_policy_base&,InputIterator1,InputIterator1,InputIterator2,InputIterator2,输出迭代,StrictWeakCompare)[与DerivedPolicy =推力::系统:: CUDA ::详细:: par_t,InputIterator1 =推力::详细:: normal_iterator>,InputIterator2 =推力: :细节:: normal_iterator>,输出迭代=推力:: device_vector>,StrictWeakCompare =推力::更少]” /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic /set_operations.inl(51):这里输出迭代的“实例推力::系统::详细::一般:: set_difference(推力:: execution_policy&,InputIterator1,InputIte rator1,InputIterator2,InputIterator2,输出迭代)[与ExecutionPolicy =推力::系统:: CUDA ::详细:: par_t,InputIterator1 =推力::详细:: normal_iterator>,InputIterator2 =推力::详细:: normal_iterator>,输出迭代=推力:: device_vector>]:输出迭代推力:: set_difference “/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/set_operations.inl(45)这里的实例化”(常量推力::详细:: execution_policy_base&,InputIterator1,InputIterator1,InputIterator2,InputIterator2,输出迭代)[与DerivedPolicy =推力::系统:: CUDA ::详细:: par_t,InputIterator1 =推力::详细:: normal_iterator>,InputIterator2 =推力::详细:: normal_iterator>,输出迭代=推力:: device_vector>]” difference.cu(15):这里

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/general_copy.h(76):错误:没有操作员“*”匹配这些操作数的操作数类型是:*推力:: device_vector>期间检测到:“推力::详细:: enable_if ::值,空隙> ::式推力::系统::详细::顺序:: general_copy_detail :: iter_assign(输出迭代,InputIterator的)[用的实例化输出迭代=推力:: device_vector>,InputIterator的推力= ::详细:: normal_iterator>] “(112):在这里的实例化” 输出迭代推力::系统::详细::顺序:: general_copy(InputIterator的,InputIterator的,输出迭代)与InputIterator的推力= ::详细:: normal_iterator>,输出迭代=推力:: device_vector>]” /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/copy .INL(74):此处“输出迭代推力::系统::详细::顺序:: copy_detail ::拷贝(InputIterator的,InputIterator的,输出迭代,推力::详细:: false_type)的实例化[与InputIterator的推力= ::德泰 升:: normal_iterator>,输出迭代=推力:: device_vector>]” /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/copy.inl(120):这里“输出迭代推力::系统::详细::顺序::拷贝(推力::系统::详细::顺序:: execution_policy&,InputIterator的,InputIterator的,输出迭代)的实例化[与DerivedPolicy =推力::详细:: seq_t,InputIterator的推力= ::详细:: normal_iterator>,输出迭代=推力:: device_vector>]”的/ usr /本地/ CUDA / bin中/../目标/ x86_64的-LINUX /包含/推力/细节/ copy.inl( 37):这里的“输出迭代推力::拷贝实例化(常量推力::详细:: execution_policy_base&,InputIterator的,InputIterator的,输出迭代)与系统=推力::详细:: seq_t,InputIterator的推力= ::详细:: normal_iterator >,输出迭代=推力:: device_vector>] “/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/set_operations.h(79):这里的实例化”输出迭代推力::系统::详细::顺序:: set_difference(推力::系统::详细::顺序:: execution_policy&,InputIterator1,InputIterator1,InputIterator2,InputIterator2,输出迭代,严格弱)与DerivedPolicy =推力::详细:: seq_t,InputIterator1 =推力::详细:: normal_iterator >,InputIterator2 =推力::详细:: normal_iterator>,输出迭代=推力:: device_vector>,严格弱=推力::更少]” /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust /detail/set_operations.inl(65):这里的“输出迭代推力:: set_difference实例化(常量推力::详细:: execution_policy_base&,InputIterator1,InputIterator1,InputIterator2,InputIterator2,输出迭代,StrictWeakCompare)[与DerivedPolicy =推力::细节:: seq_t,InputIterator1 =推力::详细:: normal_iterator>,InputIterator2 =推力::详细:: normal_iterator>,输出迭代=推力:: device_vector>,StrictWeakCompare =推力::更少]”的/ usr /本地/ CUDA / bin中/../targets/x86_64-linux/include/thrust/system/cuda/detail/set_difference.inl(157):他 再RandomAccessIterator3的”实例化推力::系统:: CUDA ::详细:: set_difference(推力::系统:: CUDA ::详细:: execution_policy&,RandomAccessIterator1,RandomAccessIterator1,RandomAccessIterator2,RandomAccessIterator2,RandomAccessIterator3,比较)[与DerivedPolicy =推力::系统:: CUDA ::详细:: par_t,RandomAccessIterator1 =推力::详细:: normal_iterator>,RandomAccessIterator2 =推力::详细:: normal_iterator>,RandomAccessIterator3 =推力:: device_vector>,比较=推力::少] “/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/set_operations.inl(65):这里的实例化” 输出迭代推力:: set_difference(常量推力::详细:: execution_policy_base&,InputIterator1,InputIterator1,InputIterator2,InputIterator2,输出迭代,StrictWeakCompare)[与DerivedPolicy =推力::系统:: CUDA ::详细:: par_t,InputIterator1 =推力::详细:: normal_iterator>,InputIterator2 =推力::细节:: normal_iterator>,输出迭代=推力:: device_vector>,StrictWea kCompare =推力::更少] “/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/set_operations.inl(51):这里的实例化” 输出迭代推力: :系统::详细::通用:: set_difference(推力:: execution_policy&,InputIterator1,InputIterator1,InputIterator2,InputIterator2,输出迭代)[与ExecutionPolicy =推力::系统:: CUDA ::详细:: par_t,InputIterator1 =推力: :细节:: normal_iterator>,InputIterator2 =推力::详细:: normal_iterator>,输出迭代=推力:: device_vector>]” /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail /set_operations.inl(45):这里的“输出迭代推力:: set_difference实例化(常量推力::详细:: execution_policy_base&,InputIterator1,InputIterator1,InputIterator2,InputIterator2,输出迭代)[与DerivedPolicy =推力::系统:: CUDA: :细节:: par_t,InputIterator1 =推力::详细:: normal_iterator>,InputIterator2 =推力::详细:: normal_iterator>,输出迭代=推力:: device_vector>]”各色 nce.cu(15):这里

在“/tmp/tmpxft_00007f24_00000000-9_difference.cpp1.ii”编译检测7个错误。

Answer 1:

有一个错字:它必须result.begin(),而不是结果。 我张贴任何其他新手正确的代码。

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

int main()
{
thrust::device_vector<int> A1(7);
thrust::device_vector<int> A2(5);

thrust::device_vector<int> result(3);

A1[0]=0;A1[1]=1;A1[2]=3;A1[3]=4;A1[4]=5;A1[5]=6;A1[6]=9;
A2[0]=1;A2[1]=3;A2[2]=5;A2[3]=7;

thrust::set_difference(thrust::device, A1.begin(), A1.end(), A2.begin(), A2.end(), result.begin());

std::cout<<"A1=";
thrust::copy(A1.begin(), A1.end(), std::ostream_iterator<int>(std::cout, " "));
std::cout<<std::endl;

std::cout<<"A2=";
thrust::copy(A2.begin(), A2.end(), std::ostream_iterator<int>(std::cout, " "));
std::cout<<std::endl;

std::cout<<"result=";
thrust::copy(result.begin(), result.end(), std::ostream_iterator<int>(std::cout, " "));
std::cout<<std::endl;

return 0;
}

./difference 
A1=0 1 3 4 5 6 9 
A2=1 3 5 7 0 
result=0 4 6 


文章来源: thrust set operations not compiling [duplicate]