All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
io.hpp
Go to the documentation of this file.
#ifndef VIENNACL_SCHEDULER_IO_HPP
#define VIENNACL_SCHEDULER_IO_HPP
/* =========================================================================
Copyright (c) 2010-2016, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
#include <iostream>
#include <sstream>
#include "viennacl/forwards.h"
#include "viennacl/scheduler/forwards.h"
namespace viennacl
{
namespace scheduler
{
namespace detail
{
#define VIENNACL_TRANSLATE_OP_TO_STRING(NAME) case NAME: return #NAME;
inline std::string to_string(viennacl::scheduler::op_element op_elem)
{
if (op_elem.type_family == OPERATION_UNARY_TYPE_FAMILY)
{
switch (op_elem.type)
{
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_ABS_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_ACOS_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_ASIN_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_ATAN_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_CEIL_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_COS_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_COSH_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_EXP_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_FABS_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_FLOOR_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_LOG_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_LOG10_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_SIN_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_SINH_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_SQRT_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_TAN_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_TANH_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_TRANS_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_NORM_1_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_NORM_2_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_NORM_INF_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_UNARY_MINUS_TYPE)
default: throw statement_not_supported_exception("Cannot convert unary operation to string");
}
}
else if (op_elem.type_family == OPERATION_BINARY_TYPE_FAMILY)
{
switch (op_elem.type)
{
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_ASSIGN_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_INPLACE_ADD_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_INPLACE_SUB_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_ADD_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_SUB_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_MAT_VEC_PROD_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_MAT_MAT_PROD_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_MULT_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_DIV_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_ELEMENT_PROD_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_ELEMENT_DIV_TYPE)
VIENNACL_TRANSLATE_OP_TO_STRING(OPERATION_BINARY_INNER_PROD_TYPE)
default: throw statement_not_supported_exception("Cannot convert unary operation to string");
}
}
else if (op_elem.type_family == OPERATION_INVALID_TYPE_FAMILY)
{
if (op_elem.type == OPERATION_INVALID_TYPE)
return "OPERATION_INVALID_TYPE";
else
throw statement_not_supported_exception("Unknown invalid operation type when converting to string");
}
else
throw statement_not_supported_exception("Unknown operation family when converting to string");
}
#undef VIENNACL_TRANSLATE_OP_TO_STRING
#define VIENNACL_TRANSLATE_ELEMENT_TO_STRING(NAME, ELEMENT) case NAME: ss << "(" << element.ELEMENT << ")"; return #NAME + ss.str();
inline std::string to_string(viennacl::scheduler::lhs_rhs_element element)
{
std::stringstream ss;
if (element.type_family == COMPOSITE_OPERATION_FAMILY)
{
ss << "(" << element.node_index << ")";
return "COMPOSITE_OPERATION_FAMILY" + ss.str();
}
else if (element.type_family == SCALAR_TYPE_FAMILY)
{
if (element.subtype == HOST_SCALAR_TYPE)
{
ss << ", HOST_SCALAR_TYPE ";
switch (element.numeric_type)
{
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(CHAR_TYPE, host_char)
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UCHAR_TYPE, host_uchar)
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(SHORT_TYPE, host_short)
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(USHORT_TYPE, host_ushort)
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(INT_TYPE, host_int)
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UINT_TYPE, host_uint)
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(LONG_TYPE, host_long)
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(ULONG_TYPE, host_ulong)
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(FLOAT_TYPE, host_float)
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(DOUBLE_TYPE, host_double)
default: throw statement_not_supported_exception("Cannot convert host scalar type to string");
}
}
else
{
ss << ", DEVICE_SCALAR_TYPE";
switch (element.numeric_type)
{
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(CHAR_TYPE, scalar_char)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UCHAR_TYPE, scalar_uchar)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(SHORT_TYPE, scalar_short)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(USHORT_TYPE, scalar_ushort)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(INT_TYPE, scalar_int)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UINT_TYPE, scalar_uint)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(LONG_TYPE, scalar_long)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(ULONG_TYPE, scalar_ulong)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(HALF_TYPE, scalar_half)
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(FLOAT_TYPE, scalar_float)
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(DOUBLE_TYPE, scalar_double)
default: throw statement_not_supported_exception("Cannot convert scalar type to string");
}
}
}
else if (element.type_family == VECTOR_TYPE_FAMILY)
{
ss << ", DENSE_VECTOR_TYPE ";
switch (element.numeric_type)
{
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(CHAR_TYPE, vector_char)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UCHAR_TYPE, vector_uchar)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(SHORT_TYPE, vector_short)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(USHORT_TYPE, vector_ushort)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(INT_TYPE, vector_int)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UINT_TYPE, vector_uint)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(LONG_TYPE, vector_long)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(ULONG_TYPE, vector_ulong)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(HALF_TYPE, vector_half)
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(FLOAT_TYPE, vector_float)
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(DOUBLE_TYPE, vector_double)
default: throw statement_not_supported_exception("Cannot convert vector type to string");
}
}
else if (element.type_family == MATRIX_TYPE_FAMILY)
{
if (element.subtype == DENSE_MATRIX_TYPE)
{
ss << ", DENSE_MATRIX_TYPE ";
switch (element.numeric_type)
{
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(CHAR_TYPE, matrix_char)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UCHAR_TYPE, matrix_uchar)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(SHORT_TYPE, matrix_short)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(USHORT_TYPE, matrix_ushort)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(INT_TYPE, matrix_int)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(UINT_TYPE, matrix_uint)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(LONG_TYPE, matrix_long)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(ULONG_TYPE, matrix_ulong)
//VIENNACL_TRANSLATE_ELEMENT_TO_STRING(HALF_TYPE, matrix_half)
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(FLOAT_TYPE, matrix_float)
VIENNACL_TRANSLATE_ELEMENT_TO_STRING(DOUBLE_TYPE, matrix_double)
default: throw statement_not_supported_exception("Cannot convert dense matrix type to string");
}
}
else
throw statement_not_supported_exception("Cannot convert matrix sub-type to string");
}
else if (element.type_family == INVALID_TYPE_FAMILY)
{
return "INVALID_TYPE_FAMILY";
}
else
throw statement_not_supported_exception("Unknown operation family when converting to string");
}
#undef VIENNACL_TRANSLATE_ELEMENT_TO_STRING
} // namespace detail
inline std::ostream & operator<<(std::ostream & os, viennacl::scheduler::statement_node const & s_node)
{
os << "LHS: " << detail::to_string(s_node.lhs) << ", "
<< "OP: " << detail::to_string(s_node.op) << ", "
<< "RHS: " << detail::to_string(s_node.rhs);
return os;
}
namespace detail
{
inline void print_node(std::ostream & os, viennacl::scheduler::statement const & s, vcl_size_t node_index, vcl_size_t indent = 0)
{
typedef viennacl::scheduler::statement::container_type StatementNodeContainer;
typedef viennacl::scheduler::statement::value_type StatementNode;
StatementNodeContainer const & nodes = s.array();
StatementNode const & current_node = nodes[node_index];
for (vcl_size_t i=0; i<indent; ++i)
os << " ";
os << "Node " << node_index << ": " << current_node << std::endl;
if (current_node.lhs.type_family == COMPOSITE_OPERATION_FAMILY)
print_node(os, s, current_node.lhs.node_index, indent+1);
if (current_node.rhs.type_family == COMPOSITE_OPERATION_FAMILY)
print_node(os, s, current_node.rhs.node_index, indent+1);
}
}
inline std::ostream & operator<<(std::ostream & os, viennacl::scheduler::statement const & s)
{
detail::print_node(os, s, s.root());
return os;
}
}
} //namespace viennacl
#endif
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