ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
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-2015, 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 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_MATRIX_TYPE)
51  {
52  switch (mat1.numeric_type)
53  {
54  case FLOAT_TYPE:
56  *mat2.matrix_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha);
57  break;
58  case DOUBLE_TYPE:
60  *mat2.matrix_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
68  throw statement_not_supported_exception("Invalid arguments in scheduler when calling am()");
69 }
70 
72 template<typename ScalarType1, typename ScalarType2>
73 void ambm(lhs_rhs_element & mat1,
74  lhs_rhs_element const & mat2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
75  lhs_rhs_element const & mat3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
76 {
77  assert( mat1.type_family == MATRIX_TYPE_FAMILY
80  && bool("Arguments are not matrix types!"));
81 
82  assert( (mat1.subtype == mat2.subtype)
83  && (mat2.subtype == mat3.subtype)
84  && bool("Matrices do not have the same layout"));
85 
86  assert( (mat1.numeric_type == mat2.numeric_type)
87  && (mat2.numeric_type == mat3.numeric_type)
88  && bool("Matrices do not have the same scalar type"));
89 
90  if (mat1.subtype == DENSE_MATRIX_TYPE)
91  {
92  switch (mat1.numeric_type)
93  {
94  case FLOAT_TYPE:
96  *mat2.matrix_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
97  *mat3.matrix_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta);
98  break;
99  case DOUBLE_TYPE:
101  *mat2.matrix_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
102  *mat3.matrix_double, convert_to_double(beta), len_beta, reciprocal_beta, flip_sign_beta);
103  break;
104  default:
105  throw statement_not_supported_exception("Invalid arguments in scheduler when calling ambm()");
106  }
107  }
108  else
109  throw statement_not_supported_exception("Invalid arguments in scheduler when calling ambm()");
110 }
111 
113 template<typename ScalarType1, typename ScalarType2>
115  lhs_rhs_element const & mat2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
116  lhs_rhs_element const & mat3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
117 {
118  assert( mat1.type_family == MATRIX_TYPE_FAMILY
121  && bool("Arguments are not matrix types!"));
122 
123  assert( (mat1.subtype == mat2.subtype)
124  && (mat2.subtype == mat3.subtype)
125  && bool("Matrices do not have the same layout"));
126 
127  assert( (mat1.numeric_type == mat2.numeric_type)
128  && (mat2.numeric_type == mat3.numeric_type)
129  && bool("Matrices do not have the same scalar type"));
130 
131  if (mat1.subtype == DENSE_MATRIX_TYPE)
132  {
133  switch (mat1.numeric_type)
134  {
135  case FLOAT_TYPE:
137  *mat2.matrix_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
138  *mat3.matrix_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta);
139  break;
140  case DOUBLE_TYPE:
142  *mat2.matrix_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
143  *mat3.matrix_double, convert_to_double(beta), len_beta, reciprocal_beta, flip_sign_beta);
144  break;
145  default:
146  throw statement_not_supported_exception("Invalid arguments in scheduler when calling ambm_m()");
147  }
148  }
149  else
150  throw statement_not_supported_exception("Invalid arguments in scheduler when calling ambm_m()");
151 }
152 
154 inline void assign_trans(lhs_rhs_element const & A,
155  lhs_rhs_element const & B)
156 {
158  && bool("Arguments are not matrix types!"));
159 
160  assert(A.numeric_type == B.numeric_type && bool("Matrices do not have the same scalar type"));
161 
162  if (A.subtype == DENSE_MATRIX_TYPE)
163  {
164  switch (A.numeric_type)
165  {
166  case FLOAT_TYPE:
168  break;
169  case DOUBLE_TYPE:
171  break;
172  default:
173  throw statement_not_supported_exception("Invalid arguments in scheduler when calling assign_trans()");
174  }
175  }
176  else
177  throw statement_not_supported_exception("Invalid arguments in scheduler when calling assign_trans()");
178 }
179 
180 } // namespace detail
181 } // namespace scheduler
182 } // namespace viennacl
183 
184 #endif
185 
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.
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)
void am(matrix_base< NumericT > &mat1, matrix_base< NumericT > const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
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.
double convert_to_double(float d)
statement_node_subtype subtype
Definition: forwards.h:340
void ambm(matrix_base< NumericT > &mat1, matrix_base< NumericT > const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, matrix_base< NumericT > const &mat3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
This file provides the forward declarations for the main types used within ViennaCL.
statement_node_type_family type_family
Definition: forwards.h:339
A class representing the 'data' for the LHS or RHS operand of the respective node.
Definition: forwards.h:337
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.
viennacl::matrix_base< double > * matrix_double
Definition: forwards.h:410
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:34
Definition: blas3.hpp:36
statement_node_numeric_type numeric_type
Definition: forwards.h:341
viennacl::matrix_base< float > * matrix_float
Definition: forwards.h:409
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.
std::size_t vcl_size_t
Definition: forwards.h:75
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
float convert_to_float(float f)
void ambm_m(matrix_base< NumericT > &mat1, matrix_base< NumericT > const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, matrix_base< NumericT > const &mat3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
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:38