简单程序中的意外推力错误

Unexpected Thrust error in simple program

本文关键字:错误 意外 程序 简单      更新时间:2023-10-16

使用Visual Studio 2017和The The 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使用未定义的类型'throust ::详细信息:: result_of_adaptable_function'
C3646'type':未知覆盖词
C4430缺少类型的指定词 - 假设INT。注意:C 不支持Default-Int

其细节以

给出
1>main.cpp
1>c:program filesnvidia gpu computing toolkitcudav8.0includethrustdetailtype_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 filesnvidia gpu computing toolkitcudav8.0includethrustiteratordetailtransform_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 filesnvidia gpu computing toolkitcudav8.0includethrustiteratordetailiterator_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 filesnvidia gpu computing toolkitcudav8.0includethrustiteratordetailtransform_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 filesnvidia gpu computing toolkitcudav8.0includethrustiteratortransform_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 filesnvidia gpu computing toolkitcudav8.0includethrustdetailtype_traits.h(440): error C3646: 'type': unknown override specifier
1>c:program filesnvidia gpu computing toolkitcudav8.0includethrustdetailtype_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 有关。

您必须包括定义类型result_of_adaptable_function

的标头

之类的线
#include <thrust/detail/type_traits/result_of_adaptable_function.h>

应该做技巧。

您缺少适当的功能。