我正在通过简单的示例学习在 CUDA 中使用纹理。我尝试了以下示例,但它不起作用。它显示值为 0。
#include "cuPrintf.cu"
texture<int,1,cudaReadModeElementType> ref;
__global__ void kernel(int *a)
{
int b=tex1D(ref,0);
cuPrintf("value is %d",b);
}
int main()
{
int *a;
cudaMalloc((void**)&a,32000*sizeof(int));
cudaMemset(a,1,32000*sizeof(int));
cudaChannelFormatDesc bit = cudaCreateChannelDesc<int>();
cudaBindTexture(0,ref,a,bit,32000*sizeof(int));
kernel<<<1,1>>>(a);
}