gemm.hpp
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief matrix-matrix multiplication kernel
5  *
6  * \author O. Krause
7  * \date 2012
8  *
9  *
10  * \par Copyright 1995-2015 Shark Development Team
11  *
12  * <BR><HR>
13  * This file is part of Shark.
14  * <http://image.diku.dk/shark/>
15  *
16  * Shark is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU Lesser General Public License as published
18  * by the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * Shark is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU Lesser General Public License for more details.
25  *
26  * You should have received a copy of the GNU Lesser General Public License
27  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
28  *
29  */
30 
31 #ifndef SHARK_LINALG_BLAS_KERNELS_GEMM_HPP
32 #define SHARK_LINALG_BLAS_KERNELS_GEMM_HPP
33 
34 #include "default/gemm.hpp"
35 
36 #ifdef SHARK_USE_CBLAS
37 #include "cblas/gemm.hpp"
38 #else
39 //if no bindings are included, we have to provide the default has_optimized_gemm otherwise the binding will take care of this
40 namespace shark { namespace blas { namespace bindings{
41 template<class M1, class M2, class M3>
42 struct has_optimized_gemm
43 : public boost::mpl::false_{};
44 }}}
45 #endif
46 
47 namespace shark { namespace blas {namespace kernels{
48 
49 ///\brief Well known GEneral Matrix-Matrix product kernel M+=alpha*E1*E2.
50 ///
51 /// If bindings are included and the matrix combination allow for a specific binding
52 /// to be applied, the binding is called automatically from {binding}/gemm.h
53 /// otherwise default/gemm.h is used which is fully implemented for all dense/sparse combinations.
54 /// if a combination is optimized, bindings::has_optimized_gemm<M,E1,E2>::type evaluates to boost::mpl::true_
55 /// The kernels themselves are implemented in blas::bindings::gemm.
56 template<class M, class E1, class E2>
57 void gemm(
58  matrix_expression<E1> const& e1,
59  matrix_expression<E2> const& e2,
61  typename M::value_type alpha
62 ) {
63  SIZE_CHECK(m().size1() == e1().size1());
64  SIZE_CHECK(m().size2() == e2().size2());
65  SIZE_CHECK(e1().size2() == e2().size1());
66 
68  e1, e2, m,alpha,
69  typename bindings::has_optimized_gemm<M,E1,E2>::type()
70  );
71 }
72 
73 }}}
74 
75 #endif