[問題] CUDA CUFFT對二維矩陣執行單x軸或y軸的傅立葉轉換

看板C_and_CPP (C/C++)作者 (aada)時間16年前 (2010/01/29 23:08), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串1/1
請問一下關於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
雖然這不是錯誤原因 但是把 i*H+j 改成 i*W+j 比較正確
01/30 01:59, 1F

01/30 02:28, , 2F
謝謝您
01/30 02:28, 2F
文章代碼(AID): #1BOldGEb (C_and_CPP)
文章代碼(AID): #1BOldGEb (C_and_CPP)