ViennaCL - The Vienna Computing Library: viennacl/scheduler/io.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
io.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_SCHEDULER_IO_HPP
2 #define VIENNACL_SCHEDULER_IO_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 <iostream>
27 #include <sstream>
28
29 #include "viennacl/forwards.h"
30 #include "viennacl/scheduler/forwards.h"
31
32
33 namespace viennacl
34 {
35 namespace scheduler
36 {
37 namespace detail
38 {
39 #define VIENNACL_TRANSLATE_OP_TO_STRING(NAME) case NAME: return #NAME;
40
42 inline std::string to_string(viennacl::scheduler::op_element op_elem)
43 {
44 if (op_elem.type_family == OPERATION_UNARY_TYPE_FAMILY)
45 {
46 switch (op_elem.type)
47 {
48 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_ABS_TYPE)
49 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_ACOS_TYPE)
50 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_ASIN_TYPE)
51 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_ATAN_TYPE)
52 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_CEIL_TYPE)
53 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_COS_TYPE)
54 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_COSH_TYPE)
55 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_EXP_TYPE)
56 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_FABS_TYPE)
57 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_FLOOR_TYPE)
58 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_LOG_TYPE)
59 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_LOG10_TYPE)
60 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_SIN_TYPE)
61 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_SINH_TYPE)
62 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_SQRT_TYPE)
63 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_TAN_TYPE)
64 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_TANH_TYPE)
65 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_TRANS_TYPE)
66 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_NORM_1_TYPE)
67 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_NORM_2_TYPE)
68 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_NORM_INF_TYPE)
69
70 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_MINUS_TYPE)
71
72 default: throw statement_not_supported_exception("Cannot convert unary operation to string");
73 }
74 }
75 else if (op_elem.type_family == OPERATION_BINARY_TYPE_FAMILY)
76 {
77 switch (op_elem.type)
78 {
79 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_ASSIGN_TYPE)
80 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_INPLACE_ADD_TYPE)
81 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_INPLACE_SUB_TYPE)
82 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_ADD_TYPE)
83 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_SUB_TYPE)
84 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_MAT_VEC_PROD_TYPE)
85 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_MAT_MAT_PROD_TYPE)
86 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_MULT_TYPE)
87 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_DIV_TYPE)
88 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_ELEMENT_PROD_TYPE)
89 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_ELEMENT_DIV_TYPE)
90 VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_INNER_PROD_TYPE)
91
92 default: throw statement_not_supported_exception("Cannot convert unary operation to string");
93 }
94 }
95 else if (op_elem.type_family == OPERATION_INVALID_TYPE_FAMILY)
96 {
97 if (op_elem.type == OPERATION_INVALID_TYPE)
98 return "OPERATION_INVALID_TYPE";
99 else
100 throw statement_not_supported_exception("Unknown invalid operation type when converting to string");
101 }
102 else
103 throw statement_not_supported_exception("Unknown operation family when converting to string");
104 }
105 #undef VIENNACL_TRANSLATE_OP_TO_STRING
106
107 #define VIENNACL_TRANSLATE_ELEMENT_TO_STRING(NAME, ELEMENT) case NAME: ss << "(" << element.ELEMENT << ")"; return #NAME + ss.str();
108
110 inline std::string to_string(viennacl::scheduler::lhs_rhs_element element)
111 {
112 std::stringstream ss;
113
114 if (element.type_family == COMPOSITE_OPERATION_FAMILY)
115 {
116 ss << "(" << element.node_index << ")";
117 return "COMPOSITE_OPERATION_FAMILY" + ss.str();
118 }
119 else if (element.type_family == SCALAR_TYPE_FAMILY)
120 {
121 if (element.subtype == HOST_SCALAR_TYPE)
122 {
123 ss << ", HOST_SCALAR_TYPE ";
124 switch (element.numeric_type)
125 {
126 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(CHAR_TYPE, host_char)
127 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UCHAR_TYPE, host_uchar)
128 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(SHORT_TYPE, host_short)
129 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(USHORT_TYPE, host_ushort)
130 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(INT_TYPE, host_int)
131 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UINT_TYPE, host_uint)
132 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(LONG_TYPE, host_long)
133 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(ULONG_TYPE, host_ulong)
134 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(FLOAT_TYPE, host_float)
135 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(DOUBLE_TYPE, host_double)
136
137 default: throw statement_not_supported_exception("Cannot convert host scalar type to string");
138 }
139 }
140 else
141 {
142 ss << ", DEVICE_SCALAR_TYPE";
143 switch (element.numeric_type)
144 {
145 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(CHAR_TYPE, scalar_char)
146 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UCHAR_TYPE, scalar_uchar)
147 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(SHORT_TYPE, scalar_short)
148 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(USHORT_TYPE, scalar_ushort)
149 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(INT_TYPE, scalar_int)
150 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UINT_TYPE, scalar_uint)
151 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(LONG_TYPE, scalar_long)
152 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(ULONG_TYPE, scalar_ulong)
153 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(HALF_TYPE, scalar_half)
154 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(FLOAT_TYPE, scalar_float)
155 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(DOUBLE_TYPE, scalar_double)
156 default: throw statement_not_supported_exception("Cannot convert scalar type to string");
157 }
158 }
159 }
160 else if (element.type_family == VECTOR_TYPE_FAMILY)
161 {
162 ss << ", DENSE_VECTOR_TYPE ";
163 switch (element.numeric_type)
164 {
165 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(CHAR_TYPE, vector_char)
166 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UCHAR_TYPE, vector_uchar)
167 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(SHORT_TYPE, vector_short)
168 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(USHORT_TYPE, vector_ushort)
169 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(INT_TYPE, vector_int)
170 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UINT_TYPE, vector_uint)
171 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(LONG_TYPE, vector_long)
172 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(ULONG_TYPE, vector_ulong)
173 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(HALF_TYPE, vector_half)
174 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(FLOAT_TYPE, vector_float)
175 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(DOUBLE_TYPE, vector_double)
176
177 default: throw statement_not_supported_exception("Cannot convert vector type to string");
178 }
179 }
180 else if (element.type_family == MATRIX_TYPE_FAMILY)
181 {
182 if (element.subtype == DENSE_MATRIX_TYPE)
183 {
184 ss << ", DENSE_MATRIX_TYPE ";
185 switch (element.numeric_type)
186 {
187 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(CHAR_TYPE, matrix_char)
188 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UCHAR_TYPE, matrix_uchar)
189 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(SHORT_TYPE, matrix_short)
190 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(USHORT_TYPE, matrix_ushort)
191 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(INT_TYPE, matrix_int)
192 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UINT_TYPE, matrix_uint)
193 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(LONG_TYPE, matrix_long)
194 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(ULONG_TYPE, matrix_ulong)
195 //VIENNACL_TRANSLATE_ELEMENT_TO_STRING(HALF_TYPE, matrix_half)
196 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(FLOAT_TYPE, matrix_float)
197 VIENNACL_TRANSLATE_ELEMENT_TO_STRING(DOUBLE_TYPE, matrix_double)
198
199 default: throw statement_not_supported_exception("Cannot convert dense matrix type to string");
200 }
201 }
202 else
203 throw statement_not_supported_exception("Cannot convert matrix sub-type to string");
204 }
205 else if (element.type_family == INVALID_TYPE_FAMILY)
206 {
207 return "INVALID_TYPE_FAMILY";
208 }
209 else
210 throw statement_not_supported_exception("Unknown operation family when converting to string");
211 }
212
213 #undef VIENNACL_TRANSLATE_ELEMENT_TO_STRING
214
215 } // namespace detail
216
217
219 inline std::ostream & operator<<(std::ostream & os, viennacl::scheduler::statement_node const & s_node)
220 {
221 os << "LHS: " << detail::to_string(s_node.lhs) << ", "
222 << "OP: " << detail::to_string(s_node.op) << ", "
223 << "RHS: " << detail::to_string(s_node.rhs);
224
225 return os;
226 }
227
228 namespace detail
229 {
231 inline void print_node(std::ostream & os, viennacl::scheduler::statement const & s, vcl_size_t node_index, vcl_size_t indent = 0)
232 {
233 typedef viennacl::scheduler::statement::container_type StatementNodeContainer;
234 typedef viennacl::scheduler::statement::value_type StatementNode;
235
236 StatementNodeContainer const & nodes = s.array();
237 StatementNode const & current_node = nodes[node_index];
238
239 for (vcl_size_t i=0; i<indent; ++i)
240 os << " ";
241
242 os << "Node " << node_index << ": " << current_node << std::endl;
243
244 if (current_node.lhs.type_family == COMPOSITE_OPERATION_FAMILY)
245 print_node(os, s, current_node.lhs.node_index, indent+1);
246
247 if (current_node.rhs.type_family == COMPOSITE_OPERATION_FAMILY)
248 print_node(os, s, current_node.rhs.node_index, indent+1);
249 }
250 }
251
258 inline std::ostream & operator<<(std::ostream & os, viennacl::scheduler::statement const & s)
259 {
260 detail::print_node(os, s, s.root());
261 return os;
262 }
263
264 }
265 } //namespace viennacl
266
267 #endif
268
viennacl::scheduler::OPERATION_UNARY_NORM_INF_TYPE
Definition: forwards.h:109
viennacl::scheduler::OPERATION_UNARY_ATAN_TYPE
Definition: forwards.h:91
viennacl::scheduler::INT_TYPE
Definition: forwards.h:294
viennacl::scheduler::OPERATION_BINARY_MAT_VEC_PROD_TYPE
Definition: forwards.h:144
viennacl::scheduler::OPERATION_UNARY_TRANS_TYPE
Definition: forwards.h:106
viennacl::scheduler::UCHAR_TYPE
Definition: forwards.h:291
viennacl::scheduler::OPERATION_UNARY_COS_TYPE
Definition: forwards.h:93
viennacl::scheduler::OPERATION_UNARY_FABS_TYPE
Definition: forwards.h:96
viennacl::scheduler::INVALID_TYPE_FAMILY
Definition: forwards.h:248
viennacl::scheduler::OPERATION_BINARY_ELEMENT_DIV_TYPE
Definition: forwards.h:127
viennacl::scheduler::DOUBLE_TYPE
Definition: forwards.h:300
viennacl::scheduler::OPERATION_INVALID_TYPE
Definition: forwards.h:70
viennacl::scheduler::OPERATION_UNARY_ACOS_TYPE
Definition: forwards.h:89
viennacl::scheduler::OPERATION_UNARY_EXP_TYPE
Definition: forwards.h:95
viennacl::scheduler::lhs_rhs_element::subtype
statement_node_subtype subtype
Definition: forwards.h:340
viennacl::scheduler::MATRIX_TYPE_FAMILY
Definition: forwards.h:260
viennacl::scheduler::OPERATION_UNARY_ASIN_TYPE
Definition: forwards.h:90
viennacl::scheduler::statement_node::op
op_element op
Definition: forwards.h:481
viennacl::scheduler::SCALAR_TYPE_FAMILY
Definition: forwards.h:254
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::OPERATION_BINARY_ASSIGN_TYPE
Definition: forwards.h:115
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::statement::array
container_type const & array() const
Definition: forwards.h:528
VIENNACL_TRANSLATE_OP_TO_STRING
#define VIENNACL_TRANSLATE_OP_TO_STRING(NAME)
Definition: io.hpp:39
viennacl::scheduler::OPERATION_INVALID_TYPE_FAMILY
Definition: forwards.h:55
viennacl::scheduler::HOST_SCALAR_TYPE
Definition: forwards.h:268
viennacl::scheduler::op_element::type_family
operation_node_type_family type_family
Definition: forwards.h:473
viennacl::scheduler::op_element
Struct for holding the type family as well as the type of an operation (could be addition, subtraction, norm, etc.)
Definition: forwards.h:471
viennacl::scheduler::OPERATION_BINARY_ELEMENT_PROD_TYPE
Definition: forwards.h:126
viennacl::scheduler::COMPOSITE_OPERATION_FAMILY
Definition: forwards.h:251
viennacl::scheduler::OPERATION_UNARY_NORM_2_TYPE
Definition: forwards.h:108
viennacl::scheduler::SHORT_TYPE
Definition: forwards.h:292
viennacl::scheduler::statement::container_type
std::vector< value_type > container_type
Definition: forwards.h:507
viennacl::scheduler::LONG_TYPE
Definition: forwards.h:296
viennacl::scheduler::DENSE_MATRIX_TYPE
Definition: forwards.h:274
viennacl::scheduler::detail::to_string
std::string to_string(viennacl::scheduler::op_element op_elem)
Helper routine for converting the operation enums to string.
Definition: io.hpp:42
viennacl::scheduler::OPERATION_UNARY_LOG_TYPE
Definition: forwards.h:98
viennacl::scheduler::OPERATION_BINARY_INNER_PROD_TYPE
Definition: forwards.h:146
viennacl::scheduler::OPERATION_UNARY_SQRT_TYPE
Definition: forwards.h:102
viennacl::scheduler::CHAR_TYPE
Definition: forwards.h:290
viennacl::scheduler::OPERATION_BINARY_INPLACE_ADD_TYPE
Definition: forwards.h:116
viennacl::scheduler::OPERATION_UNARY_SINH_TYPE
Definition: forwards.h:101
VIENNACL_TRANSLATE_ELEMENT_TO_STRING
#define VIENNACL_TRANSLATE_ELEMENT_TO_STRING(NAME, ELEMENT)
Definition: io.hpp:107
viennacl::scheduler::lhs_rhs_element::numeric_type
statement_node_numeric_type numeric_type
Definition: forwards.h:341
viennacl::scheduler::OPERATION_UNARY_SIN_TYPE
Definition: forwards.h:100
viennacl::scheduler::statement_node::rhs
lhs_rhs_element rhs
Definition: forwards.h:482
viennacl::scheduler::OPERATION_UNARY_ABS_TYPE
Definition: forwards.h:88
viennacl::scheduler::statement_node::lhs
lhs_rhs_element lhs
Definition: forwards.h:480
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
viennacl::scheduler::OPERATION_BINARY_TYPE_FAMILY
Definition: forwards.h:59
forwards.h
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
viennacl::scheduler::OPERATION_UNARY_LOG10_TYPE
Definition: forwards.h:99
viennacl::scheduler::OPERATION_UNARY_FLOOR_TYPE
Definition: forwards.h:97
viennacl::scheduler::OPERATION_BINARY_SUB_TYPE
Definition: forwards.h:119
viennacl::scheduler::USHORT_TYPE
Definition: forwards.h:293
viennacl::scheduler::detail::print_node
void print_node(std::ostream &os, viennacl::scheduler::statement const &s, vcl_size_t node_index, vcl_size_t indent=0)
Recursive worker routine for printing a whole statement.
Definition: io.hpp:231
viennacl::scheduler::OPERATION_BINARY_INPLACE_SUB_TYPE
Definition: forwards.h:117
viennacl::scheduler::OPERATION_UNARY_TAN_TYPE
Definition: forwards.h:103
viennacl::scheduler::operator<<
std::ostream & operator<<(std::ostream &os, viennacl::scheduler::statement_node const &s_node)
Print a single statement_node. Non-recursive.
Definition: io.hpp:219
viennacl::scheduler::OPERATION_UNARY_MINUS_TYPE
Definition: forwards.h:73
viennacl::scheduler::OPERATION_UNARY_CEIL_TYPE
Definition: forwards.h:92
viennacl::scheduler::op_element::type
operation_node_type type
Definition: forwards.h:474
viennacl::scheduler::OPERATION_BINARY_DIV_TYPE
Definition: forwards.h:121
viennacl::scheduler::UINT_TYPE
Definition: forwards.h:295
viennacl::scheduler::OPERATION_UNARY_TANH_TYPE
Definition: forwards.h:104
viennacl::scheduler::FLOAT_TYPE
Definition: forwards.h:299
viennacl::scheduler::statement::root
size_type root() const
Definition: forwards.h:530
viennacl::scheduler::statement
The main class for representing a statement such as x = inner_prod(y,z); at runtime.
Definition: forwards.h:502
viennacl::scheduler::OPERATION_BINARY_ADD_TYPE
Definition: forwards.h:118
viennacl::scheduler::lhs_rhs_element::node_index
vcl_size_t node_index
Definition: forwards.h:346
viennacl::scheduler::ULONG_TYPE
Definition: forwards.h:297
viennacl::scheduler::OPERATION_UNARY_COSH_TYPE
Definition: forwards.h:94
viennacl::scheduler::VECTOR_TYPE_FAMILY
Definition: forwards.h:257
viennacl::scheduler::statement_node
Main datastructure for an node in the statement tree.
Definition: forwards.h:478
viennacl::scheduler::OPERATION_BINARY_MAT_MAT_PROD_TYPE
Definition: forwards.h:145
viennacl::scheduler::statement_not_supported_exception
Exception for the case the scheduler is unable to deal with the operation.
Definition: forwards.h:38
viennacl::scheduler::OPERATION_UNARY_TYPE_FAMILY
Definition: forwards.h:58
viennacl::scheduler::OPERATION_UNARY_NORM_1_TYPE
Definition: forwards.h:107
viennacl::scheduler::OPERATION_BINARY_MULT_TYPE
Definition: forwards.h:120