如果我声明了一个无边界的纹理对象
cudaResourceDesc resDesc;
memset(&resDesc, 0, sizeof(resDesc));
resDesc.resType = cudaResourceTypeLinear;
resDesc.res.linear.devPtr = device_global_memory_ptr;
resDesc.res.linear.desc.f = cudaChannelFormatKindUnsigned;
resDesc.res.linear.desc.x = 8 /* 8 bit */ ;
resDesc.res.linear.desc.y = resDesc.res.linear.desc.x;
resDesc.res.linear.desc.z = resDesc.res.linear.desc.x;
resDesc.res.linear.desc.w = resDesc.res.linear.desc.x;
resDesc.res.linear.sizeInBytes = buffer_bytes_size;
cudaTextureDesc texDesc;
memset(&texDesc, 0, sizeof(texDesc));
texDesc.readMode = cudaReadModeElementType;
texDesc.filterMode = cudaFilterModePoint;
texDesc.addressMode[0] = cudaAddressModeBorder;
texDesc.addressMode[1] = cudaAddressModeBorder;
texDesc.addressMode[2] = cudaAddressModeBorder;
cudaTextureObject_t tex1;
cudaCreateTextureObject(&tex1, &resDesc, &texDesc, NULL);
我后来在CUDA内核中将其用作
uchar4 pixel = tex1Dfetch<uchar4>(tex1, index);
我还能从2D纹理缓存中受益吗?还是缓存取决于
tex1Dfetch
指令?不幸的是,我无法获得上面的代码来使用tex2D
。 最佳答案
不,我不会获得2D纹理缓存的好处。
如果您仅使用tex2D
也不行:我通过使用cudaMallocArray
正确分配数据,然后使用tex2D
使其工作。