-1

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?

emher
  • 5,634
  • 1
  • 21
  • 32
  • 1
    What would `(void)thrust::reduce(threadIdx.x, threadIdx.x);` even do if it compiled? If you are going to ask a question about syntax errors and how to fix them, at least have the courtesy to show some real code and an actual compiler error and line number, no some nonsense pseudocode. – talonmies Oct 06 '13 at 17:43
  • I tried to provide a minimal example; as the error persists in this minimal example i thought it was better not to include the whole source. The compiler error is exactly as stated. I decided to provide the lines causing the errors instead of line number so that you wouldn't have to scroll through the xutility file. – emher Oct 06 '13 at 18:29

1 Answers1

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

kangshiyin
  • 9,681
  • 1
  • 17
  • 29
  • Your example works just fine. My example was stupid, of course i cannot launch thrust::reduce in a kernel. However i get the samme error if i wrap it a __host__ method. I can't use main, as i am calling the method from C# through a dll. – emher Oct 06 '13 at 18:27
  • You can use `main` if you create a standalone example. That is what you are being asked to do, and indeed what is expected for questions like this on SO. You said the error persists in a minimal example. Why not provide it, instead of a "stupid" example (to use your words)? – Robert Crovella Oct 06 '13 at 23:53