gemv.hpp
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief matrix-vector 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 #ifndef REMORA_KERNELS_GEMV_HPP
31 #define REMORA_KERNELS_GEMV_HPP
32 
33 #include "default/gemv.hpp"
34 
35 #ifdef REMORA_USE_CBLAS
36 #include "cblas/gemv.hpp"
37 #else
38 // if no bindings are included, we have to provide the default has_optimized_gemv
39 // otherwise the binding will take care of this
40 namespace remora{ namespace bindings{
41 template<class M1, class M2, class M3>
42 struct has_optimized_gemv
43 : public std::false_type{};
44 }}
45 #endif
46 
47 #include <cassert>
48 
49 namespace remora{namespace kernels{
50 
51 ///\brief Well known GEneral Matrix-Vector product kernel M+=alpha*E1*e2.
52 ///
53 /// If bindings are included and the matrix/vector combination allows for a specific binding
54 /// to be applied, the binding is called automatically from {binding}/gemv.h
55 /// otherwise default/gemv.h is used which is fully implemented for all dense/sparse combinations.
56 /// if a combination is optimized, bindings::has_optimized_gemv<M,E1,E2>::type evaluates to std::true_type
57 /// The kernels themselves are implemented in bindings::gemv.
58 template<class M, class E1, class E2>
59 void gemv(
60  matrix_expression<E1, cpu_tag> const& e1,
61  vector_expression<E2, cpu_tag> const& e2,
62  vector_expression<M, cpu_tag>& m,
63  typename M::value_type alpha
64 ) {
65  assert(m().size() == e1().size1());
66  assert(e1().size2() == e2().size());
67 
68  bindings::gemv(
69  e1, e2, m,alpha,
70  typename bindings::has_optimized_gemv<M,E1,E2>::type()
71  );
72 }
73 
74 }}
75 
76 #ifdef REMORA_USE_CLBLAST
77 #include "clBlast/gemv.hpp"
78 #elif REMORA_USE_GPU
79 #include "gpu/gemv.hpp"
80 #endif
81 
82 #endif