thrust set operations not compiling [duplicate]

丶灬走出姿态 提交于 2019-12-25 00:27:14

问题


I tried a simple program using thrust::set. It finds the difference of two sets. However I get compilation error.

#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;
}

The compilation error is:

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/detail/set_operation.inl(555): warning: calling a host function from a host device function is not allowed detected during: instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here 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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/general_copy.h(106): error: no operator "++" matches these operands operand types are: ++ thrust::device_vector> detected during: instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/sequential/general_copy.h(76): error: no operator "*" matches these operands operand types are: * thrust::device_vector> detected during: instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here instantiation of "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): here

7 errors detected in the compilation of "/tmp/tmpxft_00007f24_00000000-9_difference.cpp1.ii".


回答1:


There was a typo: it has to be result.begin() instead of result. I post the correct code for any other newbie.

#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 


来源:https://stackoverflow.com/questions/53475531/thrust-set-operations-not-compiling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!