ViennaCL - The Vienna Computing Library  1.5.2
execute_matrix_dispatcher.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_SCHEDULER_EXECUTE_MATRIX_DISPATCHER_HPP
2 #define VIENNACL_SCHEDULER_EXECUTE_MATRIX_DISPATCHER_HPP
3 
4 /* =========================================================================
5  Copyright (c) 2010-2014, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8  Portions of this software are copyright by UChicago Argonne, LLC.
9 
10  -----------------
11  ViennaCL - The Vienna Computing Library
12  -----------------
13 
14  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15 
16  (A list of authors and contributors can be found in the PDF manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20 
21 
26 #include <assert.h>
27 
28 #include "viennacl/forwards.h"
32 
33 namespace viennacl
34 {
35  namespace scheduler
36  {
37  namespace detail
38  {
39 
41  template <typename ScalarType1>
42  void am(lhs_rhs_element & mat1,
43  lhs_rhs_element const & mat2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
44  {
46  && bool("Arguments are not matrix types!"));
47 
48  assert(mat1.numeric_type == mat2.numeric_type && bool("Matrices do not have the same scalar type"));
49 
50  if (mat1.subtype == DENSE_ROW_MATRIX_TYPE)
51  {
52  switch (mat1.numeric_type)
53  {
54  case FLOAT_TYPE:
56  *mat2.matrix_row_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha);
57  break;
58  case DOUBLE_TYPE:
60  *mat2.matrix_row_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha);
61  break;
62 
63  default:
64  throw statement_not_supported_exception("Invalid arguments in scheduler when calling am()");
65  }
66  }
67  else if (mat1.subtype == DENSE_COL_MATRIX_TYPE)
68  {
69  switch (mat1.numeric_type)
70  {
71  case FLOAT_TYPE:
73  *mat2.matrix_col_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha);
74  break;
75  case DOUBLE_TYPE:
77  *mat2.matrix_col_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha);
78  break;
79 
80  default:
81  throw statement_not_supported_exception("Invalid arguments in scheduler when calling am()");
82  }
83  }
84  else
85  {
86  throw statement_not_supported_exception("Invalid arguments in scheduler when calling am()");
87  }
88  }
89 
91  template <typename ScalarType1, typename ScalarType2>
92  void ambm(lhs_rhs_element & mat1,
93  lhs_rhs_element const & mat2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
94  lhs_rhs_element const & mat3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
95  {
96  assert( mat1.type_family == MATRIX_TYPE_FAMILY
99  && bool("Arguments are not matrix types!"));
100 
101  assert( (mat1.subtype == mat2.subtype)
102  && (mat2.subtype == mat3.subtype)
103  && bool("Matrices do not have the same layout"));
104 
105  assert( (mat1.numeric_type == mat2.numeric_type)
106  && (mat2.numeric_type == mat3.numeric_type)
107  && bool("Matrices do not have the same scalar type"));
108 
109  if (mat1.subtype == DENSE_ROW_MATRIX_TYPE)
110  {
111  switch (mat1.numeric_type)
112  {
113  case FLOAT_TYPE:
115  *mat2.matrix_row_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
116  *mat3.matrix_row_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta);
117  break;
118  case DOUBLE_TYPE:
120  *mat2.matrix_row_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
121  *mat3.matrix_row_double, convert_to_double(beta), len_beta, reciprocal_beta, flip_sign_beta);
122  break;
123  default:
124  throw statement_not_supported_exception("Invalid arguments in scheduler when calling ambm()");
125  }
126  }
127  else if (mat1.subtype == DENSE_COL_MATRIX_TYPE)
128  {
129  switch (mat1.numeric_type)
130  {
131  case FLOAT_TYPE:
133  *mat2.matrix_col_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
134  *mat3.matrix_col_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta);
135  break;
136  case DOUBLE_TYPE:
138  *mat2.matrix_col_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
139  *mat3.matrix_col_double, convert_to_double(beta), len_beta, reciprocal_beta, flip_sign_beta);
140  break;
141  default:
142  throw statement_not_supported_exception("Invalid arguments in scheduler when calling ambm()");
143  }
144  }
145  }
146 
148  template <typename ScalarType1, typename ScalarType2>
149  void ambm_m(lhs_rhs_element & mat1,
150  lhs_rhs_element const & mat2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
151  lhs_rhs_element const & mat3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
152  {
153  assert( mat1.type_family == MATRIX_TYPE_FAMILY
156  && bool("Arguments are not matrix types!"));
157 
158  assert( (mat1.subtype == mat2.subtype)
159  && (mat2.subtype == mat3.subtype)
160  && bool("Matrices do not have the same layout"));
161 
162  assert( (mat1.numeric_type == mat2.numeric_type)
163  && (mat2.numeric_type == mat3.numeric_type)
164  && bool("Matrices do not have the same scalar type"));
165 
166  if (mat1.subtype == DENSE_ROW_MATRIX_TYPE)
167  {
168  switch (mat1.numeric_type)
169  {
170  case FLOAT_TYPE:
172  *mat2.matrix_row_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
173  *mat3.matrix_row_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta);
174  break;
175  case DOUBLE_TYPE:
177  *mat2.matrix_row_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
178  *mat3.matrix_row_double, convert_to_double(beta), len_beta, reciprocal_beta, flip_sign_beta);
179  break;
180  default:
181  throw statement_not_supported_exception("Invalid arguments in scheduler when calling ambm_m()");
182  }
183  }
184  else if (mat1.subtype == DENSE_COL_MATRIX_TYPE)
185  {
186  switch (mat1.numeric_type)
187  {
188  case FLOAT_TYPE:
190  *mat2.matrix_col_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
191  *mat3.matrix_col_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta);
192  break;
193  case DOUBLE_TYPE:
195  *mat2.matrix_col_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
196  *mat3.matrix_col_double, convert_to_double(beta), len_beta, reciprocal_beta, flip_sign_beta);
197  break;
198  default:
199  throw statement_not_supported_exception("Invalid arguments in scheduler when calling ambm_m()");
200  }
201  }
202  }
203 
205  inline void assign_trans(lhs_rhs_element const & A,
206  lhs_rhs_element const & B)
207  {
209  && bool("Arguments are not matrix types!"));
210 
211  assert(A.numeric_type == B.numeric_type && bool("Matrices do not have the same scalar type"));
212 
214  {
215  switch (A.numeric_type)
216  {
217  case FLOAT_TYPE:
219  break;
220  case DOUBLE_TYPE:
222  break;
223 
224  default:
225  throw statement_not_supported_exception("Invalid arguments in scheduler when calling assign_trans()");
226  }
227  }
228  else if (A.subtype == DENSE_COL_MATRIX_TYPE)
229  {
230  switch (A.numeric_type)
231  {
232  case FLOAT_TYPE:
234  break;
235  case DOUBLE_TYPE:
237  break;
238 
239  default:
240  throw statement_not_supported_exception("Invalid arguments in scheduler when calling assign_trans()");
241  }
242  }
243  else
244  {
245  throw statement_not_supported_exception("Invalid arguments in scheduler when calling assign_trans()");
246  }
247  }
248 
249  } // namespace detail
250  } // namespace scheduler
251 } // namespace viennacl
252 
253 #endif
254 
statement_node_subtype subtype
Definition: forwards.h:270
viennacl::matrix_base< float > * matrix_row_float
Definition: forwards.h:339
void ambm_m(matrix_base< NumericT, F > &mat1, matrix_base< NumericT, F > const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, matrix_base< NumericT, F > const &mat3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: matrix_operations.hpp:118
std::size_t vcl_size_t
Definition: forwards.h:58
viennacl::enable_if< viennacl::is_any_sparse_matrix< M1 >::value, matrix_expression< const M1, const M1, op_trans > >::type trans(const M1 &mat)
Returns an expression template class representing a transposed matrix.
Definition: sparse_matrix_operations.hpp:330
Implementations of dense matrix related operations including matrix-vector products.
void assign_trans(lhs_rhs_element const &A, lhs_rhs_element const &B)
Scheduler unwrapper for A = trans(B)
Definition: execute_matrix_dispatcher.hpp:205
Definition: forwards.h:176
void am(matrix_base< NumericT, F > &mat1, matrix_base< NumericT, F > const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: matrix_operations.hpp:55
void ambm(matrix_base< NumericT, F > &mat1, matrix_base< NumericT, F > const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, matrix_base< NumericT, F > const &mat3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: matrix_operations.hpp:83
Definition: forwards.h:217
void ambm(lhs_rhs_element &mat1, lhs_rhs_element const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, lhs_rhs_element const &mat3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Wrapper for viennacl::linalg::avbv(), taking care of the argument unwrapping.
Definition: execute_matrix_dispatcher.hpp:92
double convert_to_double(float d)
Definition: execute_util.hpp:88
This file provides the forward declarations for the main types used within ViennaCL.
A class representing the 'data' for the LHS or RHS operand of the respective node.
Definition: forwards.h:267
void am(lhs_rhs_element &mat1, lhs_rhs_element const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Wrapper for viennacl::linalg::av(), taking care of the argument unwrapping.
Definition: execute_matrix_dispatcher.hpp:42
viennacl::matrix_base< float, viennacl::column_major > * matrix_col_float
Definition: forwards.h:351
viennacl::matrix_base< double, viennacl::column_major > * matrix_col_double
Definition: forwards.h:352
statement_node_numeric_type numeric_type
Definition: forwards.h:271
void ambm_m(lhs_rhs_element &mat1, lhs_rhs_element const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, lhs_rhs_element const &mat3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Wrapper for viennacl::linalg::avbv_v(), taking care of the argument unwrapping.
Definition: execute_matrix_dispatcher.hpp:149
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
float convert_to_float(float f)
Definition: execute_util.hpp:75
viennacl::matrix_base< double > * matrix_row_double
Definition: forwards.h:340
statement_node_type_family type_family
Definition: forwards.h:269
Definition: forwards.h:216
Provides various utilities for implementing the execution of statements.
Exception for the case the scheduler is unable to deal with the operation.
Definition: forwards.h:36