Html/CSS
CUDA编程 标签描述

CUDA编程中使用ifdef指令控制生成CPU和GPU代码 比如: include<cstdio> include<cuda_runtime.h> __host____device__voidsay_hello(){ ifdef__CUDA_ARCH__ printf("Hello,worldfromGPU!\n"); else printf("Hello,worldfromCPU!\n"); endif } __global__voidkernel(){ say_hello(); } intmain(){ kernel<<<1,1>&...

比如用__host__&__device__的情况如下: include<cstdio> include<cuda_runtime.h> __host____device__voidsay_hello(){ printf("Hello,world!\n"); } __global__voidkernel(){ say_hello(); } intmain(){ kernel<<<1,1>>>(); cudaDeviceSynchronize(); say_hello(); return0; } } 则可以用cons...