Please enable JavaScript to view this site.

Memory Validator Help

Navigation: » No topics above this level «

Working with Intel Math Kernel Library

Scroll Prev Top Next More

This topic describes how to use C++ Memory Validator when you are developing programs with the Intel Math Kernel Library.

 

Intel Math Kernel Library

 

The Intel Math Kernal Library (MKL) provides memory allocation functions for you to use to allocate memory aligned on specific memory boundaries for performance reasons.

 

The allocations functions provided by MKL mimic the basic C allocation functions malloc(), calloc(), realloc() and free(). These are provided in the form of mkl_malloc(), mkl_calloc(), mkl_realloc() and mkl_free().

 

It is natural that you would wish Memory Validator to track these allocations. MKL is provided in both statically linked and dynamically linked forms. Because of the way MKL is built it is not possible for Memory Validator to just track the MKL allocations as with a normal allocator. This is because MKL uses the C runtime heap internally and also allocates various memory for housekeeping tasks. To track your usage of MKL correctly we should not report on the internal workings of MKL or it's housekeeping tasks.

 

The solution to this to call MKL functions via some Software Verify functions. We provide two source files for you to permanently include in your software. If your program is not being profiled by Memory Validator, the mkl functions are called directly. If your program is being profiled by Memory Validator, the mkl function (de)(re)allocations are tracked and the associated underlying CRT allocations and housekeeping are ignored.

 

Usage

 

Follow the following steps to change your program to use MKL and allow MKL allocations to be tracked by Memory Validator.

 

Source Files

Include svl_mkl_helper.h and svl_mkl_helper.cpp in each DLL/EXE that uses Intel Math Kernel Library.

 

You can use these two source files without any royalty payments to Software Verify Limited. We expect these two files to be used by your software. While we believe these source files are fit for purpose and we have tested them to our satisfaction, you use them at your own risk and should satisfy yourself that they work correctly and to your satisfaction.

 

Initialisation

Call svl_mkl_init() before you call any MKL function. This applies to each DLL/EXE.

 

For example if your program has an EXE that uses MKL and a DLL that uses both the EXE and the DLL must call svl_mkl_init().

 

Replace function calls

call svl_mkl_malloc() rather than mkl_malloc()

call svl_mkl_calloc() rather than mkl_calloc()

call svl_mkl_realloc() rather than mkl_realloc()

call svl_mkl_free() rather than mkl_free()

call svl_mkl_free_buffers() rather than mkl_free_buffers()

call svl_mkl_free_thread_buffers() rather than mkl_free_thread_buffers()

 

The parameters passed to the svl_mkl_...() functions are the same as the parameters pass to mkl_...() functions. No change is needed.

 

Running your program without Memory Validator

 

Your program will run as normal when Memory Validator is not present. The MKL library functions will be called.

 

Running your program with Memory Validator

 

Your program will run as normal when Memory Validator is present. The MKL library functions will be called and the allocations and deallocations will be tracked by Memory Validator