Created
December 25, 2019 02:33
-
-
Save mickeyouyou/8fd3ee76f2ae9c44f18a82b71533b00e to your computer and use it in GitHub Desktop.
cuda kernel member function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have 2 questions