Quantcast
Channel: Intel® Software - Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 3005

Output of 2DFFT is not matching when dimensions of size 128*128, 256*256,512*512

$
0
0

Hi,

I have written a program to check the correctness of 2D FFT using two different menthods.

First one has input data in complex format(real and imaginary are interlevaed).

2nd one has input data in de-interved format(two seperate arrays of real and imaginary parts).

we have two different routines available in MKL to solve this purpose. I found that the outputs are not mathcing using these routines when input size is 128*128, 256*256, 512*512,....

I included the code below. Please have a look and let me know if i do any mistake.

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <float.h>

#include <complex>

#define MKL_Complex8 std::complex<float>

#include "mkl_dfti.h"

#include "mkl.h"

int main(int argc, char* argv[])

{

printf("hi\n");

int N1 = atoi(argv[1]);

int N2 = atoi(argv[2]);

MKL_LONG status = 0;

 MKL_Complex8 *x = 0;

 MKL_Complex8 *y = 0;

 MKL_Complex8 *z = 0;

float* real;

float* imag;

float* real1;

float* imag1;

    DFTI_DESCRIPTOR_HANDLE hand = 0;

    DFTI_DESCRIPTOR_HANDLE hand1 =0;

    DFTI_DESCRIPTOR_HANDLE hand2 =0;

MKL_LONG N[2]; N[0] = N1; N[1] = N2;

        status = DftiCreateDescriptor(&hand, DFTI_SINGLE, DFTI_COMPLEX, 2, N);

if (0 != status) printf("failed\n");

status = DftiSetValue( hand, DFTI_PLACEMENT, DFTI_INPLACE );

if (0 != status) printf("failed\n");

status = DftiCommitDescriptor(hand);

if (0 != status) printf("failed\n");

x = (MKL_Complex8*)malloc(N1*N2*sizeof(MKL_Complex8));

real = (float*)malloc(N1*N2*sizeof(float));

imag = (float*)malloc(N1*N2*sizeof(float));



status = DftiCreateDescriptor(&hand1, DFTI_SINGLE, DFTI_COMPLEX, 2,N);

if (0 != status) printf("failed\n");

status = DftiSetValue(hand1, DFTI_COMPLEX_STORAGE, DFTI_REAL_REAL);

if (0 != status) printf("failed\n");

status = DftiCommitDescriptor(hand1);

if (0 != status) printf("failed\n");

for(int i = 0; i < N1*N2; i++)

{

x[i].real() =(float) i;

real[i] = i;

imag[i] = i+1;

x[i].imag() = (float)(i+1);

}

printf("before FFT\n");

for(int i =0 ; i < N1*N2; i++)

{

//printf(" (%f, %f)----------(%f, %f)\n",x[i].real(),x[i].imag(),real[i],imag[i]);

}

status = DftiComputeForward(hand, x);

if (0 != status) printf("failed\n");

status = DftiComputeForward(hand1,real, imag);

printf("after FFT prints if value not matches\n");

for(int i =0 ; i < N1*N2; i++)

{

    if(x[i].real()!= real[i] || x[i].imag() != imag[i])

    printf("not matching  %d -- (%f, %f)--------(%f, %f)\n",i,x[i].real(),x[i].imag(),real[i],imag[i]);

}

}

 

 

complie command: icc checkFFT.cpp -o checkFFT.o -mkl.

./checkFFT 128 128

 

 

Thanks

sivaramakrishna

 


Viewing all articles
Browse latest Browse all 3005


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>