ViennaCL - The Vienna Computing Library: viennacl/scheduler/execute_matrix_dispatcher.hpp Source File

ViennaCL - The Vienna Computing Library 1.7.1 Free open-source GPU-accelerated linear algebra and solver library. |

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2016, 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"
29 #include "viennacl/scheduler/forwards.h"
30 #include "viennacl/scheduler/execute_util.hpp"
31 #include "viennacl/linalg/matrix_operations.hpp"
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 {
45 assert( mat1.type_family == MATRIX_TYPE_FAMILY && mat2.type_family == MATRIX_TYPE_FAMILY
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:
55 viennacl::linalg::am(*mat1.matrix_float,
56 *mat2.matrix_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha);
57 break;
58 case DOUBLE_TYPE:
59 viennacl::linalg::am(*mat1.matrix_double,
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
78 && mat2.type_family == MATRIX_TYPE_FAMILY
79 && mat3.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:
95 viennacl::linalg::ambm(*mat1.matrix_float,
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:
100 viennacl::linalg::ambm(*mat1.matrix_double,
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>
114 void ambm_m(lhs_rhs_element & mat1,
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
119 && mat2.type_family == MATRIX_TYPE_FAMILY
120 && mat3.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:
136 viennacl::linalg::ambm_m(*mat1.matrix_float,
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:
141 viennacl::linalg::ambm_m(*mat1.matrix_double,
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 {
157 assert( A.type_family == MATRIX_TYPE_FAMILY && B.type_family == MATRIX_TYPE_FAMILY
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:
167 *A.matrix_float = viennacl::trans(*B.matrix_float);
168 break;
169 case DOUBLE_TYPE:
170 *A.matrix_double = viennacl::trans(*B.matrix_double);
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::trans
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:376
matrix_operations.hpp
Implementations of dense matrix related operations including matrix-vector products.
viennacl::scheduler::detail::assign_trans
void assign_trans(lhs_rhs_element const &A, lhs_rhs_element const &B)
Scheduler unwrapper for A =/+=/-= trans(B)
Definition: execute_matrix_dispatcher.hpp:154
viennacl::scheduler::DOUBLE_TYPE
Definition: forwards.h:300
viennacl::linalg::am
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)
Definition: matrix_operations.hpp:111
viennacl::scheduler::detail::ambm
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:73
viennacl::scheduler::detail::convert_to_double
double convert_to_double(float d)
Definition: execute_util.hpp:89
viennacl::scheduler::lhs_rhs_element::subtype
statement_node_subtype subtype
Definition: forwards.h:340
viennacl::linalg::ambm
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)
Definition: matrix_operations.hpp:139
viennacl::scheduler::MATRIX_TYPE_FAMILY
Definition: forwards.h:260
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::scheduler::lhs_rhs_element::type_family
statement_node_type_family type_family
Definition: forwards.h:339
viennacl::scheduler::lhs_rhs_element
A class representing the 'data' for the LHS or RHS operand of the respective node.
Definition: forwards.h:337
viennacl::scheduler::detail::am
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::scheduler::lhs_rhs_element::matrix_double
viennacl::matrix_base< double > * matrix_double
Definition: forwards.h:410
viennacl::scheduler::DENSE_MATRIX_TYPE
Definition: forwards.h:274
viennacl::scheduler::lhs_rhs_element::numeric_type
statement_node_numeric_type numeric_type
Definition: forwards.h:341
viennacl::scheduler::lhs_rhs_element::matrix_float
viennacl::matrix_base< float > * matrix_float
Definition: forwards.h:409
viennacl::scheduler::detail::ambm_m
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:114
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
forwards.h
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
viennacl::scheduler::detail::convert_to_float
float convert_to_float(float f)
Definition: execute_util.hpp:76
viennacl::scheduler::FLOAT_TYPE
Definition: forwards.h:299
viennacl::linalg::ambm_m
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)
Definition: matrix_operations.hpp:174
execute_util.hpp
Provides various utilities for implementing the execution of statements.
viennacl::scheduler::statement_not_supported_exception
Exception for the case the scheduler is unable to deal with the operation.
Definition: forwards.h:38