2013-01-11 42 views
1

我是lambda表达式的新手。我试图用下面的公式初始化推力装置矢量data[10]如何使用thrust ::占位符在CUDA中初始化设备向量?

data [i] = i * 0.1 + 0.5;

我已经包含这些头文件和命名空间

#include <thrust/device_vector.h> 
#include <thrust/iterator/counting_iterator.h> 
#include <thrust/iterator/transform_iterator.h> 
#include <thrust/functional.h> 
using namespace thrust::placeholders; 

下面的代码定义&初始化data

thrust::device_vector<double> data(
     thrust::make_transform_iterator(
       thrust::counting_iterator<double>(0), _1 * 0.1 + 0.5), 
     thrust::make_transform_iterator(
       thrust::counting_iterator<double>(0), _1 * 0.1 + 0.5) + 10); 

但它不能编译,显示效果非常长的错误味精如所示帖子的结尾。

我做错了什么?

我使用CUDA 5.0,CentOS的6.3 x86_64的,GCC 4.4.6

/usr/local/cuda-5.0/bin/../include/thrust/iterator/detail/transform_iterator.inl(94): error: no instance of overloaded function "thrust::detail::functional::actor<Eval>::operator() [with Eval=thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::plus>, thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::multiplies>, thrust::detail::functional::actor<thrust::detail::functional::argument<0U>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>]" matches the argument list 
      argument types are: (double) 
      object type is: thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::plus>, thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::multiplies>, thrust::detail::functional::actor<thrust::detail::functional::argument<0U>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>> 
      detected during: 
      instantiation of "thrust::detail::backend::dereference_result<thrust::transform_iterator<UnaryFunc, Iterator, Reference, Value>>::type thrust::detail::backend::dereference(const thrust::transform_iterator<UnaryFunc, Iterator, Reference, Value> &) [with UnaryFunc=thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::plus>, thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::multiplies>, thrust::detail::functional::actor<thrust::detail::functional::argument<0U>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, Iterator=thrust::counting_iterator<double, thrust::use_default, thrust::use_default, thrust::use_default>, Reference=thrust::use_default, Value=thrust::use_default]" 
/usr/local/cuda-5.0/bin/../include/thrust/iterator/detail/zip_iterator_base.h(128): here 
      instantiation of "thrust::detail::device_dereference_iterator::apply<Iterator>::type thrust::detail::device_dereference_iterator::operator()(const Iterator &) [with Iterator=thrust::transform_iterator<thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::plus>, thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::multiplies>, thrust::detail::functional::actor<thrust::detail::functional::argument<0U>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::counting_iterator<double, thrust::use_default, thrust::use_default, thrust::use_default>, thrust::use_default, thrust::use_default>]" 
/usr/local/cuda-5.0/bin/../include/thrust/detail/tuple_transform.h(102): here 
      instantiation of "thrust::detail::tuple_meta_transform<Tuple, UnaryMetaFunction, thrust::tuple_size<Tuple>::value>::type thrust::detail::tuple_transform_functor<Tuple, UnaryMetaFunction, UnaryFunction, 2U>::do_it_on_the_host_or_device(const Tuple &, UnaryFunction) [with Tuple=thrust::tuple<thrust::transform_iterator<thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::plus>, thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::multiplies>, thrust::detail::functional::actor<thrust::detail::functional::argument<0U>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::counting_iterator<double, thrust::use_default, thrust::use_default, thrust::use_default>, thrust::use_default, thrust::use_default>, thrust::detail::normal_iterator<thrust::device_ptr<double>>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>, UnaryMetaFunction=thrust::detail::device_dereference_iterator::apply, UnaryFunction=thrust::detail::device_dereference_iterator]" 
/usr/local/cuda-5.0/bin/../include/thrust/detail/tuple_transform.h(412): here 
      instantiation of "thrust::detail::tuple_meta_transform<Tuple, UnaryMetaFunction, thrust::tuple_size<Tuple>::value>::type thrust::detail::tuple_host_device_transform<UnaryMetaFunction,Tuple,UnaryFunction>(const Tuple &, UnaryFunction) [with UnaryMetaFunction=thrust::detail::device_dereference_iterator::apply, Tuple=thrust::tuple<thrust::transform_iterator<thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::plus>, thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::multiplies>, thrust::detail::functional::actor<thrust::detail::functional::argument<0U>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::counting_iterator<double, thrust::use_default, thrust::use_default, thrust::use_default>, thrust::use_default, thrust::use_default>, thrust::detail::normal_iterator<thrust::device_ptr<double>>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>, UnaryFunction=thrust::detail::device_dereference_iterator]" 
