使用Visual Studio 2017和Thrust库,我编译了以下程序:
#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使用未定义类型&#39; thrust :: detail :: result_of_adaptable_function&#39;
C3646&#39; type&#39 ;:未知的覆盖说明符
C4430缺少类型说明符 - 假设为int。注意:C ++不支持default-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类型未定义或为什么我的代码会导致错误开始。这在我看来就像thrust::make_transform_iterator
的标准用法。
为什么会产生此错误以及如何解决?
另外,如果它很重要,我用标志编译
/DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CPP /std:c++latest
感谢您的帮助!
更新:上面的测试程序使用Clang成功编译。因此,问题似乎与VC ++有关。
答案 0 :(得分:0)
您必须包含定义类型result_of_adaptable_function
像
这样的行#include <thrust/detail/type_traits/result_of_adaptable_function.h>
应该成功。
您缺少适当的包含以使其正常工作。