xref: /aosp_15_r20/external/eigen/doc/UsingIntelMKL.dox (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li/*
2*bf2c3715SXin Li Copyright (c) 2011, Intel Corporation. All rights reserved.
3*bf2c3715SXin Li Copyright (C) 2011 Gael Guennebaud <[email protected]>
4*bf2c3715SXin Li
5*bf2c3715SXin Li Redistribution and use in source and binary forms, with or without modification,
6*bf2c3715SXin Li are permitted provided that the following conditions are met:
7*bf2c3715SXin Li
8*bf2c3715SXin Li * Redistributions of source code must retain the above copyright notice, this
9*bf2c3715SXin Li   list of conditions and the following disclaimer.
10*bf2c3715SXin Li * Redistributions in binary form must reproduce the above copyright notice,
11*bf2c3715SXin Li   this list of conditions and the following disclaimer in the documentation
12*bf2c3715SXin Li   and/or other materials provided with the distribution.
13*bf2c3715SXin Li * Neither the name of Intel Corporation nor the names of its contributors may
14*bf2c3715SXin Li   be used to endorse or promote products derived from this software without
15*bf2c3715SXin Li   specific prior written permission.
16*bf2c3715SXin Li
17*bf2c3715SXin Li THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18*bf2c3715SXin Li ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19*bf2c3715SXin Li WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20*bf2c3715SXin Li DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21*bf2c3715SXin Li ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22*bf2c3715SXin Li (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23*bf2c3715SXin Li LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24*bf2c3715SXin Li ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25*bf2c3715SXin Li (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26*bf2c3715SXin Li SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*bf2c3715SXin Li
28*bf2c3715SXin Li ********************************************************************************
29*bf2c3715SXin Li *   Content : Documentation on the use of Intel MKL through Eigen
30*bf2c3715SXin Li ********************************************************************************
31*bf2c3715SXin Li*/
32*bf2c3715SXin Li
33*bf2c3715SXin Linamespace Eigen {
34*bf2c3715SXin Li
35*bf2c3715SXin Li/** \page TopicUsingIntelMKL Using Intel® MKL from %Eigen
36*bf2c3715SXin Li
37*bf2c3715SXin Li<!-- \section TopicUsingIntelMKL_Intro Eigen and Intel® Math Kernel Library (Intel® MKL) -->
38*bf2c3715SXin Li
39*bf2c3715SXin LiSince %Eigen version 3.1 and later, users can benefit from built-in Intel® Math Kernel Library (MKL) optimizations with an installed copy of Intel MKL 10.3 (or later).
40*bf2c3715SXin Li
41*bf2c3715SXin Li<a href="http://eigen.tuxfamily.org/Counter/redirect_to_mkl.php"> Intel MKL </a> provides highly optimized multi-threaded mathematical routines for x86-compatible architectures.
42*bf2c3715SXin LiIntel MKL is available on Linux, Mac and Windows for both Intel64 and IA32 architectures.
43*bf2c3715SXin Li
44*bf2c3715SXin Li\note
45*bf2c3715SXin LiIntel® MKL is a proprietary software and it is the responsibility of users to buy or register for community (free) Intel MKL licenses for their products. Moreover, the license of the user product has to allow linking to proprietary software that excludes any unmodified versions of the GPL.
46*bf2c3715SXin Li
47*bf2c3715SXin LiUsing Intel MKL through %Eigen is easy:
48*bf2c3715SXin Li-# define the \c EIGEN_USE_MKL_ALL macro before including any %Eigen's header
49*bf2c3715SXin Li-# link your program to MKL libraries (see the <a href="http://software.intel.com/en-us/articles/intel-mkl-link-line-advisor/">MKL linking advisor</a>)
50*bf2c3715SXin Li-# on a 64bits system, you must use the LP64 interface (not the ILP64 one)
51*bf2c3715SXin Li
52*bf2c3715SXin LiWhen doing so, a number of %Eigen's algorithms are silently substituted with calls to Intel MKL routines.
53*bf2c3715SXin LiThese substitutions apply only for \b Dynamic \b or \b large enough objects with one of the following four standard scalar types: \c float, \c double, \c complex<float>, and \c complex<double>.
54*bf2c3715SXin LiOperations on other scalar types or mixing reals and complexes will continue to use the built-in algorithms.
55*bf2c3715SXin Li
56*bf2c3715SXin LiIn addition you can choose which parts will be substituted by defining one or multiple of the following macros:
57*bf2c3715SXin Li
58*bf2c3715SXin Li<table class="manual">
59*bf2c3715SXin Li<tr><td>\c EIGEN_USE_BLAS </td><td>Enables the use of external BLAS level 2 and 3 routines</td></tr>
60*bf2c3715SXin Li<tr class="alt"><td>\c EIGEN_USE_LAPACKE </td><td>Enables the use of external Lapack routines via the <a href="http://www.netlib.org/lapack/lapacke.html">Lapacke</a> C interface to Lapack</td></tr>
61*bf2c3715SXin Li<tr><td>\c EIGEN_USE_LAPACKE_STRICT </td><td>Same as \c EIGEN_USE_LAPACKE but algorithm of lower robustness are disabled. \n This currently concerns only JacobiSVD which otherwise would be replaced by \c gesvd that is less robust than Jacobi rotations.</td></tr>
62*bf2c3715SXin Li<tr class="alt"><td>\c EIGEN_USE_MKL_VML </td><td>Enables the use of Intel VML (vector operations)</td></tr>
63*bf2c3715SXin Li<tr><td>\c EIGEN_USE_MKL_ALL </td><td>Defines \c EIGEN_USE_BLAS, \c EIGEN_USE_LAPACKE, and \c EIGEN_USE_MKL_VML </td></tr>
64*bf2c3715SXin Li</table>
65*bf2c3715SXin Li
66*bf2c3715SXin LiThe \c EIGEN_USE_BLAS and \c EIGEN_USE_LAPACKE* macros can be combined with \c EIGEN_USE_MKL to explicitly tell Eigen that the underlying BLAS/Lapack implementation is Intel MKL.
67*bf2c3715SXin LiThe main effect is to enable MKL direct call feature (\c MKL_DIRECT_CALL).
68*bf2c3715SXin LiThis may help to increase performance of some MKL BLAS (?GEMM, ?GEMV, ?TRSM, ?AXPY and ?DOT) and LAPACK (LU, Cholesky and QR) routines for very small matrices.
69*bf2c3715SXin LiMKL direct call can be disabled by defining \c EIGEN_MKL_NO_DIRECT_CALL.
70*bf2c3715SXin Li
71*bf2c3715SXin Li
72*bf2c3715SXin LiNote that the BLAS and LAPACKE backends can be enabled for any F77 compatible BLAS and LAPACK libraries. See this \link TopicUsingBlasLapack page \endlink for the details.
73*bf2c3715SXin Li
74*bf2c3715SXin LiFinally, the PARDISO sparse solver shipped with Intel MKL can be used through the \ref PardisoLU, \ref PardisoLLT and \ref PardisoLDLT classes of the \ref PardisoSupport_Module.
75*bf2c3715SXin Li
76*bf2c3715SXin LiThe following table summarizes the list of functions covered by \c EIGEN_USE_MKL_VML:
77*bf2c3715SXin Li<table class="manual">
78*bf2c3715SXin Li<tr><th>Code example</th><th>MKL routines</th></tr>
79*bf2c3715SXin Li<tr><td>\code
80*bf2c3715SXin Liv2=v1.array().sin();
81*bf2c3715SXin Liv2=v1.array().asin();
82*bf2c3715SXin Liv2=v1.array().cos();
83*bf2c3715SXin Liv2=v1.array().acos();
84*bf2c3715SXin Liv2=v1.array().tan();
85*bf2c3715SXin Liv2=v1.array().exp();
86*bf2c3715SXin Liv2=v1.array().log();
87*bf2c3715SXin Liv2=v1.array().sqrt();
88*bf2c3715SXin Liv2=v1.array().square();
89*bf2c3715SXin Liv2=v1.array().pow(1.5);
90*bf2c3715SXin Li\endcode</td><td>\code
91*bf2c3715SXin Liv?Sin
92*bf2c3715SXin Liv?Asin
93*bf2c3715SXin Liv?Cos
94*bf2c3715SXin Liv?Acos
95*bf2c3715SXin Liv?Tan
96*bf2c3715SXin Liv?Exp
97*bf2c3715SXin Liv?Ln
98*bf2c3715SXin Liv?Sqrt
99*bf2c3715SXin Liv?Sqr
100*bf2c3715SXin Liv?Powx
101*bf2c3715SXin Li\endcode</td></tr>
102*bf2c3715SXin Li</table>
103*bf2c3715SXin LiIn the examples, v1 and v2 are dense vectors.
104*bf2c3715SXin Li
105*bf2c3715SXin Li
106*bf2c3715SXin Li\section TopicUsingIntelMKL_Links Links
107*bf2c3715SXin Li- Intel MKL can be purchased and downloaded <a href="http://eigen.tuxfamily.org/Counter/redirect_to_mkl.php">here</a>.
108*bf2c3715SXin Li- Intel MKL is also bundled with <a href="http://software.intel.com/en-us/articles/intel-composer-xe/">Intel Composer XE</a>.
109*bf2c3715SXin Li
110*bf2c3715SXin Li
111*bf2c3715SXin Li*/
112*bf2c3715SXin Li
113*bf2c3715SXin Li}
114