记录 | CUDA编程中用constexpr替代__host__&__device__
发布时间
阅读量:
阅读量
例如,在使用 __host__ 与 __device__ 的情形中,具体表现如下:
#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;
}
}
此时可采用 constexpr 作为 __host__ __device 的替代方案,替换后的代码示例如下:
#include <cstdio>
#include <cuda_runtime.h>
全部评论 (0)
还没有任何评论哟~
