Eigen  5.0.1
 
Loading...
Searching...
No Matches
GeneralMatrixMatrixTriangular_BLAS.h
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// SPDX-License-Identifier: BSD-3-Clause
33
34#ifndef EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_BLAS_H
35#define EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_BLAS_H
36
37// IWYU pragma: private
38#include "../InternalHeaderCheck.h"
39
40namespace Eigen {
41
42namespace internal {
43
44template <typename Index, typename Scalar, int AStorageOrder, bool ConjugateA, int ResStorageOrder, int UpLo>
45struct general_matrix_matrix_rankupdate
46 : general_matrix_matrix_triangular_product<Index, Scalar, AStorageOrder, ConjugateA, Scalar, AStorageOrder,
47 ConjugateA, ResStorageOrder, 1, UpLo, BuiltIn> {};
48
49// try to go to BLAS specialization
50#define EIGEN_BLAS_RANKUPDATE_SPECIALIZE(Scalar) \
51 template <typename Index, int LhsStorageOrder, bool ConjugateLhs, int RhsStorageOrder, bool ConjugateRhs, int UpLo> \
52 struct general_matrix_matrix_triangular_product<Index, Scalar, LhsStorageOrder, ConjugateLhs, Scalar, \
53 RhsStorageOrder, ConjugateRhs, ColMajor, 1, UpLo, Specialized> { \
54 static EIGEN_STRONG_INLINE void run(Index size, Index depth, const Scalar* lhs, Index lhsStride, \
55 const Scalar* rhs, Index rhsStride, Scalar* res, Index resIncr, \
56 Index resStride, Scalar alpha, level3_blocking<Scalar, Scalar>& blocking) { \
57 EIGEN_IF_CONSTEXPR ((UpLo & (Lower | Upper)) == UpLo) { \
58 if (lhs == rhs) { \
59 general_matrix_matrix_rankupdate<Index, Scalar, LhsStorageOrder, ConjugateLhs, ColMajor, UpLo>::run( \
60 size, depth, lhs, lhsStride, rhs, rhsStride, res, resStride, alpha, blocking); \
61 return; \
62 } \
63 } \
64 general_matrix_matrix_triangular_product<Index, Scalar, LhsStorageOrder, ConjugateLhs, Scalar, RhsStorageOrder, \
65 ConjugateRhs, ColMajor, 1, UpLo, BuiltIn>::run(size, depth, lhs, \
66 lhsStride, rhs, \
67 rhsStride, res, resIncr, \
68 resStride, alpha, \
69 blocking); \
70 } \
71 };
72
73EIGEN_BLAS_RANKUPDATE_SPECIALIZE(double)
74EIGEN_BLAS_RANKUPDATE_SPECIALIZE(float)
75// TODO: handle complex cases
76// EIGEN_BLAS_RANKUPDATE_SPECIALIZE(dcomplex)
77// EIGEN_BLAS_RANKUPDATE_SPECIALIZE(scomplex)
78
79// SYRK for float/double
80#define EIGEN_BLAS_RANKUPDATE_R(EIGTYPE, BLASTYPE, BLASFUNC) \
81 template <typename Index, int AStorageOrder, bool ConjugateA, int UpLo> \
82 struct general_matrix_matrix_rankupdate<Index, EIGTYPE, AStorageOrder, ConjugateA, ColMajor, UpLo> { \
83 enum { \
84 IsLower = (UpLo & Lower) == Lower, \
85 LowUp = IsLower ? Lower : Upper, \
86 conjA = ((AStorageOrder == ColMajor) && ConjugateA) ? 1 : 0 \
87 }; \
88 static EIGEN_STRONG_INLINE void run(Index size, Index depth, const EIGTYPE* lhs, Index lhsStride, \
89 const EIGTYPE* /*rhs*/, Index /*rhsStride*/, EIGTYPE* res, Index resStride, \
90 EIGTYPE alpha, level3_blocking<EIGTYPE, EIGTYPE>& /*blocking*/) { \
91 if (size == 0 || depth == 0) return; \
92 BlasIndex lda = convert_index<BlasIndex>(lhsStride), ldc = convert_index<BlasIndex>(resStride), \
93 n = convert_index<BlasIndex>(size), k = convert_index<BlasIndex>(depth); \
94 char uplo = ((IsLower) ? 'L' : 'U'), trans = ((AStorageOrder == RowMajor) ? 'T' : 'N'); \
95 EIGTYPE beta(1); \
96 BLASFUNC(&uplo, &trans, &n, &k, (const BLASTYPE*)&numext::real_ref(alpha), lhs, &lda, \
97 (const BLASTYPE*)&numext::real_ref(beta), res, &ldc); \
98 } \
99 };
100
101#ifdef EIGEN_USE_MKL
102EIGEN_BLAS_RANKUPDATE_R(double, double, dsyrk)
103EIGEN_BLAS_RANKUPDATE_R(float, float, ssyrk)
104#else
105EIGEN_BLAS_RANKUPDATE_R(double, double, EIGEN_BLAS_SYM(dsyrk))
106EIGEN_BLAS_RANKUPDATE_R(float, float, EIGEN_BLAS_SYM(ssyrk))
107#endif
108
109#undef EIGEN_BLAS_RANKUPDATE_SPECIALIZE
110#undef EIGEN_BLAS_RANKUPDATE_R
111} // end namespace internal
112
113} // end namespace Eigen
114
115#endif // EIGEN_GENERAL_MATRIX_MATRIX_TRIANGULAR_BLAS_H