Memory Leak when Using Intel® MKL


R
eference ID: DPD200263491, DPD200087809, DPD200085701

Problem Description:

•1.    Some tools may report memory leak when using Intel® MKL, for example, DPD200087809, Valgrind reported an "Invalid read of size 8" when calling MKL PARDISO on Linux MKL 10.0.4.023

•2.    Intel® MKL program crashes after running some time or memory grow over time and ultimately crash. For example, DPD200263491 zgemm in Intel® MKL 10.1.1.019 32bit with custom dll sequential mode causes crash with stack message

#0  0xffffe424 in __kernel_vsyscall ()
#1  0xb67f47ff in raise () from /lib/libc.so.6
#2  0xb67f60dc in abort () from /lib/libc.so.6
#3  0xb6830fd7 in __libc_message () from /lib/libc.so.6
#4  0xb6836ffb in malloc_printerr () from /lib/libc.so.6
#5  0xb6837d7b in _int_free () from /lib/libc.so.6
#6  0xb683badd in free () from /lib/libc.so.6
#7  0xaeeba19d in mkl_serv_deallocate ()   from /usr/local/lib/libmkl_custom.so
#8  0x00000008 in () ??
#9  0xaf1f97d8 in mkl_blas_p4m3_zgemm_freebufs_htn ()   from /usr/local/lib/libmkl_custom.so
#10 0xaf2edff4 in  () from /usr/local/lib/libmkl_custom.so

Root Cause and Resolution:

•1. Memory Management in MKL.

Please see MKL user guide=> Intel MKL Memory Management Software

Intel MKL has memory management software that controls memory buffers being used by the library functions. New buffers that the library allocates when your application calls Intel MKL are not deallocated until the program ends. To get the amount of memory allocated by the memory management software, call the mkl_mem_stat() function. If your program needs to free memory, call mkl_free_buffers(). If another call is made to a library function that needs a memory buffer, the memory manager again allocates the buffers and they again remain allocated until either the program ends or the program deallocates the memory. This behavior facilitates better performance. However, some tools may report this behavior as a memory leak.

The memory management software is turned on by default. To turn it off, set the MKL_DISABLE_FAST_MM environment variable to any value or call the mkl_disable_fast_mm() function. Be aware that this change may negatively impact performance of some Intel MKL routines, especially for small problem sizes.

So the solution is either to call mkl_free_buffers() after mkl function call

Or use mkl_disable_fast_mm()/MKL_DISABLE_FAST_MM to disable the memory management.

For example, DPD200263491 can be resolved by call mkl_free_buffers() after mkl function call.

while (i<10000) {

so = dlopen(lib_mkl_custom.so, RTLD_NOW);

/* get the addresses of the functions */

...

zgemm();

mkl_free_buffers();

dlclose(so);

++i;

}

•2. Real Function Bugs

Please check MKL bug fix list:

Intel® MKL 10.2 fixes List.

Intel® MKL 10.3 Bug Fixes

For example,

DPD200085701

MKL leaks memory even when freeing buffers with mkl_free_buffers() after each MKL operation

DPD200087809

Memory leak in OOC PARDISO, some data structures are not deallocated.

They are fixed in Intel MKL 10.2 update 5 (23 Apr 2010) and MKL 10.2 update 4 (19 Feb 2010) respectively.

Solution: try the latest version if possible

•3. Memory Leak in Intel OpenMP Library

As Intel MKL is threaded by Intel OpenMP library, which is provided by Intel® Composer XE 2011, the function behaviors is influenced by Intel OpenMP library.

Please see Intel® Composer XE 2011 Compilers Fixes List: /en-us/articles/intel-composer-xe-2011-compilers-fixes-list

DPD200167301

C

OpenMP* memory leak under windows

libiomp5md.dll  5.0.2007.1022 DOES not leak
libiomp5md.dll  5.0.2010.924 DOES leak.

The problem was fixed in Composer XE update 4 (Aug 2011),

Solution: try the latest version if possible

Here is MKL version info in Composer XE

Which version of the Intel® IPP, Intel® MKL and Intel® TBB Libraries are Included in the Intel® Composer Bundles?

Which version of Intel IPP, Intel MKL and Intel TBB is installed by the Intel® Compiler Professional Edition V11.*?

•4. Other Unknown Problems

If neither using the latest MKL version, or using mkl_free_buffers()Or using mkl_disable_fast_mm()/MKL_DISABLE_FAST_MM, the memory leak always insist.

Please create simple test case and submit it to premier.intel.com or Intel MKL forum

as valgrind invalid read mkl_serv_mkl_get_max_threads


Operating System :

Windows, Linux and MAC OS* X

[DISCLAIMER: The information on this web site is intended for hardware system manufacturers and software developers. Intel does not warrant the accuracy, completeness or utility of any information on this site. Intel may make changes to the information or the site at any time without notice. Intel makes no commitment to update the information at this site. ALL INFORMATION PROVIDED ON THIS WEBSITE IS PROVIDED "as is" without any express, implied, or statutory warranty of any kind including but not limited to warranties of merchantability, non-infringement of intellectual property, or fitness for any particular purpose. Independent companies manufacture the third-party products that are mentioned on this site. Intel is not responsible for the quality or performance of third-party products and makes no representation or warranty regarding such products. The third-party supplier remains solely responsible for the design, manufacture, sale and functionality of its products. Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries. *Other names and brands may be claimed as the property of others.]

 

Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.