GeneralMatrixMatrix_MKL.h
Go to the documentation of this file.
00001 /*
00002  Copyright (c) 2011, Intel Corporation. All rights reserved.
00003 
00004  Redistribution and use in source and binary forms, with or without modification,
00005  are permitted provided that the following conditions are met:
00006 
00007  * Redistributions of source code must retain the above copyright notice, this
00008    list of conditions and the following disclaimer.
00009  * Redistributions in binary form must reproduce the above copyright notice,
00010    this list of conditions and the following disclaimer in the documentation
00011    and/or other materials provided with the distribution.
00012  * Neither the name of Intel Corporation nor the names of its contributors may
00013    be used to endorse or promote products derived from this software without
00014    specific prior written permission.
00015 
00016  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00020  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00023  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027  ********************************************************************************
00028  *   Content : Eigen bindings to Intel(R) MKL
00029  *   General matrix-matrix product functionality based on ?GEMM.
00030  ********************************************************************************
00031 */
00032 
00033 #ifndef EIGEN_GENERAL_MATRIX_MATRIX_MKL_H
00034 #define EIGEN_GENERAL_MATRIX_MATRIX_MKL_H
00035 
00036 namespace Eigen { 
00037 
00038 namespace internal {
00039 
00040 /**********************************************************************
00041 * This file implements general matrix-matrix multiplication using BLAS
00042 * gemm function via partial specialization of
00043 * general_matrix_matrix_product::run(..) method for float, double,
00044 * std::complex<float> and std::complex<double> types
00045 **********************************************************************/
00046 
00047 // gemm specialization
00048 
00049 #define GEMM_SPECIALIZATION(EIGTYPE, EIGPREFIX, MKLTYPE, MKLPREFIX) \
00050 template< \
00051   typename Index, \
00052   int LhsStorageOrder, bool ConjugateLhs, \
00053   int RhsStorageOrder, bool ConjugateRhs> \
00054 struct general_matrix_matrix_product<Index,EIGTYPE,LhsStorageOrder,ConjugateLhs,EIGTYPE,RhsStorageOrder,ConjugateRhs,ColMajor> \
00055 { \
00056 static void run(Index rows, Index cols, Index depth, \
00057   const EIGTYPE* _lhs, Index lhsStride, \
00058   const EIGTYPE* _rhs, Index rhsStride, \
00059   EIGTYPE* res, Index resStride, \
00060   EIGTYPE alpha, \
00061   level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/, \
00062   GemmParallelInfo<Index>* /*info = 0*/) \
00063 { \
00064   using std::conj; \
00065 \
00066   char transa, transb; \
00067   MKL_INT m, n, k, lda, ldb, ldc; \
00068   const EIGTYPE *a, *b; \
00069   MKLTYPE alpha_, beta_; \
00070   MatrixX##EIGPREFIX a_tmp, b_tmp; \
00071   EIGTYPE myone(1);\
00072 \
00073 /* Set transpose options */ \
00074   transa = (LhsStorageOrder==RowMajor) ? ((ConjugateLhs) ? 'C' : 'T') : 'N'; \
00075   transb = (RhsStorageOrder==RowMajor) ? ((ConjugateRhs) ? 'C' : 'T') : 'N'; \
00076 \
00077 /* Set m, n, k */ \
00078   m = (MKL_INT)rows;  \
00079   n = (MKL_INT)cols;  \
00080   k = (MKL_INT)depth; \
00081 \
00082 /* Set alpha_ & beta_ */ \
00083   assign_scalar_eig2mkl(alpha_, alpha); \
00084   assign_scalar_eig2mkl(beta_, myone); \
00085 \
00086 /* Set lda, ldb, ldc */ \
00087   lda = (MKL_INT)lhsStride; \
00088   ldb = (MKL_INT)rhsStride; \
00089   ldc = (MKL_INT)resStride; \
00090 \
00091 /* Set a, b, c */ \
00092   if ((LhsStorageOrder==ColMajor) && (ConjugateLhs)) { \
00093     Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > lhs(_lhs,m,k,OuterStride<>(lhsStride)); \
00094     a_tmp = lhs.conjugate(); \
00095     a = a_tmp.data(); \
00096     lda = a_tmp.outerStride(); \
00097   } else a = _lhs; \
00098 \
00099   if ((RhsStorageOrder==ColMajor) && (ConjugateRhs)) { \
00100     Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > rhs(_rhs,k,n,OuterStride<>(rhsStride)); \
00101     b_tmp = rhs.conjugate(); \
00102     b = b_tmp.data(); \
00103     ldb = b_tmp.outerStride(); \
00104   } else b = _rhs; \
00105 \
00106   MKLPREFIX##gemm(&transa, &transb, &m, &n, &k, &alpha_, (const MKLTYPE*)a, &lda, (const MKLTYPE*)b, &ldb, &beta_, (MKLTYPE*)res, &ldc); \
00107 }};
00108 
00109 GEMM_SPECIALIZATION(double,   d,  double,        d)
00110 GEMM_SPECIALIZATION(float,    f,  float,         s)
00111 GEMM_SPECIALIZATION(dcomplex, cd, MKL_Complex16, z)
00112 GEMM_SPECIALIZATION(scomplex, cf, MKL_Complex8,  c)
00113 
00114 } // end namespase internal
00115 
00116 } // end namespace Eigen
00117 
00118 #endif // EIGEN_GENERAL_MATRIX_MATRIX_MKL_H


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Thu Aug 27 2015 11:58:22