syrk.hpp
Go to the documentation of this file.
1 //===========================================================================
2 /*!
3  *
4  *
5  * \brief -
6  *
7  * \author O. Krause
8  * \date 2010
9  *
10  *
11  * \par Copyright 1995-2015 Shark Development Team
12  *
13  * <BR><HR>
14  * This file is part of Shark.
15  * <http://image.diku.dk/shark/>
16  *
17  * Shark is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Lesser General Public License as published
19  * by the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * Shark is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
29  *
30  */
31 //===========================================================================
32 #ifndef REMORA_KERNELS_CBLAS_SYRK_HPP
33 #define REMORA_KERNELS_CBLAS_SYRK_HPP
34 
35 #include "cblas_inc.hpp"
36 #include <type_traits>
37 
38 namespace remora{ namespace bindings {
39 
40 inline void syrk(
41  CBLAS_ORDER const order, CBLAS_UPLO uplo, CBLAS_TRANSPOSE trans,
42  int N, int K,
43  float alpha, float const *A, int lda,
44  float beta, float *C, int ldc
45 ){
46  cblas_ssyrk(
47  order, uplo, trans,
48  N, K,
49  alpha, A, lda,
50  beta, C, ldc
51  );
52 }
53 
54 inline void syrk(
55  CBLAS_ORDER const order, CBLAS_UPLO uplo, CBLAS_TRANSPOSE trans,
56  int N, int K,
57  double alpha, double const *A, int lda,
58  double beta, double *C, int ldc
59 ){
60  cblas_dsyrk(
61  order, uplo, trans,
62  N, K,
63  alpha, A, lda,
64  beta, C, ldc
65  );
66 }
67 
68 
69 // C <- C + alpha * A * A^T
70 template <bool Upper, typename MatA, typename MatC>
71 void syrk(
72  matrix_expression<MatA, cpu_tag> const& A,
73  matrix_expression<MatC, cpu_tag>& C,
74  typename MatC::value_type alpha,
75  std::true_type
76 ) {
77  REMORA_SIZE_CHECK(A().size1() == C().size1());
78  REMORA_SIZE_CHECK(C().size1() == C().size2());
79 
80  CBLAS_ORDER stor_ord = (CBLAS_ORDER) storage_order<typename MatC::orientation >::value;
81  CBLAS_UPLO uplo = Upper?CblasUpper: CblasLower;
82  CBLAS_TRANSPOSE trans = std::is_same<typename MatA::orientation,typename MatC::orientation>::value?CblasNoTrans:CblasTrans;
83  std::size_t n = C().size1();
84  std::size_t k = A().size2();
85 
86 
87  auto storageA = A().raw_storage();
88  auto storageC = C().raw_storage();
89  syrk(stor_ord, uplo, trans,
90  (int)n, (int)k, alpha,
91  storageA.values,
92  storageA.leading_dimension,
93  typename MatC::value_type(1),
94  storageC.values,
95  storageC.leading_dimension
96  );
97 }
98 
99 template<class M1, class M2>
100 struct has_optimized_syrk: std::integral_constant<bool,
101  allowed_cblas_type<typename M1::value_type>::type::value
102  && std::is_same<typename M1::value_type, typename M2::value_type>::value
103  && std::is_base_of<dense_tag, typename M1::storage_type::storage_tag>::value
104  && std::is_base_of<dense_tag, typename M2::storage_type::storage_tag>::value
105 >{};
106 
107 }}
108 
109 #endif