Reputation: 4224
I am trying to compile some CUDA code that was originally made in VS2013 using unknown version of CUDA.
I'm using GCC and CUDA 8.0. Here is where it trips up (method of 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++;
}
}
The error message (first part) is:
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
The arg_max_functor is defined in the same file as:
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));
}
};
The label member of struct gpu_queries is defined as:
thrust::device_vector<int> label;
Obviously, there is some argument type mismatch here, but I'm not sure how to fix this, I'm a bit new to CUDA-specific things. Any ideas how to fix this?
Thanks in advance!
P.S. Relevant documentation:
Upvotes: 2
Views: 1184
Reputation: 4224
This problem is solved by adding the "const" modifier to the argument of the unary function. Apparently, it wasn't explicitly enforced by the compiler in some earlier version of CUDA. In this case, inside arg_max_functor
, the proper definition is:
__host__ __device__ void operator()(const thrust::tuple<float&, float&,int&> & mx_curr_argmx) const
I think the reason behind this is in the statement "UnaryFunction is a model of Unary Function, and UnaryFunction does not apply any non-constant operation through its argument" in the link to group modifying provided above.
Upvotes: 1