1

我是 lambda 表达式的新手。我正在尝试data[10]使用以下公式初始化推力装置矢量,

数据[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
4

1 回答 1

2

感谢@RobertCrovella 的建议。

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

于 2013-01-11T21:18:28.207 回答