hi guys
i am new in cuda. i m getting problem with this code. i got this code by googling on net
#include <stdio.h>
#include <math.h>
#include<complex.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <cufft.h>
#define N 128
int main()
{
//Allocate arrays on the host
float *kx,*ky,*r;
float scale;
kx =(float*)malloc(sizeof(float)*N);
ky =(float*)malloc(sizeof(float)*N);
r = (float*)malloc(sizeof(float)*N*N);
// Aloocate arrays on the GPU with cudaMalloc
float *kx_d, *ky_d, *r_d;
cudaMalloc((void **)&kx_d, sizeof(cufftComplex)*N);
cudaMalloc((void **)&ky_d, sizeof(cufftComplex)*N);
cudaMalloc((void **)&r_d, sizeof(cufftComplex)*N*N);
cufftComplex *r_complex_d;
cudaMalloc((void **)&r_complex_d, sizeof(cufftComplex)*N*N);
// initialize r, kx and ky on the host
//Transfer data from host to device with cudaMemcpy(target,source,size,direction)
cudaMemcpy(kx_d,kx,sizeof(float)*N , cudaMemcpyHostToDevice);
cudaMemcpy(ky_d,ky,sizeof(float)*N , cudaMemcpyHostToDevice);
cudaMemcpy(r_d,r,sizeof(float)*N*N , cudaMemcpyHostToDevice);
//Creat plan for CUDA FFT
cufftHandle plan;
cufftPlan2d(&plan,N,N,CUFFT_C2C);
/* compute the execution configuration NB:
block_size_x*bloxk_size_y = number of threads */
dim3 dimBlock(N, N);
dim3 dimGrid(N/dimBlock.x, N/dimBlock.y);
// Hnadle N not multiple of block_size_x or block_size_y
if (N%N !=0) dimGrid.x+=1;
if (N%N !=0) dimGrid.y+=1;
// Copy real data to complex data
__global__ void real2complex(float *a, cufftComplex *c, int N) {
//compute idx and idy, the location of the element in the original NxN array
int idx = blockId.x*blockDim.x+threadIdx.x;
int idy = blockId.y*blockDim.y+threadIdx.y;
if (idx<N && idy<N)
{
int index = idx + idy*N;
c[index].x = a[index];
c[index].y = 0.f;
}
}/
// Transform real input to complex input
real2complex<<<dimGrid,dimBlock>>>(r_d,r_complex_d,N);
// Compute in place forward FFT
cufftExecC2C(plan,r_complex_d, r_complex_d,CUFFT_FORWARD);
//solve_possion
__global__ void solve_poission(cufftComplex *c, float *kx, float *ky, int N) {
// compute idx and idy, the location of the elemtn in the original NxN array
int idx = blockId.x*blockDim.x+threadIdx.x;
int idy = blockId.y*blockDim.y+threadIdx.y;
if (idx <N && idy<N)
{
int index = idx + idy*N;
float scale = - (kx[idx]*kx[idx] + ky[idy]*ky[idy]);
if (idx == 0 && idy == 0) scale = 1.f;
scale = 1.f/scale;
c[index].x*=scale;
c[index].y*=scale;
}
}
//solve poisson equation in Fourier space
solve_possion<<<dimGrid,dimBlock>>>(r_complex_d,kx_d,ky_d,N);
//Compute in place inverse FFT
cufftExecC2C(plan,r_complex_d,r_complex_d, CUFFT_INVERSE);
// comlex2real_scaled copy real part of complex data into real array and apply scaling
__global__ void complex2real_scaled(cufftComplex *c, float *a, int N, float scale) {
// compute idx and idy, the location of the element in the origina NxN array
int idx = blockId.x*blockDim.x+threadIdx.x;
int idy = blockId.y*blockDim.x+threadIdx.y;
if (idx <N && idy <N)
{
int index = idx + idy*N;
a[index] = scale*c[index].x;
}
}
/*copy the solution to a real array and apply scaling (anFFT followed
by iFFT will give you back the same array times the length of the transform)*/
scale = 1.f/((float)N * (float)N);
complex2real_scaled<<<dimGrid, dimBlock>>>(r_d,r_complex_d,N,scale);
/*Transfer data from device to host withcudaMemcpy(target,source,size,direction)*/
cudaMemcpy(r,r_d,sizeof(float)*N*N, cudaMemcpyDeviceToHost);
// distroy plan and clean up memory on device
cufftDestroy(plan);
cudaFree(r_complex_d);
cudaFree(kx_d);
cudaFree(r_d);
cudaFree(ky_d);
}
on running this code its giving error
exm_lavi.cu(54): error: expected a “)”
exm_lavi.cu(54): error: expected a “;”
exm_lavi.cu(69): warning: parsing restarts here after previous syntax error
exm_lavi.cu(75): error: expected a “)”
exm_lavi.cu(75): error: expected a “;”
exm_lavi.cu(92): warning: parsing restarts here after previous syntax error
exm_lavi.cu(100): error: expected a “)”
exm_lavi.cu(100): error: expected a “;”
exm_lavi.cu(114): warning: parsing restarts here after previous syntax error
exm_lavi.cu(115): error: argument of type “float *” is incompatible with parameter of type “cufftComplex *”
exm_lavi.cu(115): error: argument of type “cufftComplex *” is incompatible with parameter of type “float *”
exm_lavi.cu(115): error: too many arguments in function call
exm_lavi.cu(115): warning: variable “scale” is used before its value is set
9 errors detected in the compilation of “/tmp/tmpxft_0000037a_00000000-4_exm_lavi.cpp1.ii”.
what i missing in code.
i m using OS- Linux-x86_64 Driver-260.19.29 cudatoolkit 3.2
Nvidia Card- GeForce 9800 GT
please help