我有這段代碼,每次啓動都會崩潰。 我曾嘗試使用malloc/cudaMallocHost/cudeMalloc但它沒用。它認爲這是由於手動cufftComplex初始化發生的,但證明它不能,因爲沒有數據我不能得到fft。你能幫我消除這種崩潰嗎?在CUFFT 1-D FFT期間發生奇怪的崩潰
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <conio.h>
#include <cuda.h>
#include <cufft.h>
using namespace std;
int main(int argc, char **argv)
{
cufftHandle plan;
cufftComplex *data;
cufftComplex *digits;
cufftComplex *h_data;
cudaMallocHost((void**)&digits, sizeof(cufftComplex)*8);
digits[0].x = 12.5f; digits[0].y = 0.0f;
digits[1].x = 66.23f; digits[1].y = 0.0f;
digits[2].x = 35.1f; digits[2].y = 0.0f;
digits[3].x = 16.7f; digits[3].y = 0.0f;
digits[4].x = 14.83f; digits[4].y = 0.0f;
digits[5].x = 55.1f; digits[5].y = 0.0f;
digits[6].x = 11.7f; digits[6].y = 0.0f;
digits[7].x = 18.83f; digits[7].y = 0.0f;
cudaMalloc((void**)&data, sizeof(cufftComplex)*8);
cudaMemcpy(data, digits, sizeof(cufftComplex)*8, cudaMemcpyHostToDevice);
if (cufftPlan1d(&plan, 8, CUFFT_C2C, 1) != CUFFT_SUCCESS) {
fprintf(stderr, "Cuda: cufftPlan1d CUFFT_C2C failed\n");
return 1;
}
if (cufftExecC2C(plan, data, data, CUFFT_FORWARD) != CUFFT_SUCCESS) {
fprintf(stderr, "Cuda: cufftExecC2C CUFFT_FORWARD failed\n");
return 1;
}
if (cudaMalloc((void**)&h_data, sizeof(cufftComplex)*8) != cudaSuccess) {
fprintf(stderr, "Cuda: cudaMalloc((void**)&h_data failed\n");
return 1;
}
cudaMemcpy(h_data, data, sizeof(cufftComplex)*8, cudaMemcpyDeviceToHost);
printf("\nOriginal:\n");
for(int i = 0; i < 8; ++i){
printf("\nRe:%2.5f Im:%2.5f", digits[i].x, digits[i].y);
}
printf("\n\n1D-FFT:\n");
for(int i = 0; i < 8; ++i){
printf("\nRe:%2.5f Im:%2.5f", h_data[i].x, h_data[i].y);
}
cudaFree(digits);
cudaFree(data);
cudaFree(h_data);
cufftDestroy(plan);
}
謝謝澄清! –