CUFFT程式,記憶體錯誤

taker1986 2009-12-25 10:35:02
以下是我的CUFFT程式,
想問為什麼我最後串出來的值都是0,
而且最後會出現記憶體錯誤

於 0x00000000 的 memcp.exe 中發生未處理的例外狀況: 0xC0000005: 讀取位置
0x00000000 時發生存取違規

該怎麼修改呢,謝謝

#include <stdio.h>
#include <stdlib.h>
#include <cuda.h>
#include <cufft.h>

#define NX 2
#define BATCH 2

int main()
{
cufftHandle plan;
cufftComplex *data;
cudaMalloc((void**)&data, sizeof(cufftComplex)*NX*BATCH);

int a[NX]={1,2};
float b[NX];
cudaMemcpy(data, a, sizeof(cufftComplex)*NX*BATCH, cudaMemcpyHostToDevice);

/* Create a 1D FFT plan. */
cufftPlan1d(&plan, NX, CUFFT_C2C, BATCH);

/* Use the CUFFT plan to transform the signal in place. */
cufftExecC2C(plan, data, data, CUFFT_FORWARD);

/* Inverse transform the signal in place. */
cufftExecC2C(plan, data, data, CUFFT_INVERSE);

cudaMemcpy(b, data, sizeof(cufftComplex)*NX*BATCH, cudaMemcpyDeviceToHost);
printf("a[0]=%f, a[1]=%f", b[0], b[1]);

/* Destroy the CUFFT plan. */
cufftDestroy(plan);
cudaFree(data);

system("PAUSE");
return 0;
}
...全文
291 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
bell_cindrella 2010-07-17
  • 打赏
  • 举报
回复
我想问下楼主,问题怎么解决的?那个cufftComplex该如何赋值呢?
  • 打赏
  • 举报
回复
因为cufft是根据fftw写的,fftw文档说明
FFTW computes an unnormalized transform, in that there is no coefficient in front of
the summation in the DFT. In other words, applying the forward and then the backward
transform will multiply the input by n.

所以二维的也一样,要得到正确结果就要除以(H*W)
  • 打赏
  • 举报
回复
研究不多,回答不上.呵呵.
taker1986 2009-12-26
  • 打赏
  • 举报
回复
上面的問題解決了, 謝謝
但是為什麼我經過兩次FFT出來,輸出與輸入的值是不一樣呢,
輸出值只要除以T就為輸入了,為什麼呢

#include <stdio.h>
#include <stdlib.h>
#include <cuda_runtime.h>
#include <cutil.h>
#include <cufft.h>

#define H 2
#define W 2
#define T H*W

int main()
{
cufftComplex aaa[H][W]={{1, 2, 3, 4.5},{5, 6 ,7 ,8}};
cufftHandle plan;
cufftComplex *idata, *odata, *odata1;

cudaMalloc((void**)&odata1, sizeof(cufftComplex)*T);
cudaMalloc((void**)&odata, sizeof(cufftComplex)*T);
cudaMalloc((void**)&idata, sizeof(cufftComplex)*T);

cudaMemcpy(idata, aaa, sizeof(cufftComplex) * T,cudaMemcpyHostToDevice);

cufftPlan2d(&plan, H, W, CUFFT_C2C);
cufftExecC2C(plan, idata, odata, CUFFT_FORWARD);

cufftPlan2d(&plan, H, W, CUFFT_C2C);
cufftExecC2C(plan, odata, odata, CUFFT_INVERSE);

cufftComplex host_odata[T];
cudaMemcpy(host_odata, odata, sizeof(cufftComplex)*T, cudaMemcpyDeviceToHost);

cufftDestroy(plan);
cudaFree(idata);
cudaFree(odata);
}
  • 打赏
  • 举报
回复
int/float能与cufftComplex直接copy嘛?

231

社区成员

发帖
与我相关
我的任务
社区描述
CUDA on Windows XP
社区管理员
  • CUDA on Windows XP社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