From 6a9ca88e7e1bb72de621806b51c5a4fd17310943 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 11 Apr 2016 15:17:14 +0200 Subject: Relax dependency on MKL for EIGEN_USE_BLAS --- .../products/GeneralMatrixMatrixTriangular_MKL.h | 24 +++++----- Eigen/src/Core/products/GeneralMatrixMatrix_MKL.h | 17 +++---- Eigen/src/Core/products/GeneralMatrixVector_MKL.h | 20 ++++----- .../Core/products/SelfadjointMatrixMatrix_MKL.h | 52 +++++++--------------- .../Core/products/SelfadjointMatrixVector_MKL.h | 16 +++---- .../src/Core/products/TriangularMatrixMatrix_MKL.h | 25 ++++------- .../src/Core/products/TriangularMatrixVector_MKL.h | 36 +++++++-------- .../src/Core/products/TriangularSolverMatrix_MKL.h | 28 +++++------- Eigen/src/Core/util/MKL_support.h | 12 ++++- 9 files changed, 98 insertions(+), 132 deletions(-) diff --git a/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_MKL.h b/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_MKL.h index 3deed068e..1cdf48fbf 100644 --- a/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_MKL.h +++ b/Eigen/src/Core/products/GeneralMatrixMatrixTriangular_MKL.h @@ -50,25 +50,26 @@ template { \ static EIGEN_STRONG_INLINE void run(Index size, Index depth,const Scalar* lhs, Index lhsStride, \ - const Scalar* rhs, Index rhsStride, Scalar* res, Index resStride, Scalar alpha) \ + const Scalar* rhs, Index rhsStride, Scalar* res, Index resStride, Scalar alpha, level3_blocking& blocking) \ { \ if (lhs==rhs) { \ general_matrix_matrix_rankupdate \ - ::run(size,depth,lhs,lhsStride,rhs,rhsStride,res,resStride,alpha); \ + ::run(size,depth,lhs,lhsStride,rhs,rhsStride,res,resStride,alpha,blocking); \ } else { \ general_matrix_matrix_triangular_product \ - ::run(size,depth,lhs,lhsStride,rhs,rhsStride,res,resStride,alpha); \ + ::run(size,depth,lhs,lhsStride,rhs,rhsStride,res,resStride,alpha,blocking); \ } \ } \ }; EIGEN_MKL_RANKUPDATE_SPECIALIZE(double) -//EIGEN_MKL_RANKUPDATE_SPECIALIZE(dcomplex) EIGEN_MKL_RANKUPDATE_SPECIALIZE(float) -//EIGEN_MKL_RANKUPDATE_SPECIALIZE(scomplex) +// TODO handle complex cases +// EIGEN_MKL_RANKUPDATE_SPECIALIZE(dcomplex) +// EIGEN_MKL_RANKUPDATE_SPECIALIZE(scomplex) // SYRK for float/double #define EIGEN_MKL_RANKUPDATE_R(EIGTYPE, MKLTYPE, MKLFUNC) \ @@ -80,7 +81,7 @@ struct general_matrix_matrix_rankupdate& /*blocking*/) \ { \ /* typedef Matrix MatrixRhs;*/ \ \ @@ -105,7 +106,7 @@ struct general_matrix_matrix_rankupdate& /*blocking*/) \ { \ typedef Matrix MatrixType; \ \ @@ -132,11 +133,12 @@ struct general_matrix_matrix_rankupdate > map_x(rhs,cols,1,InnerStride<>(incx)); \ @@ -114,14 +112,14 @@ static void run( \ x_ptr=x_tmp.data(); \ incx=1; \ } else x_ptr=rhs; \ - MKLPREFIX##gemv(&trans, &m, &n, &alpha_, (const MKLTYPE*)lhs, &lda, (const MKLTYPE*)x_ptr, &incx, &beta_, (MKLTYPE*)res, &incy); \ + MKLPREFIX##gemv_(&trans, &m, &n, &numext::real_ref(alpha), (const MKLTYPE*)lhs, &lda, (const MKLTYPE*)x_ptr, &incx, &numext::real_ref(beta), (MKLTYPE*)res, &incy); \ }\ }; -EIGEN_MKL_GEMV_SPECIALIZATION(double, double, d) -EIGEN_MKL_GEMV_SPECIALIZATION(float, float, s) -EIGEN_MKL_GEMV_SPECIALIZATION(dcomplex, MKL_Complex16, z) -EIGEN_MKL_GEMV_SPECIALIZATION(scomplex, MKL_Complex8, c) +EIGEN_MKL_GEMV_SPECIALIZATION(double, double, d) +EIGEN_MKL_GEMV_SPECIALIZATION(float, float, s) +EIGEN_MKL_GEMV_SPECIALIZATION(dcomplex, double, z) +EIGEN_MKL_GEMV_SPECIALIZATION(scomplex, float, c) } // end namespase internal diff --git a/Eigen/src/Core/products/SelfadjointMatrixMatrix_MKL.h b/Eigen/src/Core/products/SelfadjointMatrixMatrix_MKL.h index dfa687fef..9c2e811dd 100644 --- a/Eigen/src/Core/products/SelfadjointMatrixMatrix_MKL.h +++ b/Eigen/src/Core/products/SelfadjointMatrixMatrix_MKL.h @@ -52,24 +52,19 @@ struct product_selfadjoint_matrix& /*blocking*/) \ { \ char side='L', uplo='L'; \ MKL_INT m, n, lda, ldb, ldc; \ const EIGTYPE *a, *b; \ - MKLTYPE alpha_, beta_; \ + EIGTYPE beta(1); \ MatrixX##EIGPREFIX b_tmp; \ - EIGTYPE myone(1);\ \ /* Set transpose options */ \ /* Set m, n, k */ \ m = (MKL_INT)rows; \ n = (MKL_INT)cols; \ \ -/* Set alpha_ & beta_ */ \ - assign_scalar_eig2mkl(alpha_, alpha); \ - assign_scalar_eig2mkl(beta_, myone); \ -\ /* Set lda, ldb, ldc */ \ lda = (MKL_INT)lhsStride; \ ldb = (MKL_INT)rhsStride; \ @@ -86,7 +81,7 @@ struct product_selfadjoint_matrix& /*blocking*/) \ { \ char side='L', uplo='L'; \ MKL_INT m, n, lda, ldb, ldc; \ const EIGTYPE *a, *b; \ - MKLTYPE alpha_, beta_; \ + EIGTYPE beta(1); \ MatrixX##EIGPREFIX b_tmp; \ Matrix a_tmp; \ - EIGTYPE myone(1); \ \ /* Set transpose options */ \ /* Set m, n, k */ \ m = (MKL_INT)rows; \ n = (MKL_INT)cols; \ \ -/* Set alpha_ & beta_ */ \ - assign_scalar_eig2mkl(alpha_, alpha); \ - assign_scalar_eig2mkl(beta_, myone); \ -\ /* Set lda, ldb, ldc */ \ lda = (MKL_INT)lhsStride; \ ldb = (MKL_INT)rhsStride; \ @@ -154,15 +144,15 @@ struct product_selfadjoint_matrix& /*blocking*/) \ { \ char side='R', uplo='L'; \ MKL_INT m, n, lda, ldb, ldc; \ const EIGTYPE *a, *b; \ - MKLTYPE alpha_, beta_; \ + EIGTYPE beta(1); \ MatrixX##EIGPREFIX b_tmp; \ - EIGTYPE myone(1);\ \ /* Set m, n, k */ \ m = (MKL_INT)rows; \ n = (MKL_INT)cols; \ \ -/* Set alpha_ & beta_ */ \ - assign_scalar_eig2mkl(alpha_, alpha); \ - assign_scalar_eig2mkl(beta_, myone); \ -\ /* Set lda, ldb, ldc */ \ lda = (MKL_INT)rhsStride; \ ldb = (MKL_INT)lhsStride; \ @@ -212,7 +197,7 @@ struct product_selfadjoint_matrix& /*blocking*/) \ { \ char side='R', uplo='L'; \ MKL_INT m, n, lda, ldb, ldc; \ const EIGTYPE *a, *b; \ - MKLTYPE alpha_, beta_; \ + EIGTYPE beta(1); \ MatrixX##EIGPREFIX b_tmp; \ Matrix a_tmp; \ - EIGTYPE myone(1); \ \ /* Set m, n, k */ \ m = (MKL_INT)rows; \ n = (MKL_INT)cols; \ \ -/* Set alpha_ & beta_ */ \ - assign_scalar_eig2mkl(alpha_, alpha); \ - assign_scalar_eig2mkl(beta_, myone); \ -\ /* Set lda, ldb, ldc */ \ lda = (MKL_INT)rhsStride; \ ldb = (MKL_INT)lhsStride; \ @@ -279,14 +259,14 @@ struct product_selfadjoint_matrix map_x(_rhs,size,1); \ x_tmp=map_x.conjugate(); \ x_ptr=x_tmp.data(); \ } else x_ptr=_rhs; \ - MKLFUNC(&uplo, &n, &alpha_, (const MKLTYPE*)lhs, &lda, (const MKLTYPE*)x_ptr, &incx, &beta_, (MKLTYPE*)res, &incy); \ + MKLFUNC(&uplo, &n, &numext::real_ref(alpha), (const MKLTYPE*)lhs, &lda, (const MKLTYPE*)x_ptr, &incx, &numext::real_ref(beta), (MKLTYPE*)res, &incy); \ }\ }; -EIGEN_MKL_SYMV_SPECIALIZATION(double, double, dsymv) -EIGEN_MKL_SYMV_SPECIALIZATION(float, float, ssymv) -EIGEN_MKL_SYMV_SPECIALIZATION(dcomplex, MKL_Complex16, zhemv) -EIGEN_MKL_SYMV_SPECIALIZATION(scomplex, MKL_Complex8, chemv) +EIGEN_MKL_SYMV_SPECIALIZATION(double, double, dsymv_) +EIGEN_MKL_SYMV_SPECIALIZATION(float, float, ssymv_) +EIGEN_MKL_SYMV_SPECIALIZATION(dcomplex, double, zhemv_) +EIGEN_MKL_SYMV_SPECIALIZATION(scomplex, float, chemv_) } // end namespace internal diff --git a/Eigen/src/Core/products/TriangularMatrixMatrix_MKL.h b/Eigen/src/Core/products/TriangularMatrixMatrix_MKL.h index d9e7cf852..31f6d2007 100644 --- a/Eigen/src/Core/products/TriangularMatrixMatrix_MKL.h +++ b/Eigen/src/Core/products/TriangularMatrixMatrix_MKL.h @@ -109,7 +109,8 @@ struct product_triangular_matrix_matrix_trmm(alpha_, alpha); \ \ /* Set m, n */ \ m = (MKL_INT)diagSize; \ @@ -175,7 +172,7 @@ struct product_triangular_matrix_matrix_trmm > res_tmp(res,rows,cols,OuterStride<>(resStride)); \ @@ -184,9 +181,9 @@ struct product_triangular_matrix_matrix_trmm(alpha_, alpha); \ \ /* Set m, n */ \ m = (MKL_INT)rows; \ @@ -289,7 +282,7 @@ struct product_triangular_matrix_matrix_trmm > res_tmp(res,rows,cols,OuterStride<>(resStride)); \ @@ -298,9 +291,9 @@ struct product_triangular_matrix_matrix_trmm(alpha_, alpha); \ - assign_scalar_eig2mkl(beta_, EIGTYPE(1)); \ + EIGTYPE beta(1); \ \ /* Set m, n */ \ n = (MKL_INT)size; \ @@ -123,10 +121,10 @@ struct triangular_matrix_vector_product_trmv(alpha_, alpha); \ - assign_scalar_eig2mkl(beta_, EIGTYPE(1)); \ + EIGTYPE beta(1); \ \ /* Set m, n */ \ n = (MKL_INT)size; \ @@ -207,10 +203,10 @@ struct triangular_matrix_vector_product_trmv dcomplex; typedef std::complex scomplex; +#if defined(EIGEN_USE_BLAS) && !defined(EIGEN_USE_MKL) +typedef int MKL_INT; +#endif + namespace internal { template @@ -125,6 +129,7 @@ static inline void assign_conj_scalar_eig2mkl(MKLType& mklScalar, const EigenTyp mklScalar=eigenScalar; } +#ifdef EIGEN_USE_MKL template <> inline void assign_scalar_eig2mkl(MKL_Complex16& mklScalar, const dcomplex& eigenScalar) { mklScalar.real=eigenScalar.real(); @@ -148,11 +153,14 @@ inline void assign_conj_scalar_eig2mkl(MKL_Complex8& mklS mklScalar.real=eigenScalar.real(); mklScalar.imag=-eigenScalar.imag(); } +#endif } // end namespace internal } // end namespace Eigen +#if defined(EIGEN_USE_BLAS) && !defined(EIGEN_USE_MKL) +#include "../../misc/blas.h" #endif #endif // EIGEN_MKL_SUPPORT_H -- cgit v1.2.3