[問題] CUDA CUFFT對二維矩陣執行單x軸或y軸的傅立葉轉換
請問一下關於CUDA CUFFT對二維矩陣執行單x軸或y軸的傅立葉轉換,
我用MATLAB執行來驗證CUDA跑得對不對,
執行結果應該為:
8 8 8 8
0 0 0 0
0 0 0 0
0 0 0 0
但在CUDA上跑的結果為
(8.000000) (0.000000) (0.000000) (8.000000)
(0.000000) (0.000000) (8.000000) (0.000000)
(0.000000) (8.000000) (0.000000) (0.000000)
(-4.000000) (-4.000000) (-4.000000) (220.000000)
是否能請板上的大大提示一下, 以下是我的程式碼
謝謝
#include <stdio.h>
#include <stdlib.h>
#include <cuda_runtime.h>
#include <cutil.h>
#include <cufft.h>
#include <math.h>
#define H 4
#define W 4
#define T H*W
int main()
{
cufftReal *aaa;
aaa = (cufftReal*) malloc( sizeof(cufftReal)*(T) );
for(int i=0; i<H; i++)
{
for(int j=0; j<W; j++)
{
aaa[i*H+j] = 2.0;
}
}
cufftHandle plan;
cufftComplex *odata;
cufftReal *idata;
cudaMalloc( (void**)&idata, sizeof(cufftReal)*(T) );
cudaMalloc( (void**)&odata, sizeof(cufftComplex)*(T) );
cudaMemcpy(idata, aaa, sizeof(cufftReal) * T,cudaMemcpyHostToDevice);
cufftPlan1d(&plan, W, CUFFT_R2C, H);
cufftExecR2C(plan, (cufftReal*)idata, odata);
cuComplex *FFT_odata;
cudaMemcpy( FFT_odata, odata, sizeof(cufftComplex)*T, cudaMemcpyDeviceToHost
);
/**/
for(int i=0; i <H; i++)
{
for(int j=0; j <W; j++)
{
printf("[%d][%d] = (%5f) ", i, j, FFT_odata[i*H+j].x );
}
printf("\n");
}
cufftDestroy(plan);
cudaFree(idata);
cudaFree(odata);
system("PAUSE");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.122.192.147
→
01/30 01:59, , 1F
01/30 01:59, 1F
→
01/30 02:28, , 2F
01/30 02:28, 2F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章