GeneralMatrixMatrixTriangular_BLAS.h
Go to the documentation of this file.
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 BLAS F77
29  * Level 3 BLAS SYRK/HERK implementation.
30  ********************************************************************************
31 */
32 
33 #ifndef EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_BLAS_H
34 #define EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_BLAS_H
35 
36 // IWYU pragma: private
37 #include "../InternalHeaderCheck.h"
38 
39 namespace Eigen {
40 
41 namespace internal {
42 
43 template <typename Index, typename Scalar, int AStorageOrder, bool ConjugateA, int ResStorageOrder, int UpLo>
45  : general_matrix_matrix_triangular_product<Index, Scalar, AStorageOrder, ConjugateA, Scalar, AStorageOrder,
46  ConjugateA, ResStorageOrder, 1, UpLo, BuiltIn> {};
47 
48 // try to go to BLAS specialization
49 #define EIGEN_BLAS_RANKUPDATE_SPECIALIZE(Scalar) \
50  template <typename Index, int LhsStorageOrder, bool ConjugateLhs, int RhsStorageOrder, bool ConjugateRhs, int UpLo> \
51  struct general_matrix_matrix_triangular_product<Index, Scalar, LhsStorageOrder, ConjugateLhs, Scalar, \
52  RhsStorageOrder, ConjugateRhs, ColMajor, 1, UpLo, Specialized> { \
53  static EIGEN_STRONG_INLINE void run(Index size, Index depth, const Scalar* lhs, Index lhsStride, \
54  const Scalar* rhs, Index rhsStride, Scalar* res, Index resIncr, \
55  Index resStride, Scalar alpha, level3_blocking<Scalar, Scalar>& blocking) { \
56  if (lhs == rhs && ((UpLo & (Lower | Upper)) == UpLo)) { \
57  general_matrix_matrix_rankupdate<Index, Scalar, LhsStorageOrder, ConjugateLhs, ColMajor, UpLo>::run( \
58  size, depth, lhs, lhsStride, rhs, rhsStride, res, resStride, alpha, blocking); \
59  } else { \
60  general_matrix_matrix_triangular_product<Index, Scalar, LhsStorageOrder, ConjugateLhs, Scalar, \
61  RhsStorageOrder, ConjugateRhs, ColMajor, 1, UpLo, \
62  BuiltIn>::run(size, depth, lhs, lhsStride, rhs, rhsStride, res, \
63  resIncr, resStride, alpha, blocking); \
64  } \
65  } \
66  };
67 
70 // TODO handle complex cases
71 // EIGEN_BLAS_RANKUPDATE_SPECIALIZE(dcomplex)
72 // EIGEN_BLAS_RANKUPDATE_SPECIALIZE(scomplex)
73 
74 // SYRK for float/double
75 #define EIGEN_BLAS_RANKUPDATE_R(EIGTYPE, BLASTYPE, BLASFUNC) \
76  template <typename Index, int AStorageOrder, bool ConjugateA, int UpLo> \
77  struct general_matrix_matrix_rankupdate<Index, EIGTYPE, AStorageOrder, ConjugateA, ColMajor, UpLo> { \
78  enum { \
79  IsLower = (UpLo & Lower) == Lower, \
80  LowUp = IsLower ? Lower : Upper, \
81  conjA = ((AStorageOrder == ColMajor) && ConjugateA) ? 1 : 0 \
82  }; \
83  static EIGEN_STRONG_INLINE void run(Index size, Index depth, const EIGTYPE* lhs, Index lhsStride, \
84  const EIGTYPE* /*rhs*/, Index /*rhsStride*/, EIGTYPE* res, Index resStride, \
85  EIGTYPE alpha, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) { \
86  /* typedef Matrix<EIGTYPE, Dynamic, Dynamic, RhsStorageOrder> MatrixRhs;*/ \
87  if (size == 0 || depth == 0) return; \
88  BlasIndex lda = convert_index<BlasIndex>(lhsStride), ldc = convert_index<BlasIndex>(resStride), \
89  n = convert_index<BlasIndex>(size), k = convert_index<BlasIndex>(depth); \
90  char uplo = ((IsLower) ? 'L' : 'U'), trans = ((AStorageOrder == RowMajor) ? 'T' : 'N'); \
91  EIGTYPE beta(1); \
92  BLASFUNC(&uplo, &trans, &n, &k, (const BLASTYPE*)&numext::real_ref(alpha), lhs, &lda, \
93  (const BLASTYPE*)&numext::real_ref(beta), res, &ldc); \
94  } \
95  };
96 
97 // HERK for complex data
98 #define EIGEN_BLAS_RANKUPDATE_C(EIGTYPE, BLASTYPE, RTYPE, BLASFUNC) \
99  template <typename Index, int AStorageOrder, bool ConjugateA, int UpLo> \
100  struct general_matrix_matrix_rankupdate<Index, EIGTYPE, AStorageOrder, ConjugateA, ColMajor, UpLo> { \
101  enum { \
102  IsLower = (UpLo & Lower) == Lower, \
103  LowUp = IsLower ? Lower : Upper, \
104  conjA = (((AStorageOrder == ColMajor) && ConjugateA) || ((AStorageOrder == RowMajor) && !ConjugateA)) ? 1 : 0 \
105  }; \
106  static EIGEN_STRONG_INLINE void run(Index size, Index depth, const EIGTYPE* lhs, Index lhsStride, \
107  const EIGTYPE* /*rhs*/, Index /*rhsStride*/, EIGTYPE* res, Index resStride, \
108  EIGTYPE alpha, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) { \
109  typedef Matrix<EIGTYPE, Dynamic, Dynamic, AStorageOrder> MatrixType; \
110  if (size == 0 || depth == 0) return; \
111  BlasIndex lda = convert_index<BlasIndex>(lhsStride), ldc = convert_index<BlasIndex>(resStride), \
112  n = convert_index<BlasIndex>(size), k = convert_index<BlasIndex>(depth); \
113  char uplo = ((IsLower) ? 'L' : 'U'), trans = ((AStorageOrder == RowMajor) ? 'C' : 'N'); \
114  RTYPE alpha_, beta_; \
115  const EIGTYPE* a_ptr; \
116  \
117  alpha_ = alpha.real(); \
118  beta_ = 1.0; \
119  /* Copy with conjugation in some cases*/ \
120  MatrixType a; \
121  if (conjA) { \
122  Map<const MatrixType, 0, OuterStride<> > mapA(lhs, n, k, OuterStride<>(lhsStride)); \
123  a = mapA.conjugate(); \
124  lda = a.outerStride(); \
125  a_ptr = a.data(); \
126  } else \
127  a_ptr = lhs; \
128  BLASFUNC(&uplo, &trans, &n, &k, &alpha_, (BLASTYPE*)a_ptr, &lda, &beta_, (BLASTYPE*)res, &ldc); \
129  } \
130  };
131 
132 #ifdef EIGEN_USE_MKL
133 EIGEN_BLAS_RANKUPDATE_R(double, double, dsyrk)
134 EIGEN_BLAS_RANKUPDATE_R(float, float, ssyrk)
135 #else
136 EIGEN_BLAS_RANKUPDATE_R(double, double, dsyrk_)
137 EIGEN_BLAS_RANKUPDATE_R(float, float, ssyrk_)
138 #endif
139 
140 // TODO handle complex cases
141 // EIGEN_BLAS_RANKUPDATE_C(dcomplex, double, double, zherk_)
142 // EIGEN_BLAS_RANKUPDATE_C(scomplex, float, float, cherk_)
143 
144 } // end namespace internal
145 
146 } // end namespace Eigen
147 
148 #endif // EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_BLAS_H
#define EIGEN_BLAS_RANKUPDATE_R(EIGTYPE, BLASTYPE, BLASFUNC)
Definition: GeneralMatrixMatrixTriangular_BLAS.h:75
#define EIGEN_BLAS_RANKUPDATE_SPECIALIZE(Scalar)
Definition: GeneralMatrixMatrixTriangular_BLAS.h:49
int BLASFUNC() dsyrk(char *, char *, int *, int *, double *, double *, int *, double *, double *, int *)
int BLASFUNC() ssyrk(char *, char *, int *, int *, float *, float *, int *, float *, float *, int *)
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
Definition: Eigen_Colamd.h:49
Definition: GeneralMatrixMatrixTriangular_BLAS.h:46
Definition: GeneralMatrixMatrixTriangular.h:39