关于纹理存储器的使用

版主
我在用纹理存储器做图像的均值滤波,问题处代码如下
float output_value_B =
tex2D(texRef,(float)(x-1),(float)(y-1)).x+ tex2D(texRef,(float)x,(float)(y-1)).x+ tex2D(texRef,(float)(x+1),(float)(y-1)).x+ tex2D(texRef,(float)(x-1),(float)y).x + tex2D(texRef,(float)x,(float)y).x + tex2D(texRef,(float)(x+1),(float)y).x + tex2D(texRef,(float)(x-1),(float)(y+1)).x+ tex2D(texRef,(float)x,(float)(y+1)).x+ tex2D(texRef,(float)(x+1),(float)(y+1)).x;
此时为什么tex2D说是未定义的标示符错误提示“没有匹配参数的实例重载函数"tex2D"”难道是头文件的设置问题吗
纹理定义及绑定的部分代码如下
texture<float4,2>texRef;
//分配纹理存储器cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(32,32,32,32,cudaChannelFormatKindFloat); cudaArraycuArray; checkCudaErrors(cudaMallocArray(&cuArray,&channelDesc,width,height)); checkCudaErrors(cudaMemcpy2DToArray(cuArray,0,0,hos_Image_f4,widthsizeof(float4),width * sizeof(float4),height,cudaMemcpyHostToDevice)); checkCudaErrors(cudaBindTextureToArray(&texRef,cuArray,&channelDesc));

楼主您好:

(1)您的tex2D()用法正确。没有任何问题。
(2)您的头文件无需担心设置错误,会自动#include的(如果你没有include的话)
(3)唯一可能的原因是您(或者他人)额外#define tex2D成其他函数了,建议检查这里。

感谢来访。
(昨日就看到您的问题了,但是始终论坛无法回帖,点击回复出不来,于是等到了半夜论坛好了)

谢谢版主的回答,问题解决了

可考虑使用NPP库中的函数box filter.