3

I have a base class:

  template <class T> 
  class A{
         public:
           // some data
           T data;
           //some functions like constructs etc.
            ...
           // one virtual function
           virtual void evaluate() = 0;

   }

and a derived class:

 template <class T> 
 class B:public A<T>{
          public:
          // some functions like constructors etc.
          virtual void evaluate();
          __global__ void function2();   // **** error message

 } 

Also, I have

 template <class T> void
 B<T>::evaluate()
 { 
    dim3 grid(1);dim3 block(1);  
    void function2<<<grid,block>>>();
 }

and

template <class T>  __global__ void B<T>::function2() // **** error message 
{
   // computation here
}

so essentially I have a member function of a derived class which I would like to execute in a parallel fashion on the device.

Unfortunately, I get the error:

error : illegal combination of memory qualifiers on the lines :

1> __global__ void function2();   // **** error message

2> template <class T>  __global__ void B<T>::function2() // **** error message

I am new to CUDA. It would be very kind if someone points me to my error. I am developing on Visual Studio 2010.

Vitality
  • 20,705
  • 4
  • 108
  • 146
user1612986
  • 1,373
  • 3
  • 22
  • 38
  • 5
    `__global__` functions cannot be class static members in CUDA. – talonmies Jul 08 '13 at 21:16
  • 1
    Here is the [documentation reference](http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#classes) for @talonmies comment. – Robert Crovella Jul 08 '13 at 21:32
  • 1
    My comment will not add anything new to what talonmies and Robert Crovella have already pointed out to you. Do you really need to define `function2` as a static member function? I'm also using template classes with CUDA under Visual Studio 2010 and I'm defining all my `__global__` functions as non-member functions. – Vitality Jul 08 '13 at 21:37
  • 1
    @talonmies I think this is sufficient as an answer. If you would post it as an answer I would upvote it. – Robert Crovella Jul 08 '13 at 21:40
  • Last comment. I would say that your question is independent on whether the class is derived or not. Could this detail of your post have been skipped? – Vitality Jul 08 '13 at 21:50
  • may i have a template then how to achieve what i am trying to do. for some "getting started" documentation i learnt that to implement a parallel function i need to put _global_ in front. and that is what i was trying. but i think my knowledge is not complete. – user1612986 Jul 08 '13 at 21:57

1 Answers1

3

The template class definition in your first code snippet is illegal because it contains a __global__ function (CUDA kernel). As per the language documentation, __global__ functions cannot be static class member functions. The second templated class member function is illegal for the same reason.

talonmies
  • 70,661
  • 34
  • 192
  • 269