0

嗨,我必须使用 CUFFT 对两个信号 [pulseMatrixRow[i] 和 pulse[i]] 进行卷积。因为我的代码是 int main(int argc, char **argv)

{
FILE *fileWritePtr;
cufftComplex h_signal[NX*BATCH];
cufftComplex h_filter_signal[NX*BATCH];
cufftComplex hf_signal[NX*BATCH];   

// Initalize the memory for the signal
for (unsigned int i = 0; i < SIGNAL_SIZE; ++i)
{
    h_signal[i].x = pulseMatrixRow[i];
    h_signal[i].y = pulseMatrixRow[i];
}

// device memory allocation 
    cudaMalloc((void**)&d_signal, sizeof(cufftComplex)*NX*BATCH);

// transfer to device memory
cudaMemcpy(d_signal, h_signal, sizeof(cufftComplex)*NX*BATCH, cudaMemcpyHostToDevice);



// Initalize the memory for the filter
for (unsigned int i = 0; i < FILTER_signal_SIZE; ++i)

{
    h_filter_signal[i].x = pulse[i];
    h_filter_signal[i].y = pulse[i];
}


// device memory allocation 
    cudaMalloc((void**)&d_filter_signal, sizeof(cufftComplex)*NX*BATCH);

// transfer to device memory
   cudaMemcpy(d_filter_signal, h_filter_signal, sizeof(cufftComplex)*NX*BATCH,         cudaMemcpyHostToDevice);

  // CUFFT plan

  cufftPlan1d(&plan, NX, CUFFT_C2C, BATCH);

  // Transform signal and fsignal

 printf("Transforming signal cufftExecC2C\n");
  cufftExecC2C(plan, (cufftComplex *)d_signal, (cufftComplex *)d_signal,     CUFFT_FORWARD);


printf("Transforming filter_signal cufftExecC2C\n");
cufftExecC2C(plan, (cufftComplex *)d_filter_signal, (cufftComplex     *)d_filter_signal, CUFFT_FORWARD);



// Multiply the coefficients together 
ComplexPointwiseMulAndScale<<<blocksPerGrid, threadsPerBlock>>>(d_signal, d_filter_signal, NX, 1.0f/NX*BATCH);


// Transform signal back
printf("Transforming signal back cufftExecC2C\n");
cufftExecC2C(plan, (cufftComplex *)d_signal, (cufftComplex *)d_signal, CUFFT_INVERSE);



// transfer results from GPU memory 


cudaMemcpy(hf_signal, d_signal, sizeof(cufftComplex)*NX*BATCH,cudaMemcpyDeviceToHost);


fileWritePtr = fopen("OutputData1.txt","w+");

for(i = 0; i < NX ; i++){
    //printf("%f %f\n", i, hf_signal[i].x, hf_signal[i].y);
     fprintf(fileWritePtr,"%d %f %f\n", i, hf_signal[i].x, hf_signal[i].y);
     }
fclose(fileWritePtr);



//Destroy CUFFT context
cufftDestroy(plan);

 // cleanup memory
 cudaFree(d_signal);
 cudaFree(d_filter_signal);


 // free(h_signal);
 // free(h_filter_signal);

return 0;

 }

我的 matlab 生成的 pulseMatrix 代码如下:

pulse = [ones(1,50) zeros(1,500-50)];
pulseMatrix = repmat(pulse,10,1);
pulseMatrix = pulseMatrix.';
pulseMatrixRow = pulseMatrix(:);

但我必须一次只处理 1000 个 pulseMatrixRow 样本,然后一个一个地休息为 1000 个。由于我的 fft 是 1024.,请告诉我必须如何以及在哪个阶段在输入信号的末尾填充零,以及我的滤波器信号简单地给出为脉冲 = [ones(1,50) zeros(1,500- 50)];

4

1 回答 1

1

您可以memset()在将主机内存传输到设备内存之前将其填充为零,或者

cudaMemset()在执行 fft 之前和主机到设备内存传输之后,您可以使用将设备内存的填充归零。

使用方法请参考此链接memset()

使用方法请参考此链接cudaMemset()

于 2013-01-24T11:03:08.327 回答