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