2017-06-04 66 views
3

使用Visual Studio 2017年和推力图书馆,我整理了以下程序:意外的推力错误

#include <thrust/iterator/counting_iterator.h> 
#include <thrust/iterator/transform_iterator.h> 

template<int c> 
struct computes_mod 
{ 
    auto operator()(int i) const 
    { 
     return i % c; 
    } 
}; 

int main() 
{ 
    auto ti = thrust::make_transform_iterator(thrust::make_counting_iterator(0), computes_mod<3>{}); 

    return 0; 
} 

不过,我得到以下编译器错误:

C2027使用未定义类型'thrust :: detail :: result_of_adaptable_function'
C3646'type':未知覆盖说明符
C4430缺少类型说明符 - int假定。注意:C++不支持默认int

其详细给出

1>main.cpp 
1>c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\thrust\detail\type_traits.h(440): error C2027: use of undefined type 'thrust::detail::result_of_adaptable_function<UnaryFunc (int),void>' 
1>  with 
1>  [ 
1>   UnaryFunc=computes_mod<3> 
1>  ] 
1>c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\thrust\iterator\detail\transform_iterator.inl(40): note: see declaration of 'thrust::detail::result_of_adaptable_function<UnaryFunc (int),void>' 
1>  with 
1>  [ 
1>   UnaryFunc=computes_mod<3> 
1>  ] 
1>c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\thrust\iterator\detail\iterator_adaptor_base.h(53): note: see reference to class template instantiation 'thrust::detail::eval_if<true,DefaultNullaryFn,thrust::detail::identity_<System>>' being compiled 
1>  with 
1>  [ 
1>   DefaultNullaryFn=thrust::detail::result_of_adaptable_function<computes_mod<3> (int),void>, 
1>   System=thrust::use_default 
1>  ] 
1>c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\thrust\iterator\detail\transform_iterator.inl(41): note: see reference to class template instantiation 'thrust::detail::ia_dflt_help<Reference,thrust::detail::result_of_adaptable_function<UnaryFunc (int),void>>' being compiled 
1>  with 
1>  [ 
1>   Reference=thrust::use_default, 
1>   UnaryFunc=computes_mod<3> 
1>  ] 
1>c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\thrust\iterator\transform_iterator.h(191): note: see reference to class template instantiation 'thrust::detail::transform_iterator_base<AdaptableUnaryFunction,Iterator,Reference,Value>' being compiled 
1>  with 
1>  [ 
1>   AdaptableUnaryFunction=computes_mod<3>, 
1>   Iterator=thrust::counting_iterator<int,thrust::use_default,thrust::use_default,thrust::use_default>, 
1>   Reference=thrust::use_default, 
1>   Value=thrust::use_default 
1>  ] 
1>[my_project]\main.cpp(32): note: see reference to class template instantiation 'thrust::transform_iterator<computes_mod<3>,thrust::counting_iterator<int,thrust::use_default,thrust::use_default,thrust::use_default>,thrust::use_default,thrust::use_default>' being compiled 
1>c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\thrust\detail\type_traits.h(440): error C3646: 'type': unknown override specifier 
1>c:\program files\nvidia gpu computing toolkit\cuda\v8.0\include\thrust\detail\type_traits.h(440): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 

我不知道为什么,编译器会报告该推力类型未定义或为什么我的代码导致错误首先。这看起来像一个标准的使用thrust::make_transform_iterator

为什么产生这个错误,我该如何解决?

此外,如果重要的是,我与标志

/DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CPP /std:c++latest 

谢谢你的帮助下编制的!

更新:上面的测试程序使用Clang成功编译。因此这个问题似乎与VC++具体有关。

回答

0

你必须包括定义类型result_of_adaptable_function

#include <thrust/detail/type_traits/result_of_adaptable_function.h> 

一个行应该能招的标头。

你错过了正确的包括使其工作。

+0

我添加了你的建议,但它不会改变输出的错误。我认为其他包括间接包含适当的推力/细节。 – Grayscale