thrust (CUDA) error: function cannot be called with the given argument list

thrust (CUDA) error: function cannot be called with the given argument list

我正在尝试使用未知版本的 CUDA 编译一些最初在 VS2013 中制作的 CUDA 代码。

我正在使用 GCC 和 CUDA 8.0。 这是它绊倒的地方(struct gpu_queries 的方法):

void updateLabelsFromProbs(std::vector<thrust::device_vector<float> >& 
probabilities, thrust::device_vector<float>& tmpBuffer){
        thrust::fill(label.begin(), label.end(), 0);
        auto& mx = tmpBuffer;
        thrust::fill(mx.begin(), mx.end(), -1);
        int i = 0;
        for (auto& pr : probabilities){
            auto first = thrust::make_zip_iterator(thrust::make_tuple(mx.begin(), pr.begin(), label.begin()));
            auto last = thrust::make_zip_iterator(thrust::make_tuple(mx.end(), pr.end(), label.end()));
            thrust::for_each(first, last, arg_max_functor(i));//error HERE
            i++;
        }
    }

错误消息(第一部分)是:

error: function "arg_max_functor::operator()" cannot be called with the given argument list
            argument types are: (thrust::detail::tuple_of_iterator_references<float &, float &, int &, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type, thrust::null_type>)
            object type is: arg_max_functor

arg_max_functor 在与以下文件相同的文件中定义:

struct arg_max_functor {
    const int curentIdx;
    arg_max_functor(int i) : curentIdx(i) {}
    //current max, current val, current max idx
    __host__ __device__ void operator()(thrust::tuple<float&, float&,int &> & mx_curr_argmx) const 
    {
        bool currentValBigger = thrust::get<0>(mx_curr_argmx) < thrust::get<1>(mx_curr_argmx);
        thrust::get<2>(mx_curr_argmx) = (currentValBigger ? curentIdx : thrust::get<2>(mx_curr_argmx));
        thrust::get<0>(mx_curr_argmx) = (currentValBigger ? thrust::get<1>(mx_curr_argmx) : thrust::get<0>(mx_curr_argmx));

    }
};

结构gpu_queries的标签成员定义为:

thrust::device_vector<int> label;

显然,这里有些参数类型不匹配,但我不确定如何解决这个问题,我对 CUDA 特定的东西有点陌生。有什么解决办法吗?

提前致谢!

P.S。 相关文档:

这个问题通过在一元函数的参数中添加"const"修饰符来解决。显然,在某些早期版本的 CUDA 中,编译器并未明确强制执行它。在这种情况下,在 arg_max_functor 中,正确的定义是:

__host__ __device__ void operator()(const thrust::tuple<float&, float&,int&> & mx_curr_argmx) const

我认为这背后的原因在上面提供的 link 组修改中的语句 "UnaryFunction is a model of Unary Function, and UnaryFunction does not apply any non-constant operation through its argument" 中。