CUFFT程式,記憶體錯誤
以下是我的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;
}