gemv.hpp
Go to the documentation of this file.
1 //===========================================================================
2 /*!
3  *
4  *
5  * \brief -
6  *
7  * \author O. Krause
8  * \date 2017
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_CLBLAST_GEMV_HPP
33 #define REMORA_KERNELS_CLBLAST_GEMV_HPP
34 
35 #include "../../expression_types.hpp"
36 #include "../../detail/traits.hpp"
37 #include <clblast.h>
38 namespace remora{ namespace kernels{
39 
40 // v <- v + alpha * A * x
41 template <typename MatA, typename VecX, typename VecV>
42 void gemv(
43  matrix_expression<MatA, gpu_tag> const& A,
44  vector_expression<VecX, gpu_tag> const& x,
45  vector_expression<VecV, gpu_tag>& v,
46  typename VecV::value_type const& alpha
47 ) {
48  REMORA_SIZE_CHECK(A().size1() == v().size());
49  REMORA_SIZE_CHECK(A().size2() == x().size());
50 
51  static_assert(std::is_same<typename MatA::value_type, typename VecX::value_type>::value, "[gemv] Arguments do not have same element type");
52  static_assert(std::is_same<typename MatA::value_type, typename VecV::value_type>::value, "[gemv] Arguments do not have same element type");
53  static_assert(std::is_same<typename MatA::evaluation_category::tag, dense_tag>::value, "[gemv] A is not dense");
54  static_assert(std::is_same<typename VecX::evaluation_category::tag, dense_tag>::value, "[gemv] x is not dense");
55  static_assert(std::is_base_of<dense_tag, typename VecV::storage_type::storage_tag>::value, "[gemv] v does not have dense storage layout");
56 
57  //pre-evaluate A and x into a temporary if necessary
58  auto const& Aeval = eval_expression(A);
59  auto const& xeval = eval_expression(x);
60 
61 
62  using namespace clblast;
63 
64  //obtain geometry information
65  auto layout = std::is_same<typename MatA::orientation::orientation, row_major>::value? Layout::kRowMajor: Layout::kColMajor;
66  std::size_t m = A().size1();
67  std::size_t n = A().size2();
68 
69  //obtain raw storage
70  auto storageA = Aeval.raw_storage();
71  auto storagex = xeval.raw_storage();
72  auto storagev = v().raw_storage();
73 
74  cl_event* event = nullptr;//todo: store events for out-of-order queues
75  auto code = Gemv(layout, Transpose::kNo,
76  m, n, alpha,
77  storageA.buffer.get(), storageA.offset, storageA.leading_dimension,
78  storagex.buffer.get(), storagex.offset, storagex.stride,
79  typename VecV::value_type(1),
80  storagev.buffer.get(), storagev.offset, storagev.stride,
81  &v().queue().get(), event
82  );
83  assert(code == StatusCode::kSuccess);
84 }
85 
86 }}
87 
88 #endif