记录 | CUDA编程中的 __host__ & __device__ 双重修饰

通过 __host____device__ 双重修饰符,可以把函数同时定义在 CPU 和 GPU 上,这样 CPU 和 GPU 都可以调用

比如:

#include 
#include 

__host__ __device__ void say_hello(){
    printf("Hello, world!\n");
}

__global__ void kernel(){
    say_hello();
}

int main(){
    kernel<<<1, 1>>>();
    cudaDeviceSynchronize();
    say_hello();
    return 0;
}

你可能感兴趣的:(踩坑记录,CUDA,C++,host,device,CUDA编程)