gpt4 book ai didi

c++ - 推力 (CUDA) 错误 : function cannot be called with the given argument list

转载 作者:行者123 更新时间:2023-11-30 05:12:06 25 4
gpt4 key购买 nike

我正在尝试使用未知版本的 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));

}
};

struct gpu_queries 的标签成员定义为:

thrust::device_vector<int> label;

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

提前致谢!

附言相关文档:

最佳答案

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

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

我认为这背后的原因在于上面提供的组修改链接中的声明“UnaryFunction 是一元函数的模型,并且 UnaryFunction 不通过其参数应用任何非常量操作”。

关于c++ - 推力 (CUDA) 错误 : function cannot be called with the given argument list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44700341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com