Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Memory Leak in MKL

Gera__Danny
Beginner
4,193 Views

Our program analyzes several images every few seconds. Each image is processed in its own thread. The threads are ordinary Windows threads. MKL functions are used in the process. We used a memory leak detection tool to find leaks in the application (Memory Validator by Software Verification). The tool revealed a leak in calls to MKL vsMul function (32 bits for each image). The call stack is as follows:

vsMul->mkl_vml_kernel_GetTTableIndex->_vmlGetThreadLocalData

I found a note in Intel documentation (https://software.intel.com/en-us/mkl-windows-developer-guide-avoiding-memory-leaks-in-intel-mkl) and accordingly I tried to use both the mkl_disable_fast_mm function and the MKL_DISABLE_FAST_MM environment variable. None of them helped to eliminate the memory leak.

How can I overcome this memory leak problem?

0 Kudos
11 Replies
Gennady_F_Intel
Moderator
4,192 Views

Did you try to call mkl_free_buffers after the last call to Intel MKL functions?

 

0 Kudos
Gera__Danny
Beginner
4,192 Views

Our application runs on an industrial machine and needs to be robust enough to run 24/7. Calling mkl_free_buffers before exiting the program does not help because the leaking buffers will continue to be accumulated as the program runs. Calling mkl_free-thread_buffers before exiting a thread may make more sense, but it is hard to do without compromising OOP structure (There are several types of algorithmic threads, only some of them call vsMul). I still don't understand why calling mkl_disable_fast_mm does nothing, or is there an inherent memory leak?

0 Kudos
Maria_K_Intel
Employee
4,192 Views

Hello,

That's correct. mkl_disable_fast_mm doesn't allow MKL to use fast internal memory allocations. What MKL version do you use? Could you please share a small reproducer with MKL functions that you use? It will help us a lot to figure out what causes a memory leak.

0 Kudos
Gera__Danny
Beginner
4,192 Views

We use MKL version 2019.1.144. I tried to create a small example of the problem, but unfortunately the problem was not reproduced in a small example. I tried to call vsMul in a loop, each time in a different thread, and even several threads running concurrently, but the test showed no leak. I don't know what is different in our full application. Timing, maybe, or maybe the numbers in the vectors do matter.

0 Kudos
Gennady_F_Intel
Moderator
4,192 Views

may be this is some kind of false positives reported by this tool. we never try such tool in the past. We usually use Intel Inspector to check same sort of problems ( deadlocks, mem leaks and etc...). 

0 Kudos
Gera__Danny
Beginner
4,192 Views

I finally succeeded to create a small example with the leak problem. The trick is to perform the thread creation and calculation from within a DLL. I attach to the message my source files and the Memory validation tool report (as a PDF). The MKL_Test file is the program main. The MKL_TestAux files were compiled in a separate DLL that was called from the main program.

Any idea what is happening here?

0 Kudos
Gennady_F_Intel
Moderator
4,192 Views

and did you try Intel(R) Inspector tool to check these leaks?

0 Kudos
Gera__Danny
Beginner
4,192 Views

No, we don't have Inspector. 

So far, all the leaks our memory tool (C++ Memory Validator from Software Verification) found were real.

I would also add (maybe it is relevant) that we run 64 bit system on Visual Studio 2012.

0 Kudos
Gera__Danny
Beginner
4,192 Views

Well, please, does anybody have any idea or had a look in the example I uploaded?

 

0 Kudos
Gera__Danny
Beginner
4,192 Views

Well, it took me a while, but finally I got time to install Inspector and run the same test with Inspector analysis. The memory leak is still there, according to Inspector report. I attach here a zip file with all the analysis files. The source code was uploaded previously.

It seems like there is a real problem with our usage of MKL.

0 Kudos
Orra__Oriol
Beginner
4,192 Views

Hello everyone,

I have the same issue as Danny.

I create some worker threads to do some calculations inside a DLL, and then does not deallocate the memory.

I am trying to use the functions: 

            MKL_Disable_Fast_MM();
             mkl_disable_fast_mm();

            MKL_Thread_Free_Buffers();
            mkl_thread_free_buffers();

            MKL_Free_Buffers();
            mkl_free_buffers();

But it is not making any difference, Could you give us a solution?

 

Thanks you very much,

0 Kudos
Reply