2
Copyright (c) 2011, Intel Corporation. All rights reserved.
4
Redistribution and use in source and binary forms, with or without modification,
5
are permitted provided that the following conditions are met:
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.
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.
27
********************************************************************************
28
* Content : Eigen bindings to Intel(R) MKL
29
* Self adjoint matrix * matrix product functionality based on ?SYMM/?HEMM.
30
********************************************************************************
33
#ifndef EIGEN_SELFADJOINT_MATRIX_MATRIX_MKL_H
34
#define EIGEN_SELFADJOINT_MATRIX_MATRIX_MKL_H
41
/* Optimized selfadjoint matrix * matrix (?SYMM/?HEMM) product */
43
#define EIGEN_MKL_SYMM_L(EIGTYPE, MKLTYPE, EIGPREFIX, MKLPREFIX) \
44
template <typename Index, \
45
int LhsStorageOrder, bool ConjugateLhs, \
46
int RhsStorageOrder, bool ConjugateRhs> \
47
struct product_selfadjoint_matrix<EIGTYPE,Index,LhsStorageOrder,true,ConjugateLhs,RhsStorageOrder,false,ConjugateRhs,ColMajor> \
50
static EIGEN_DONT_INLINE void run( \
51
Index rows, Index cols, \
52
const EIGTYPE* _lhs, Index lhsStride, \
53
const EIGTYPE* _rhs, Index rhsStride, \
54
EIGTYPE* res, Index resStride, \
57
char side='L', uplo='L'; \
58
MKL_INT m, n, lda, ldb, ldc; \
59
const EIGTYPE *a, *b; \
60
MKLTYPE alpha_, beta_; \
61
MatrixX##EIGPREFIX b_tmp; \
64
/* Set transpose options */ \
69
/* Set alpha_ & beta_ */ \
70
assign_scalar_eig2mkl(alpha_, alpha); \
71
assign_scalar_eig2mkl(beta_, myone); \
73
/* Set lda, ldb, ldc */ \
74
lda = (MKL_INT)lhsStride; \
75
ldb = (MKL_INT)rhsStride; \
76
ldc = (MKL_INT)resStride; \
79
if (LhsStorageOrder==RowMajor) uplo='U'; \
82
if (RhsStorageOrder==RowMajor) { \
83
Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > rhs(_rhs,n,m,OuterStride<>(rhsStride)); \
84
b_tmp = rhs.adjoint(); \
86
ldb = b_tmp.outerStride(); \
89
MKLPREFIX##symm(&side, &uplo, &m, &n, &alpha_, (const MKLTYPE*)a, &lda, (const MKLTYPE*)b, &ldb, &beta_, (MKLTYPE*)res, &ldc); \
95
#define EIGEN_MKL_HEMM_L(EIGTYPE, MKLTYPE, EIGPREFIX, MKLPREFIX) \
96
template <typename Index, \
97
int LhsStorageOrder, bool ConjugateLhs, \
98
int RhsStorageOrder, bool ConjugateRhs> \
99
struct product_selfadjoint_matrix<EIGTYPE,Index,LhsStorageOrder,true,ConjugateLhs,RhsStorageOrder,false,ConjugateRhs,ColMajor> \
101
static EIGEN_DONT_INLINE void run( \
102
Index rows, Index cols, \
103
const EIGTYPE* _lhs, Index lhsStride, \
104
const EIGTYPE* _rhs, Index rhsStride, \
105
EIGTYPE* res, Index resStride, \
108
char side='L', uplo='L'; \
109
MKL_INT m, n, lda, ldb, ldc; \
110
const EIGTYPE *a, *b; \
111
MKLTYPE alpha_, beta_; \
112
MatrixX##EIGPREFIX b_tmp; \
113
Matrix<EIGTYPE, Dynamic, Dynamic, LhsStorageOrder> a_tmp; \
116
/* Set transpose options */ \
121
/* Set alpha_ & beta_ */ \
122
assign_scalar_eig2mkl(alpha_, alpha); \
123
assign_scalar_eig2mkl(beta_, myone); \
125
/* Set lda, ldb, ldc */ \
126
lda = (MKL_INT)lhsStride; \
127
ldb = (MKL_INT)rhsStride; \
128
ldc = (MKL_INT)resStride; \
131
if (((LhsStorageOrder==ColMajor) && ConjugateLhs) || ((LhsStorageOrder==RowMajor) && (!ConjugateLhs))) { \
132
Map<const Matrix<EIGTYPE, Dynamic, Dynamic, LhsStorageOrder>, 0, OuterStride<> > lhs(_lhs,m,m,OuterStride<>(lhsStride)); \
133
a_tmp = lhs.conjugate(); \
135
lda = a_tmp.outerStride(); \
137
if (LhsStorageOrder==RowMajor) uplo='U'; \
139
if (RhsStorageOrder==ColMajor && (!ConjugateRhs)) { \
142
if (RhsStorageOrder==ColMajor && ConjugateRhs) { \
143
Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > rhs(_rhs,m,n,OuterStride<>(rhsStride)); \
144
b_tmp = rhs.conjugate(); \
146
if (ConjugateRhs) { \
147
Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > rhs(_rhs,n,m,OuterStride<>(rhsStride)); \
148
b_tmp = rhs.adjoint(); \
150
Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > rhs(_rhs,n,m,OuterStride<>(rhsStride)); \
151
b_tmp = rhs.transpose(); \
154
ldb = b_tmp.outerStride(); \
157
MKLPREFIX##hemm(&side, &uplo, &m, &n, &alpha_, (const MKLTYPE*)a, &lda, (const MKLTYPE*)b, &ldb, &beta_, (MKLTYPE*)res, &ldc); \
162
EIGEN_MKL_SYMM_L(double, double, d, d)
163
EIGEN_MKL_SYMM_L(float, float, f, s)
164
EIGEN_MKL_HEMM_L(dcomplex, MKL_Complex16, cd, z)
165
EIGEN_MKL_HEMM_L(scomplex, MKL_Complex8, cf, c)
168
/* Optimized matrix * selfadjoint matrix (?SYMM/?HEMM) product */
170
#define EIGEN_MKL_SYMM_R(EIGTYPE, MKLTYPE, EIGPREFIX, MKLPREFIX) \
171
template <typename Index, \
172
int LhsStorageOrder, bool ConjugateLhs, \
173
int RhsStorageOrder, bool ConjugateRhs> \
174
struct product_selfadjoint_matrix<EIGTYPE,Index,LhsStorageOrder,false,ConjugateLhs,RhsStorageOrder,true,ConjugateRhs,ColMajor> \
177
static EIGEN_DONT_INLINE void run( \
178
Index rows, Index cols, \
179
const EIGTYPE* _lhs, Index lhsStride, \
180
const EIGTYPE* _rhs, Index rhsStride, \
181
EIGTYPE* res, Index resStride, \
184
char side='R', uplo='L'; \
185
MKL_INT m, n, lda, ldb, ldc; \
186
const EIGTYPE *a, *b; \
187
MKLTYPE alpha_, beta_; \
188
MatrixX##EIGPREFIX b_tmp; \
195
/* Set alpha_ & beta_ */ \
196
assign_scalar_eig2mkl(alpha_, alpha); \
197
assign_scalar_eig2mkl(beta_, myone); \
199
/* Set lda, ldb, ldc */ \
200
lda = (MKL_INT)rhsStride; \
201
ldb = (MKL_INT)lhsStride; \
202
ldc = (MKL_INT)resStride; \
205
if (RhsStorageOrder==RowMajor) uplo='U'; \
208
if (LhsStorageOrder==RowMajor) { \
209
Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > lhs(_lhs,n,m,OuterStride<>(rhsStride)); \
210
b_tmp = lhs.adjoint(); \
212
ldb = b_tmp.outerStride(); \
215
MKLPREFIX##symm(&side, &uplo, &m, &n, &alpha_, (const MKLTYPE*)a, &lda, (const MKLTYPE*)b, &ldb, &beta_, (MKLTYPE*)res, &ldc); \
221
#define EIGEN_MKL_HEMM_R(EIGTYPE, MKLTYPE, EIGPREFIX, MKLPREFIX) \
222
template <typename Index, \
223
int LhsStorageOrder, bool ConjugateLhs, \
224
int RhsStorageOrder, bool ConjugateRhs> \
225
struct product_selfadjoint_matrix<EIGTYPE,Index,LhsStorageOrder,false,ConjugateLhs,RhsStorageOrder,true,ConjugateRhs,ColMajor> \
227
static EIGEN_DONT_INLINE void run( \
228
Index rows, Index cols, \
229
const EIGTYPE* _lhs, Index lhsStride, \
230
const EIGTYPE* _rhs, Index rhsStride, \
231
EIGTYPE* res, Index resStride, \
234
char side='R', uplo='L'; \
235
MKL_INT m, n, lda, ldb, ldc; \
236
const EIGTYPE *a, *b; \
237
MKLTYPE alpha_, beta_; \
238
MatrixX##EIGPREFIX b_tmp; \
239
Matrix<EIGTYPE, Dynamic, Dynamic, RhsStorageOrder> a_tmp; \
246
/* Set alpha_ & beta_ */ \
247
assign_scalar_eig2mkl(alpha_, alpha); \
248
assign_scalar_eig2mkl(beta_, myone); \
250
/* Set lda, ldb, ldc */ \
251
lda = (MKL_INT)rhsStride; \
252
ldb = (MKL_INT)lhsStride; \
253
ldc = (MKL_INT)resStride; \
256
if (((RhsStorageOrder==ColMajor) && ConjugateRhs) || ((RhsStorageOrder==RowMajor) && (!ConjugateRhs))) { \
257
Map<const Matrix<EIGTYPE, Dynamic, Dynamic, RhsStorageOrder>, 0, OuterStride<> > rhs(_rhs,n,n,OuterStride<>(rhsStride)); \
258
a_tmp = rhs.conjugate(); \
260
lda = a_tmp.outerStride(); \
262
if (RhsStorageOrder==RowMajor) uplo='U'; \
264
if (LhsStorageOrder==ColMajor && (!ConjugateLhs)) { \
267
if (LhsStorageOrder==ColMajor && ConjugateLhs) { \
268
Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > lhs(_lhs,m,n,OuterStride<>(lhsStride)); \
269
b_tmp = lhs.conjugate(); \
271
if (ConjugateLhs) { \
272
Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > lhs(_lhs,n,m,OuterStride<>(lhsStride)); \
273
b_tmp = lhs.adjoint(); \
275
Map<const MatrixX##EIGPREFIX, 0, OuterStride<> > lhs(_lhs,n,m,OuterStride<>(lhsStride)); \
276
b_tmp = lhs.transpose(); \
279
ldb = b_tmp.outerStride(); \
282
MKLPREFIX##hemm(&side, &uplo, &m, &n, &alpha_, (const MKLTYPE*)a, &lda, (const MKLTYPE*)b, &ldb, &beta_, (MKLTYPE*)res, &ldc); \
286
EIGEN_MKL_SYMM_R(double, double, d, d)
287
EIGEN_MKL_SYMM_R(float, float, f, s)
288
EIGEN_MKL_HEMM_R(dcomplex, MKL_Complex16, cd, z)
289
EIGEN_MKL_HEMM_R(scomplex, MKL_Complex8, cf, c)
291
} // end namespace internal
293
} // end namespace Eigen
295
#endif // EIGEN_SELFADJOINT_MATRIX_MATRIX_MKL_H