Using Class Member Functions in Kernels

Hi,
I am having problems when I’m trying to call a member function of an integer queue class from a global kernel. I get an error as following : “expression must have class type”. I basically can not use any member functions defined in CPU. Anyone knows how to handle this problem ?

Thanks.

Can you show a short, complete example that demonstrates the problem?

I don’t think it should be difficult to call a class member function in device code, but probably I’m not understanding the problem.

Here’s a simple example:

$ cat t549.cu
#include <stdio.h>

class A{

    int data;
  public:
    A() { data = 0;}
    __host__ __device__
    void increment()  { data++;}
    __host__ __device__
    void print_data() { printf("data = %d\n", data);}
};

__global__ void test(A a){

  a.increment();
  a.print_data();
}

int main(){

  A h_a;
  h_a.increment();
  h_a.print_data();
  test<<<1,1>>>(h_a);
  cudaDeviceSynchronize();
}
$ nvcc -arch=sm_20 -o t549 t549.cu
$ cuda-memcheck ./t549
========= CUDA-MEMCHECK
data = 1
data = 2
========= ERROR SUMMARY: 0 errors
$