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

Using Boost.Align and Boost.Numeric.uBlas with Intel MKL


Hello everybody,

for my project I need to call some basic BLAS routines from the Intel MKL library like gemm or syev. For convenience I wrote my own matrix class whose functions wrap around the BLAS function calls from the MKL library. Since I already use some components of the Boost library, I would like to replace my matrix class with the boost::numeric::ublas::matrix class.

Till now the underlying storage of my own matrix class is a std::unique_ptr whose data is allocated with mkl_malloc(..., 64) and has a custom deleter

template<typename T> struct Mkl_deleter { void operator()(T* p) { mkl_free(p); } };

to ensure the alignment to 64-Byte boundaries in order to maximize performance of the MKL routines. The ublas::matrix class allows to specify an allocator. Hence my idea is to use the boost::align::alined_allocator with 64-Byte alignment for the ublas::matrix class in order to maximize the performance of the MKL routines. Is this a good approach ? Does this yield the desired behavior ? Are there any  performance drawbacks ?

Best regards,

Felix Kaiser

0 Kudos
1 Reply

Hi Felix, 

There is one article talking about use use Boost* uBLAS with Intel® MKL. ;

I believe you had known this.  

Regardto replace your matrix class with the boost::numeric::ublas::matrix class and matrix alignment.  The function mkl_malloc (*.64)  do nothing special things, just allocate more continuous memory space , then return the 64 byte as start address, then use mkl_free to release all memory space.   

int *mallocedMemory = (int *)malloc(size+63);

alignedMemory = (int *)(((int)mallocedMemory + 63) & ~63);

 Given that the ublas::matrix class allows to specify an allocator,  if  you can modify  boost::align::alined_allocator with 64-Byte alignment,  then  yes, it should be no problem, it does same functionality as mkl_malloc, no drawback. 

Best Regards,


0 Kudos