问题
I would like to use thrust reduction in my CUDA application. Hence I include the header and call the function:
#include <thrust\reduce.h>
__host__ void reduction(){
unsigned int t = 0;
thrust::reduce(t,t);
}
However I get compile errors (only one type): "name followed by "::" must be a class or namespace". The problem is with a file called xutility (which i haven't touched). All errors are related to the follow class definition:
// TEMPLATE CLASS iterator_traits
template<class _Iter>
struct iterator_traits
{ // get traits from iterator _Iter
typedef typename _Iter::iterator_category iterator_category;
typedef typename _Iter::value_type value_type;
typedef typename _Iter::difference_type difference_type;
typedef difference_type distance_type; // retained
typedef typename _Iter::pointer pointer;
typedef typename _Iter::reference reference;
};
I am not really into template programming. What am I doing wrong?
回答1:
Thrust routines are all designed to be invoked from the host side rather than in the kernels.
See this for the example of using thrust::reduce
.
https://github.com/thrust/thrust/blob/master/examples/sum.cu
来源:https://stackoverflow.com/questions/19209736/cuda-thrust-xutility-name-followed-by-must-be-a-class-or-namespace