Thanks very much again for the reply LSChien. I cannot upload right for some reason I don’t know…
but the code is not a lot so I ll just post it here.
This is the main.cpp file from which I m sending the audio array:
[codebox]
// includes, system
#include
#include <stdlib.h>
#include
#include
#include <cufft.h>
#include <cuda.h>
// Required to include CUDA vector types
#include <vector_types.h>
#include “cutil_inline.h”
const float PI = 3.14159265;
extern “C” void runTest(unsigned int len, cufftComplex* c1, cufftComplex* c2);
int main(int argc, char** argv)
{
// input data
const int len = 1000;
int memSize = len * sizeof(float);
float* floatArray;
cufftComplex* h_COMPLEX_DATA, *h_COMPLEX_DATA2;
// Memory allocation
floatArray = (float *) malloc(memSize);
h_COMPLEX_DATA = (cufftComplex*)malloc( sizeof(cufftComplex)*len ) ;
h_COMPLEX_DATA2 = (cufftComplex*)malloc( sizeof(cufftComplex)*len ) ;
for(int i=0;i<len;i++)
{
floatArray[i] = sin(2*PI*500/len*i) + 1; // create sine wave at 500Hz and convert -1 - 1 range to 0 - 1 range
floatArray[i] *= 0.5f;
h_COMPLEX_DATA[i].x = floatArray[i];
h_COMPLEX_DATA[i].y = 0;
}
// run the device part of the program
runTest(len, h_COMPLEX_DATA, h_COMPLEX_DATA2);
for(int x=0;x<len;x++)
{
floatArray[x] = h_COMPLEX_DATA2[x].x;
}
for(int i=0;i<100;i++)
{
printf("%f\n", floatArray[i]);
}
cutilExit(argc, argv);
free(floatArray);
return 0;
}
[/codebox]
And this is the .cu file thats receives the array, transforms it and sends it back :
[codebox]
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cufft.h>
#include <cutil_inline.h>
const float PI = 3.14159265;
extern “C” void
runTest(unsigned int len, cufftComplex* c1, cufftComplex* c2)
{
cudaSetDevice( cutGetMaxGflopsDeviceId() );
cufftResult result;
cufftHandle plan;
cufftComplex* COMPLEX_DATA, *COMPLEX_DATA2;
cutilSafeCall(cudaMalloc((void**)&COMPLEX_DATA,
sizeof(cufftComplex)*len));
cutilSafeCall(cudaMalloc((void**)&COMPLEX_DATA2,
sizeof(cufftComplex)*len));
// copy data from host to device
cutilSafeCall(cudaMemcpy(COMPLEX_DATA, c1, len, cudaMemcpyHostToDevice));
result = cufftPlan1d(&plan, len, CUFFT_C2C, 1);
result = cufftExecC2C(plan, COMPLEX_DATA, COMPLEX_DATA2, CUFFT_FORWARD);
// copy results from device to host
cutilSafeCall(cudaMemcpy(c2, COMPLEX_DATA2, len, cudaMemcpyDeviceToHost));
// cleanup memory
cutilSafeCall(cudaFree(COMPLEX_DATA2));
cutilSafeCall(cudaFree(COMPLEX_DATA));
cufftDestroy(plan);
cudaThreadExit();
}
[/codebox]
Well thats about it really. Thanks for all the help again.