Search code examples
cudathrust

how to add a static member to thrust::binary_predicate?


I'm trying to add a static member to the following type:

struct mostRightCornerPred
{
    __host__ __device__ 
    static int numIterations;   
    bool operator()(const long long first,const long long seconds) const
    {
        return true;
    }

};

but I keep on getting an error:

1>c:\users\igal\desktop\pj1712 fixed map res\graph\types.h(21): error
: attribute "__host__" does not apply here
1>c:\users\igal\desktop\pj1712 fixed map res\graph\types.h(21): error
: memory qualifier on data member is not allowed

My guess is that CUDA can't refer to this member. How can I fix it?


Solution

  • Even looking past the syntax errors in your code, static data in device code is illegal. The reason is that there is no defined point at which it would be initialized, if all threads would do so, or if just one, and if so, which thread. So static data just doesn't make sense in this context.

    I believe this limitation is discussed in the CUDA programming guide.

    If you want data members in a functor, just add a constructor to your functor and initialize the data using an argument to the constructor.