[英]cuFFT in column direction
我有一個 nx * ny 的復矩陣。 我只想在列方向上執行 FFT。 一種方法是轉置整個矩陣,然后使用 cufftPlan1d 獲得 FFT。 有沒有其他有效的方法可以在不進行矩陣轉置的情況下獲得 FFT。 cufftPlanMany 將有助於在列方向獲得 fft。 例如,讓我們假設 nx = 8192 和 ny = 32768。 cufftPlanMany 的參數如下:
rank = 1;
idist = 1 // distance b/w batches
odist = 1
istride = nx
ostride = nx
int inembed[]={nx}
int onembed[]={nx}
cufftPlanMany(&plan,rank,ny,&inembed,istride,idist,&oneembed,ostride,odist,CUFFT_C2C,1)
這是使用 cufftPlanMany 的正確方法嗎?
您提到了批次和 1D,因此我假設您想要進行行式 1D 變換或列式 1D 變換。
在這種情況下,批次數等於行數情況下的行數或列數情況下的列數。
對於一維變換, inembed
和onembed
並不重要,但它們不能設置為 NULL。
idist
、 istride
、 odist
和ostride
參數是本示例中需要更改的關鍵參數(與batch
)。 使用 CUFFT 高級數據布局信息。
這是一個工作示例,顯示了按行和按列的轉換:
$ cat t1620.cu
#include <cufft.h>
#include <iostream>
int main(){
cufftComplex data[] = {
{1.0f, 0}, {2.0f, 0}, {3.0f, 0}, {4.0f, 0},
{1.0f, 0}, {2.0f, 0}, {3.0f, 0}, {4.0f, 0},
{1.0f, 0}, {2.0f, 0}, {3.0f, 0}, {4.0f, 0},
{1.0f, 0}, {2.0f, 0}, {3.0f, 0}, {4.0f, 0}};
cufftComplex *d_data;
int ds = sizeof(data)/sizeof(data[0]);
cudaMalloc(&d_data, ds*sizeof(data[0]));
cudaMemcpy(d_data, data, ds*sizeof(data[0]), cudaMemcpyHostToDevice);
cufftHandle plan;
int dim = 4;
int rank = 1;
int nx = dim;
int ny = dim;
#ifdef ROW_WISE
int batch = ny;
int inembed[rank] = {nx};
int onembed[rank] = {nx};
int istride = 1;
int idist = nx;
int ostride = 1;
int odist = nx;
int n[] = {nx};
#else
int batch = nx;
int inembed[rank] = {ny};
int onembed[rank] = {ny};
int istride = nx;
int idist = 1;
int ostride = nx;
int odist = 1;
int n[] = {ny};
#endif
cufftResult err = cufftPlanMany(&plan, rank, n, inembed,
istride, idist, onembed, ostride,
odist, CUFFT_C2C, batch);
std::cout << "plan :" << (int)err << std::endl;
err = cufftExecC2C(plan, d_data, d_data, CUFFT_FORWARD);
std::cout << "exec :" << (int)err << std::endl;
cudaMemcpy(data, d_data, ds*sizeof(data[0]), cudaMemcpyDeviceToHost);
for (int i = 0; i < ds; i++) std::cout << data[i].x << "," << data[i].y << std::endl;
return 0;
}
$ nvcc -o t1620 t1620.cu -lcufft -DROW_WISE
$ ./t1620
plan :0
exec :0
10,0
-2,2
-2,0
-2,-2
10,0
-2,2
-2,0
-2,-2
10,0
-2,2
-2,0
-2,-2
10,0
-2,2
-2,0
-2,-2
$ nvcc -o t1620 t1620.cu -lcufft
$ ./t1620
plan :0
exec :0
4,0
8,0
12,0
16,0
0,0
0,0
0,0
0,0
0,0
0,0
0,0
0,0
0,0
0,0
0,0
0,0
$
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.