Quantcast
Viewing all articles
Browse latest Browse all 536

How to use Boost* uBLAS with Intel® MKL?

You can take advantage of Intel® MKL, if you are used to uBLAS, by performing BLAS matrix-matrix multiplication in C++ using Intel MKL substitution of Boost uBLAS functions.

uBLAS pertains to the Boost C++ open-source libraries and provides BLAS functionality for dense, packed, and sparse matrices. The library uses an expression template technique for passing expressions as function arguments, which enables evaluating vector and matrix expressions in one pass without temporary matrices. uBLAS provides two modes:

-   Debug (safe) mode, default.
Type and conformance checking is performed.

-   Release (fast) mode.
Enabled by the NDEBUG preprocessor symbol.

The documentation for the Boost uBLAS is available at www.boost.org/.

Example in this KB article demonstrates how to overload prod() function for substituting uBLAS dense matrix-matrix multiplication with the Intel MKL gemm calls. Though these functions break uBLAS expression templates and introduce temporary matrices, the performance advantage can be considerable for matrix sizes that are not too small (roughly, over 50).

You do not need to change your source code to use the functions. To call them:

-   Include the header file mkl_boost_ublas_matrix_prod.hpp in your code (from the attached mkl_and_boost_examples zip file).

-   Add appropriate Intel MKL libraries to the link line.

 

Only the following expressions are substituted:

prod( m1, m2 )

prod( trans(m1), m2 )

prod( trans(conj(m1)), m2 )

prod( conj(trans(m1)), m2 )

prod( m1, trans(m2) )

prod( trans(m1), trans(m2) )

prod( trans(conj(m1)), trans(m2) )

prod( conj(trans(m1)), trans(m2) )

prod( m1, trans(conj(m2)) )

prod( trans(m1), trans(conj(m2)) )

prod( trans(conj(m1)), trans(conj(m2)) )

prod( conj(trans(m1)), trans(conj(m2)) )

prod( m1, conj(trans(m2)) )

prod( trans(m1), conj(trans(m2)) )

prod( trans(conj(m1)), conj(trans(m2)) )

prod( conj(trans(m1)), conj(trans(m2)) )

These expressions are substituted in the release mode only (with NDEBUG preprocessor symbol defined). Supported uBLAS versions are Boost 1.34.1, 1.35.0, 1.36.0, and 1.37.0

A code example provided in the attached zip file ublas/ource/sylvester.cpp file illustrates usage of the Intel MKL uBLAS header file for solving a special case of the Sylvester equation.

To run the Intel MKL ublas examples, specify the BOOST_ROOT parameter in the make command, for instance, when using Boost version 1.37.0:

make lib32 BOOST_ROOT=<your_path>/boost_1_37_0

 

  • mkl with boost
  • mkl ublas
  • mkl and boost/ublas
  • Linux*
  • OS X*
  • Windows*
  • C/C++
  • Intel® Math Kernel Library
  • URL

  • Viewing all articles
    Browse latest Browse all 536

    Trending Articles



    <script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>