/usr/local/cuda-5.0/bin/../include/thrust/iterator/detail/zip_iterator.inl(160): here 
      instantiation of "thrust::detail::backend::dereference_result<thrust::zip_iterator<IteratorTuple>>::type thrust::detail::backend::dereference(const thrust::zip_iterator<IteratorTuple> &) [with IteratorTuple=thrust::tuple<thrust::transform_iterator<thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::plus>, thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::multiplies>, thrust::detail::functional::actor<thrust::detail::functional::argument<0U>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::counting_iterator<double, thrust::use_default, thrust::use_default, thrust::use_default>, thrust::use_default, thrust::use_default>, thrust::detail::normal_iterator<thrust::device_ptr<double>>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>]" 
/usr/local/cuda-5.0/bin/../include/thrust/detail/backend/cuda/for_each.inl(75): here 
      [ 24 instantiation contexts not shown ] 
      instantiation of "void thrust::detail::vector_base<T, Alloc>::allocate_and_copy(thrust::detail::vector_base<T, Alloc>::size_type, ForwardIterator, ForwardIterator, thrust::detail::vector_base<T, Alloc>::storage_type &) [with T=double, Alloc=thrust::device_malloc_allocator<double>, ForwardIterator=thrust::transform_iterator<thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::plus>, thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::multiplies>, thrust::detail::functional::actor<thrust::detail::functional::argument<0U>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::counting_iterator<double, thrust::use_default, thrust::use_default, thrust::use_default>, thrust::use_default, thrust::use_default>]" 
/usr/local/cuda-5.0/bin/../include/thrust/detail/vector_base.inl(191): here 
      instantiation of "void thrust::detail::vector_base<T, Alloc>::range_init(ForwardIterator, ForwardIterator, thrust::detail::false_type) [with T=double, Alloc=thrust::device_malloc_allocator<double>, ForwardIterator=thrust::transform_iterator<thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::plus>, thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::multiplies>, thrust::detail::functional::actor<thrust::detail::functional::argument<0U>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::counting_iterator<double, thrust::use_default, thrust::use_default, thrust::use_default>, thrust::use_default, thrust::use_default>]" 
/usr/local/cuda-5.0/bin/../include/thrust/detail/vector_base.inl(168): here 
      instantiation of "void thrust::detail::vector_base<T, Alloc>::init_dispatch(IteratorOrIntegralType, IteratorOrIntegralType, thrust::detail::false_type) [with T=double, Alloc=thrust::device_malloc_allocator<double>, IteratorOrIntegralType=thrust::transform_iterator<thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::plus>, thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::multiplies>, thrust::detail::functional::actor<thrust::detail::functional::argument<0U>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::counting_iterator<double, thrust::use_default, thrust::use_default, thrust::use_default>, thrust::use_default, thrust::use_default>]" 
/usr/local/cuda-5.0/bin/../include/thrust/detail/vector_base.inl(207): here 
      instantiation of "thrust::detail::vector_base<T, Alloc>::vector_base(InputIterator, InputIterator) [with T=double, Alloc=thrust::device_malloc_allocator<double>, InputIterator=thrust::transform_iterator<thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::plus>, thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::multiplies>, thrust::detail::functional::actor<thrust::detail::functional::argument<0U>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::counting_iterator<double, thrust::use_default, thrust::use_default, thrust::use_default>, thrust::use_default, thrust::use_default>]" 
/usr/local/cuda-5.0/bin/../include/thrust/device_vector.h(131): here 
      instantiation of "thrust::device_vector<T, Alloc>::device_vector(InputIterator, InputIterator) [with T=double, Alloc=thrust::device_malloc_allocator<double>, InputIterator=thrust::transform_iterator<thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::plus>, thrust::detail::functional::actor<thrust::detail::functional::composite<thrust::detail::functional::binary_operator<thrust::multiplies>, thrust::detail::functional::actor<thrust::detail::functional::argument<0U>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::detail::functional::value<double>, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>>, thrust::counting_iterator<double, thrust::use_default, thrust::use_default, thrust::use_default>, thrust::use_default, thrust::use_default>]" 
test/lambda.cu(27): here 
+1

你可以尝试从[这里](https://github.com/thrust/thrust/tree/master/thrust)下载开发v1.7版本的推力。我试了一下,似乎解决了这个问题。 –

+0

要更新推力,您可能需要超级用户权限。如果是这样,你可以做'git clone http:// github.com/thrust/thrust.git'然后将推力/推力的内容放到你的/ usr/local/cuda/include/thrust位置。 –

+0

谢谢! @RobertCrovella。推力v1.7和v1.6都可以工作。 cuda 5.0中的推力v1.53似乎太旧了。 – kangshiyin

回答

2

感谢@ RobertCrovella的建议。

将推力升级至v1.6/v1.7后,问题得以解决,而不更改问题中显示的代码。对于lambda表达式功能来说,cuda 5.0中的推力v1.53似乎太旧了。