TriangularSolverMatrix_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  * Triangular matrix * matrix product functionality based on ?TRMM.
30  ********************************************************************************
31 */
32 
33 #ifndef EIGEN_TRIANGULAR_SOLVER_MATRIX_BLAS_H
34 #define EIGEN_TRIANGULAR_SOLVER_MATRIX_BLAS_H
35 
36 // IWYU pragma: private
37 #include "../InternalHeaderCheck.h"
38 
39 namespace Eigen {
40 
41 namespace internal {
42 
43 // implements LeftSide op(triangular)^-1 * general
44 #define EIGEN_BLAS_TRSM_L(EIGTYPE, BLASTYPE, BLASFUNC) \
45  template <typename Index, int Mode, bool Conjugate, int TriStorageOrder> \
46  struct triangular_solve_matrix<EIGTYPE, Index, OnTheLeft, Mode, Conjugate, TriStorageOrder, ColMajor, 1> { \
47  enum { \
48  IsLower = (Mode & Lower) == Lower, \
49  IsUnitDiag = (Mode & UnitDiag) ? 1 : 0, \
50  IsZeroDiag = (Mode & ZeroDiag) ? 1 : 0, \
51  conjA = ((TriStorageOrder == ColMajor) && Conjugate) ? 1 : 0 \
52  }; \
53  static void run(Index size, Index otherSize, const EIGTYPE* _tri, Index triStride, EIGTYPE* _other, \
54  Index otherIncr, Index otherStride, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) { \
55  if (size == 0 || otherSize == 0) return; \
56  EIGEN_ONLY_USED_FOR_DEBUG(otherIncr); \
57  eigen_assert(otherIncr == 1); \
58  BlasIndex m = convert_index<BlasIndex>(size), n = convert_index<BlasIndex>(otherSize), lda, ldb; \
59  char side = 'L', uplo, diag = 'N', transa; \
60  /* Set alpha_ */ \
61  EIGTYPE alpha(1); \
62  ldb = convert_index<BlasIndex>(otherStride); \
63  \
64  const EIGTYPE* a; \
65  /* Set trans */ \
66  transa = (TriStorageOrder == RowMajor) ? ((Conjugate) ? 'C' : 'T') : 'N'; \
67  /* Set uplo */ \
68  uplo = IsLower ? 'L' : 'U'; \
69  if (TriStorageOrder == RowMajor) uplo = (uplo == 'L') ? 'U' : 'L'; \
70  /* Set a, lda */ \
71  typedef Matrix<EIGTYPE, Dynamic, Dynamic, TriStorageOrder> MatrixTri; \
72  Map<const MatrixTri, 0, OuterStride<> > tri(_tri, size, size, OuterStride<>(triStride)); \
73  MatrixTri a_tmp; \
74  \
75  if (conjA) { \
76  a_tmp = tri.conjugate(); \
77  a = a_tmp.data(); \
78  lda = convert_index<BlasIndex>(a_tmp.outerStride()); \
79  } else { \
80  a = _tri; \
81  lda = convert_index<BlasIndex>(triStride); \
82  } \
83  if (IsUnitDiag) diag = 'U'; \
84  /* call ?trsm*/ \
85  BLASFUNC(&side, &uplo, &transa, &diag, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, \
86  &lda, (BLASTYPE*)_other, &ldb); \
87  } \
88  };
89 
90 #ifdef EIGEN_USE_MKL
91 EIGEN_BLAS_TRSM_L(double, double, dtrsm)
92 EIGEN_BLAS_TRSM_L(dcomplex, MKL_Complex16, ztrsm)
93 EIGEN_BLAS_TRSM_L(float, float, strsm)
94 EIGEN_BLAS_TRSM_L(scomplex, MKL_Complex8, ctrsm)
95 #else
96 EIGEN_BLAS_TRSM_L(double, double, dtrsm_)
97 EIGEN_BLAS_TRSM_L(dcomplex, double, ztrsm_)
98 EIGEN_BLAS_TRSM_L(float, float, strsm_)
99 EIGEN_BLAS_TRSM_L(scomplex, float, ctrsm_)
100 #endif
101 
102 // implements RightSide general * op(triangular)^-1
103 #define EIGEN_BLAS_TRSM_R(EIGTYPE, BLASTYPE, BLASFUNC) \
104  template <typename Index, int Mode, bool Conjugate, int TriStorageOrder> \
105  struct triangular_solve_matrix<EIGTYPE, Index, OnTheRight, Mode, Conjugate, TriStorageOrder, ColMajor, 1> { \
106  enum { \
107  IsLower = (Mode & Lower) == Lower, \
108  IsUnitDiag = (Mode & UnitDiag) ? 1 : 0, \
109  IsZeroDiag = (Mode & ZeroDiag) ? 1 : 0, \
110  conjA = ((TriStorageOrder == ColMajor) && Conjugate) ? 1 : 0 \
111  }; \
112  static void run(Index size, Index otherSize, const EIGTYPE* _tri, Index triStride, EIGTYPE* _other, \
113  Index otherIncr, Index otherStride, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) { \
114  if (size == 0 || otherSize == 0) return; \
115  EIGEN_ONLY_USED_FOR_DEBUG(otherIncr); \
116  eigen_assert(otherIncr == 1); \
117  BlasIndex m = convert_index<BlasIndex>(otherSize), n = convert_index<BlasIndex>(size), lda, ldb; \
118  char side = 'R', uplo, diag = 'N', transa; \
119  /* Set alpha_ */ \
120  EIGTYPE alpha(1); \
121  ldb = convert_index<BlasIndex>(otherStride); \
122  \
123  const EIGTYPE* a; \
124  /* Set trans */ \
125  transa = (TriStorageOrder == RowMajor) ? ((Conjugate) ? 'C' : 'T') : 'N'; \
126  /* Set uplo */ \
127  uplo = IsLower ? 'L' : 'U'; \
128  if (TriStorageOrder == RowMajor) uplo = (uplo == 'L') ? 'U' : 'L'; \
129  /* Set a, lda */ \
130  typedef Matrix<EIGTYPE, Dynamic, Dynamic, TriStorageOrder> MatrixTri; \
131  Map<const MatrixTri, 0, OuterStride<> > tri(_tri, size, size, OuterStride<>(triStride)); \
132  MatrixTri a_tmp; \
133  \
134  if (conjA) { \
135  a_tmp = tri.conjugate(); \
136  a = a_tmp.data(); \
137  lda = convert_index<BlasIndex>(a_tmp.outerStride()); \
138  } else { \
139  a = _tri; \
140  lda = convert_index<BlasIndex>(triStride); \
141  } \
142  if (IsUnitDiag) diag = 'U'; \
143  /* call ?trsm*/ \
144  BLASFUNC(&side, &uplo, &transa, &diag, &m, &n, (const BLASTYPE*)&numext::real_ref(alpha), (const BLASTYPE*)a, \
145  &lda, (BLASTYPE*)_other, &ldb); \
146  /*std::cout << "TRMS_L specialization!\n";*/ \
147  } \
148  };
149 
150 #ifdef EIGEN_USE_MKL
151 EIGEN_BLAS_TRSM_R(double, double, dtrsm)
152 EIGEN_BLAS_TRSM_R(dcomplex, MKL_Complex16, ztrsm)
153 EIGEN_BLAS_TRSM_R(float, float, strsm)
154 EIGEN_BLAS_TRSM_R(scomplex, MKL_Complex8, ctrsm)
155 #else
156 EIGEN_BLAS_TRSM_R(double, double, dtrsm_)
157 EIGEN_BLAS_TRSM_R(dcomplex, double, ztrsm_)
158 EIGEN_BLAS_TRSM_R(float, float, strsm_)
159 EIGEN_BLAS_TRSM_R(scomplex, float, ctrsm_)
160 #endif
161 
162 } // end namespace internal
163 
164 } // end namespace Eigen
165 
166 #endif // EIGEN_TRIANGULAR_SOLVER_MATRIX_BLAS_H
#define EIGEN_BLAS_TRSM_R(EIGTYPE, BLASTYPE, BLASFUNC)
Definition: TriangularSolverMatrix_BLAS.h:103
#define EIGEN_BLAS_TRSM_L(EIGTYPE, BLASTYPE, BLASFUNC)
Definition: TriangularSolverMatrix_BLAS.h:44
int BLASFUNC() strsm(char *, char *, char *, char *, int *, int *, float *, float *, int *, float *, int *)
int BLASFUNC() ztrsm(char *, char *, char *, char *, int *, int *, double *, double *, int *, double *, int *)
int BLASFUNC() dtrsm(char *, char *, char *, char *, int *, int *, double *, double *, int *, double *, int *)
int BLASFUNC() ctrsm(char *, char *, char *, char *, int *, int *, float *, float *, int *, float *, int *)
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
std::complex< double > dcomplex
Definition: MKL_support.h:128
std::complex< float > scomplex
Definition: MKL_support.h:129
Definition: Eigen_Colamd.h:49