Skip to content

Instantly share code, notes, and snippets.

@mickeyouyou
Created December 25, 2019 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mickeyouyou/8fd3ee76f2ae9c44f18a82b71533b00e to your computer and use it in GitHub Desktop.
Save mickeyouyou/8fd3ee76f2ae9c44f18a82b71533b00e to your computer and use it in GitHub Desktop.
cuda kernel member function
#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();
}
@MoharramBagheri
Copy link

I have 2 questions

  1. I have no problem with int data[10] as member variable but How can I use member variable like int* ?
  2. How can I transfer class definition and Implementation to other file and include it in the main file? I got some strange error !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment