有个问题,困扰了几天,向各位求助!这里多谢了。
RT:
整个程序是对图像进行卷积滤波,采用CUFFT库。
1。 对滤波函数filter补零,再做调用CUFFT做FFT正变换。
2。 对图像signal每行补零,同样调用CUFFT,并用batch实现多行同时处理。
3。 再用一行的filter对多行的signal进行分别线性乘法。
4。 得到的信号再调用CUFFT反变换。
问题是:当赋给不同的图像时,有的结果正确,有的不正确。给同一图像不同的滤波函数也是有的正确,有的结果不正确。
我怀疑是核函数写得有问题,我的核函数如下。
dim3 dimBlock(256, 1); //每个block的线程维度
dim3 dimGrid((new_size+dimBlock.x-1)/dimBlock.x, (SIGNAL_HEIGHT+dimBlock.y-1)/dimBlock.y); //每个Grid中的块维度
ComplexPointwiseMulAndScale<<<dimGrid, dimBlock>>>(d_signal, d_filter_kernel, new_size, SIGNAL_HEIGHT,1.0f / new_size);
static global void ComplexPointwiseMulAndScale(Complex* a, const Complex* b, int size, int height,float scale)
{
//改高度没问题
const int x = blockIdx.xblockDim.x + threadIdx.x;
const int y = blockIdx.yblockDim.y + threadIdx.y;
const int batch_x = blockDim.xgridDim.x;
const int batch_y = blockDim.ygridDim.y;
if (x<size&&y<height)
{
for (int j=y; j<height; j+=batch_y)
{
for (int i=x; i<size; i+=batch_x)
{
a[i+size*j] = ComplexScale(ComplexMul(a[i+size*j], b[i]), scale);
}
}
}
}
请高手指点!谢谢