推力集操作未编译

thrust set operations not compiling

我尝试了一个使用 thrust::set 的简单程序。它找到两个集合的差异。但是我得到编译错误。

#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):警告:从 host[= 调用 host 函数26=] 设备 功能不允许 检测期间: "thrust::system::cuda::detail::detail::set_operation_detail::set_operation_closure::set_operation_closure(InputIterator1, Size, InputIterator2, InputIterator3, InputIterator4, OutputIterator, Compare, SetOperation) [with threads_per_block=(unsigned short)128U, work_per_thread=(unsigned short)15U, InputIterator1=thrust::detail::normal_iterator, thrust::system::cuda::detail::par_t, thrust::use_default, thrust::use_default>>, Size=signed long, InputIterator2=thrust::detail::normal_iterator>, InputIterator3=thrust::detail::normal_iterator>, InputIterator4=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>, Compare=thrust::less, SetOperation=thrust::system::cuda::detail::set_difference_detail::serial_bounded_set_difference]" 的实例化 【578】:这里 "thrust::system::cuda::detail::detail::set_operation_detail::set_operation_closure thrust::system::cuda::detail::detail::set_operation_detail::make_set_operation_closure(InputIterator1, Size, InputIterator2, InputIterator3, InputIterator4, OutputIterator, Compare, SetOperation) [with threads_per_block=(unsigned short)128U, work_per_thread=(unsigned short)15U, InputIterator1=thrust::detail::normal_iterator, thrust::system::cuda::detail::par_t, thrust::use_default, thrust::use_default>>, Size=signed long, InputIterator2=thrust::detail::normal_iterator>, InputIterator3=thrust::detail::normal_iterator>, /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/set_operations.inl(51):这里 "OutputIterator InputIterator3=thrust::detail::normal_iterator>, InputIterator4=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>, Compare=thrust::less, SetOperation=thrust::system::cuda::detail::set_difference_detail::serial_bounded_set_difference]" 的实例化 (560): 这里 "void thrust::system::cuda::detail::detail::set_operation_detail::set_operation_closure::operator()() const [with threads_per_block=(unsigned short)128U, work_per_thread=(unsigned short)15U, InputIterator1=thrust::detail::normal_iterator, thrust::system::cuda::detail::par_t, thrust::use_default, thrust::use_default>>, Size=signed long, InputIterator2=thrust::detail::normal_iterator>, InputIterator3=thrust::detail::normal_iterator>, InputIterator4=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>, Compare=thrust::less, SetOperation=thrust::system::cuda::detail::set_difference_detail::serial_bounded_set_difference]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/detail/launch_closure.inl(52): 这里 "void thrust::system::cuda::detail::detail::launch_closure_by_value(Closure) [with Closure=thrust::system::cuda::detail::detail::set_operation_detail::set_operation_closure<(unsigned short)128U, (unsigned short)15U, thrust::detail::normal_iterator, thrust::system::cuda::detail::par_t, thrust::use_default, thrust::use_default>>, signed long, thrust::detail::normal_iterator>, thrust::detail::normal_iterator>, thrust::detail::normal_iterator>, thrust::device_vector>, thrust::less, thrust::system::cuda::detail::set_difference_detail::serial_bounded_set_difference>]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/set_operations.inl(45): 这里 "OutputIterator thrust::set_difference(const thrust::detail::execution_policy_base &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator) [with DerivedPolicy=thrust::system::cuda::detail::par_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 difference.cu(15): 这里 thrust::system::detail::sequential::copy(thrust::system::detail::sequential::execution_policy &, InputIterator, InputIterator, OutputIterator) [with DerivedPolicy=thrust::detail::seq_t, InputIterator=thrust ::细节::normal_iterator>,OutputIterator=thrust::device_vector>]" /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/copy.inl(37): 这里 "OutputIterator thrust::copy(const thrust::detail::execution_policy_base &, InputIterator, InputIterator, OutputIterator) [with System=thrust::detail::seq_t, InputIterator=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/set_operations.h(79):这里 "OutputIterator thrust::system::detail::sequential::set_difference(thrust::system::detail::sequential::execution_policy &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator, StrictWeakOrdering) [with DerivedPolicy=thrust::detail::seq_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>, StrictWeakOrdering=thrust::less]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/set_operations.inl(65): 这里 "OutputIterator thrust::set_difference(const thrust::detail::execution_policy_base &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator, StrictWeakCompare) [with DerivedPolicy=thrust::detail::seq_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>, StrictWeakCompare=thrust::less]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/set_difference.inl(157): 这里 "RandomAccessIterator3 thrust::system::cuda::detail::set_difference(thrust::system::cuda::detail::execution_policy &, RandomAccessIterator1, RandomAccessIterator1, RandomAccessIterator2, RandomAccessIterator2, RandomAccessIterator3, Compare) [with DerivedPolicy=thrust::system::cuda::detail::par_t, RandomAccessIterator1=thrust::detail::normal_iterator>, RandomAccessIterator2=thrust::detail::normal_iterator>, RandomAccessIterator3=thrust::device_vector>, Compare=thrust::less]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/set_operations.inl(65): 这里 "OutputIterator thrust::set_difference(const thrust::detail::execution_policy_base &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator, StrictWeakCompare) [with DerivedPolicy=thrust::system::cuda::detail::par_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>, StrictWeakCompare=thrust::less]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/set_operations.inl(51):这里 "OutputIterator thrust::system::detail::generic::set_difference(thrust::execution_policy &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator) [with ExecutionPolicy=thrust::system::cuda::detail::par_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/set_operations.inl(45): 这里 "OutputIterator thrust::set_difference(const thrust::detail::execution_policy_base &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator) [with DerivedPolicy=thrust::system::cuda::detail::par_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 difference.cu(15): 这里

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/general_copy.h(106): 错误:没有运算符“++”匹配这些操作数 操作数类型为:++ thrust::device_vector> 检测期间: "OutputIterator thrust::system::detail::sequential::general_copy(InputIterator, InputIterator, OutputIterator) [with InputIterator=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/copy.inl(74): 这里 "OutputIterator thrust::system::detail::sequential::copy_detail::copy(InputIterator, InputIterator, OutputIterator, thrust::detail::false_type) [with InputIterator=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/copy.inl(120): 这里 "OutputIterator thrust::system::detail::sequential::copy(thrust::system::detail::sequential::execution_policy &, InputIterator, InputIterator, OutputIterator) [with DerivedPolicy=thrust::detail::seq_t, InputIterator=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/copy.inl(37): 这里 "OutputIterator thrust::copy(const thrust::detail::execution_policy_base &, InputIterator, InputIterator, OutputIterator) [with System=thrust::detail::seq_t, InputIterator=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/set_operations.h(79):这里 "OutputIterator thrust::system::detail::sequential::set_difference(thrust::system::detail::sequential::execution_policy &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator, StrictWeakOrdering) [with DerivedPolicy=thrust::detail::seq_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>, StrictWeakOrdering=thrust::less]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/set_operations.inl(65): 这里 "OutputIterator thrust::set_difference(const thrust::detail::execution_policy_base &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator, StrictWeakCompare) [with DerivedPolicy=thrust::detail::seq_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>, StrictWeakCompare=thrust::less]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/set_difference.inl(157): 这里 "RandomAccessIterator3 thrust::system::cuda::detail::set_difference(thrust::system::cuda::detail::execution_policy &, RandomAccessIterator1, RandomAccessIterator1, RandomAccessIterator2, RandomAccessIterator2, RandomAccessIterator3, Compare) [with DerivedPolicy=thrust::system::cuda::detail::par_t, RandomAccessIterator1=thrust::detail::normal_iterator>, RandomAccessIterator2=thrust::detail::normal_iterator>, RandomAccessIterator3=thrust::device_vector>, Compare=thrust::less]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/set_operations.inl(65): 这里 "OutputIterator thrust::set_difference(const thrust::detail::execution_policy_base &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator, StrictWeakCompare) [with DerivedPolicy=thrust::system::cuda::detail::par_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>, StrictWeakCompare=thrust::less]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/set_operations.inl(51):这里 "OutputIterator thrust::system::detail::generic::set_difference(thrust::execution_policy &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator) [with ExecutionPolicy=thrust::system::cuda::detail::par_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/set_operations.inl(45): 这里 "OutputIterator thrust::set_difference(const thrust::detail::execution_policy_base &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator) [with DerivedPolicy=thrust::system::cuda::detail::par_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 difference.cu(15): 这里

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/general_copy.h(76): 错误:没有运算符“*”匹配这些操作数 操作数类型为:* thrust::device_vector> 检测期间: "thrust::detail::enable_if::value, void>::type thrust::system::detail::sequential::general_copy_detail::iter_assign(OutputIterator, InputIterator) [with OutputIterator=thrust::device_vector>, InputIterator=thrust::detail::normal_iterator>]" 的实例化 (112):这里 "OutputIterator thrust::system::detail::sequential::general_copy(InputIterator, InputIterator, OutputIterator) [with InputIterator=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/copy.inl(74): 这里 "OutputIterator thrust::system::detail::sequential::copy_detail::copy(InputIterator, InputIterator, OutputIterator, thrust::detail::false_type) [with InputIterator=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/copy.inl(120): 这里 "OutputIterator thrust::system::detail::sequential::copy(thrust::system::detail::sequential::execution_policy &, InputIterator, InputIterator, OutputIterator) [with DerivedPolicy=thrust::detail::seq_t, InputIterator=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/copy.inl(37): 这里 "OutputIterator thrust::copy(const thrust::detail::execution_policy_base &, InputIterator, InputIterator, OutputIterator) [with System=thrust::detail::seq_t, InputIterator=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/set_operations.h(79):这里 "OutputIterator thrust::system::detail::sequential::set_difference(thrust::system::detail::sequential::execution_policy &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator, StrictWeakOrdering) [with DerivedPolicy=thrust::detail::seq_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>, StrictWeakOrdering=thrust::less]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/set_operations.inl(65): 这里 "OutputIterator thrust::set_difference(const thrust::detail::execution_policy_base &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator, StrictWeakCompare) [with DerivedPolicy=thrust::detail::seq_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>, StrictWeakCompare=thrust::less]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/set_difference.inl(157): 这里 "RandomAccessIterator3 thrust::system::cuda::detail::set_difference(thrust::system::cuda::detail::execution_policy &, RandomAccessIterator1, RandomAccessIterator1, RandomAccessIterator2, RandomAccessIterator2, RandomAccessIterator3, Compare) [with DerivedPolicy=thrust::system::cuda::detail::par_t, RandomAccessIterator1=thrust::detail::normal_iterator>, RandomAccessIterator2=thrust::detail::normal_iterator>, RandomAccessIterator3=thrust::device_vector>, Compare=thrust::less]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/set_operations.inl(65): 这里 "OutputIterator thrust::set_difference(const thrust::detail::execution_policy_base &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator, StrictWeakCompare) [with DerivedPolicy=thrust::system::cuda::detail::par_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>, StrictWeakCompare=thrust::less]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/set_operations.inl(51):这里 "OutputIterator thrust::system::detail::generic::set_difference(thrust::execution_policy &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator) [with ExecutionPolicy=thrust::system::cuda::detail::par_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 /usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/detail/set_operations.inl(45): 这里 "OutputIterator thrust::set_difference(const thrust::detail::execution_policy_base &, InputIterator1, InputIterator1, InputIterator2, InputIterator2, OutputIterator) [with DerivedPolicy=thrust::system::cuda::detail::par_t, InputIterator1=thrust::detail::normal_iterator>, InputIterator2=thrust::detail::normal_iterator>, OutputIterator=thrust::device_vector>]" 的实例化 difference.cu(15): 这里

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

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

#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