使用CUDA只读缓存有两个办法
1.你可以使用内部函数__ldg来通过只读缓存直接对数组进行读取访问:
但是我的汇报错,说__ldg未定义,非常玄奇,不知道有没有老铁看了知道的告诉我一下
__global__ void copyKernel(int *out,int *in){
int idx = blockIdx.x*blockDim.x+threadIdx.x;
out[idx] = __ldg(&in[idx]);
}
2.使用__restrict__ 和constant
__global__ void copyKernel_2(int *__restrict__ out,const int *__restrict__ in){
int idx = blockIdx.x*blockDim.x+threadIdx.x;
out[idx] = in[idx];
}
都可以。