0
点赞
收藏
分享

微信扫一扫

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


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

比如:

#include <cstdio>
#include <cuda_runtime.h>

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

__global__ void kernel(){
    say_hello();
}

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


举报

相关推荐

0 条评论