1 /* 2 Copyright (c) 2011, Intel Corporation. All rights reserved. 3 4 Redistribution and use in source and binary forms, with or without modification, 5 are permitted provided that the following conditions are met: 6 7 * Redistributions of source code must retain the above copyright notice, this 8 list of conditions and the following disclaimer. 9 * Redistributions in binary form must reproduce the above copyright notice, 10 this list of conditions and the following disclaimer in the documentation 11 and/or other materials provided with the distribution. 12 * Neither the name of Intel Corporation nor the names of its contributors may 13 be used to endorse or promote products derived from this software without 14 specific prior written permission. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 27 ******************************************************************************** 28 * Content : Eigen bindings to Intel(R) MKL 29 * Selfadjoint matrix-vector product functionality based on ?SYMV/HEMV. 30 ******************************************************************************** 31 */ 32 33 #ifndef EIGEN_SELFADJOINT_MATRIX_VECTOR_MKL_H 34 #define EIGEN_SELFADJOINT_MATRIX_VECTOR_MKL_H 35 36 namespace Eigen { 37 38 namespace internal { 39 40 /********************************************************************** 41 * This file implements selfadjoint matrix-vector multiplication using BLAS 42 **********************************************************************/ 43 44 // symv/hemv specialization 45 46 template<typename Scalar, typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs> 47 struct selfadjoint_matrix_vector_product_symv : 48 selfadjoint_matrix_vector_product<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs,BuiltIn> {}; 49 50 #define EIGEN_MKL_SYMV_SPECIALIZE(Scalar) \ 51 template<typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs> \ 52 struct selfadjoint_matrix_vector_product<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs,Specialized> { \ 53 static void run( \ 54 Index size, const Scalar* lhs, Index lhsStride, \ 55 const Scalar* _rhs, Index rhsIncr, Scalar* res, Scalar alpha) { \ 56 enum {\ 57 IsColMajor = StorageOrder==ColMajor \ 58 }; \ 59 if (IsColMajor == ConjugateLhs) {\ 60 selfadjoint_matrix_vector_product<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs,BuiltIn>::run( \ 61 size, lhs, lhsStride, _rhs, rhsIncr, res, alpha); \ 62 } else {\ 63 selfadjoint_matrix_vector_product_symv<Scalar,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs>::run( \ 64 size, lhs, lhsStride, _rhs, rhsIncr, res, alpha); \ 65 }\ 66 } \ 67 }; \ 68 69 EIGEN_MKL_SYMV_SPECIALIZE(double) 70 EIGEN_MKL_SYMV_SPECIALIZE(float) 71 EIGEN_MKL_SYMV_SPECIALIZE(dcomplex) 72 EIGEN_MKL_SYMV_SPECIALIZE(scomplex) 73 74 #define EIGEN_MKL_SYMV_SPECIALIZATION(EIGTYPE,MKLTYPE,MKLFUNC) \ 75 template<typename Index, int StorageOrder, int UpLo, bool ConjugateLhs, bool ConjugateRhs> \ 76 struct selfadjoint_matrix_vector_product_symv<EIGTYPE,Index,StorageOrder,UpLo,ConjugateLhs,ConjugateRhs> \ 77 { \ 78 typedef Matrix<EIGTYPE,Dynamic,1,ColMajor> SYMVVector;\ 79 \ 80 static void run( \ 81 Index size, const EIGTYPE* lhs, Index lhsStride, \ 82 const EIGTYPE* _rhs, Index rhsIncr, EIGTYPE* res, EIGTYPE alpha) \ 83 { \ 84 enum {\ 85 IsRowMajor = StorageOrder==RowMajor ? 1 : 0, \ 86 IsLower = UpLo == Lower ? 1 : 0 \ 87 }; \ 88 MKL_INT n=size, lda=lhsStride, incx=rhsIncr, incy=1; \ 89 MKLTYPE alpha_, beta_; \ 90 const EIGTYPE *x_ptr, myone(1); \ 91 char uplo=(IsRowMajor) ? (IsLower ? 'U' : 'L') : (IsLower ? 'L' : 'U'); \ 92 assign_scalar_eig2mkl(alpha_, alpha); \ 93 assign_scalar_eig2mkl(beta_, myone); \ 94 SYMVVector x_tmp; \ 95 if (ConjugateRhs) { \ 96 Map<const SYMVVector, 0, InnerStride<> > map_x(_rhs,size,1,InnerStride<>(incx)); \ 97 x_tmp=map_x.conjugate(); \ 98 x_ptr=x_tmp.data(); \ 99 incx=1; \ 100 } else x_ptr=_rhs; \ 101 MKLFUNC(&uplo, &n, &alpha_, (const MKLTYPE*)lhs, &lda, (const MKLTYPE*)x_ptr, &incx, &beta_, (MKLTYPE*)res, &incy); \ 102 }\ 103 }; 104 105 EIGEN_MKL_SYMV_SPECIALIZATION(double, double, dsymv) 106 EIGEN_MKL_SYMV_SPECIALIZATION(float, float, ssymv) 107 EIGEN_MKL_SYMV_SPECIALIZATION(dcomplex, MKL_Complex16, zhemv) 108 EIGEN_MKL_SYMV_SPECIALIZATION(scomplex, MKL_Complex8, chemv) 109 110 } // end namespace internal 111 112 } // end namespace Eigen 113 114 #endif // EIGEN_SELFADJOINT_MATRIX_VECTOR_MKL_H 115