Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.

New to MKL, Memory Crashes Occuring

Thomas_M_3
Beginner
978 Views

I am new to the MKL.  My platform is Win7 (64bit), Visual Studio 2010, and I am using the MSVC compiler / linker, not Intel.  I am building a 32 bit project.  I have version 11.1 of the Intel Compiler and whatever the associated MKL is.  I just made my first project in MSVC using MKL functions, and I'm getting fatal memory errors.

Running this project causes a fatal error.  I've tried it in the National Instruments C IDE as well, and it causes "dynamic memory corruption" and general protection faults.  What's going on?? I configured MSVC 2010 to use MKL by the following steps: including the 32 bit static libraries: mkl_core.lib, mkl_intel_c.lib, mkl_intel_thread.lib, and libiomp5md.lib.  In addition, I placed libiomp5md.dll in my executable directory and added the MKL ia32 include directory to my include paths.

#include "mkl.h"
#include <stdio.h>
#include <string.h>
#include <math.h>#define ARRAYSIZE 8096static double* fftArray = NULL;
static double* zeros = NULL;
static MKL_LONG status;
static DFTI_DESCRIPTOR_HANDLE descriptorHandle;void initializeFFT()
{
int i;for (i = 0; i < ARRAYSIZE; i++)
fftArray = sin((double)i/3) + sin((double)i/30) + sin((double)i/100);memset(zeros, 0, ARRAYSIZE * sizeof(double));
}int main()
{
fftArray = (double*)mkl_malloc(ARRAYSIZE * sizeof(double), 16);
zeros = (double*)mkl_malloc(ARRAYSIZE * sizeof(double), 16);
intializeFFT();
DftiCreateDescriptor(&descriptorHandle, DFTI_DOUBLE, DFTI_COMPLEX, 1, ARRAYSIZE);
DftiCommitDescriptor(descriptorHandle);
status = DftiComputeForward(descriptorHandle, fftArray, zeros);
DftiFreeDescriptor(&descriptorHandle);mkl_free_buffers();
}

0 Kudos
6 Replies
Evgueni_P_Intel
Employee
978 Views
Hi Thomas, If you expect MKL to do complex-to-complex FFT of length ARRAYSIZE, please allocate 2*sizeof(double)*ARRAYSIZE bytes for the input array and 2*sizeof(double)*ARRAYSIZE bytes for the output array. Thanks, Evgueni.
0 Kudos
Thomas_M_3
Beginner
978 Views
Thanks, that might be the problem. Let me ask a quick clarification though. If I'm performing the complex FFT in place, two buffers are required: real in/out, and imaginary in/out. If my real and imaginary data that I need transformed are both, say, 4096 pts long, I have two buffers that are 4096. You are saying I cannot simply pass these two 4096 element buffers to the FFT function, that I need to double the length of both the real and imaginary input buffers to 8096? I was under the impression that the output from an FFT was always the length of the input. Therefore if you had a real and an imaginary buffer both of ARRAYSIZE, the output would also be two buffers of ARRAYSIZE. What part of this is wrong?
0 Kudos
Evgueni_P_Intel
Employee
978 Views
If you want MKL to do an FFT in-place on real and imaginary parts stored in different arrays (split-complex numbers), please add [cpp] DftiSetValue(&descriptorHandle, DFTI_COMPLEX_STORAGE, DFTI_REAL_REAL); [/cpp] between the following lines [cpp] DftiCreateDescriptor(&descriptorHandle, DFTI_DOUBLE, DFTI_COMPLEX, 1, ARRAYSIZE); DftiCommitDescriptor(descriptorHandle); [/cpp] Without DFTI_COMPLEX_STORAGE set to DFTI_REAL_REAL, MKL interprets DftiComputeForward(handle, x, y) as out-of-place FFT on interleaved complex data. You may also want to check the examples examples/dftc/source/config_complex_storage.c in the MKL intallation directory. Thanks, Evgueni.
0 Kudos
Thomas_M_3
Beginner
978 Views
Thanks - this is what I think I was missing! I was just reading the documentation for DftiComputeForward, which lists: status = DftiComputeForward(desc_handle, xre_inout, xim_inout); as one of the four parameter options. However, it was missing the key configuration information that you provided! I looked over the examples again as you suggested, and indeed the 1D in place complex transform uses an array of type "_Complex", which I did not notice before.
0 Kudos
Evgueni_P_Intel
Employee
978 Views
We will pass your input to the MKL documentation team. Thank you for trying Intel MKL!
0 Kudos
Thomas_M_3
Beginner
978 Views
I just wanted to update the thread that the suggested fix works. As an aside, I tested the speed of both interleaved (COMPLEX_COMPLEX) and separate-array (REAL_REAL) storage for the complex forward transform. As expected, the interleaved data storage leads to faster execution time.
0 Kudos
Reply