ViennaCL - The Vienna Computing Library  1.5.2
execute_scalar_assign.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_SCHEDULER_EXECUTE_SCALAR_ASSIGN_HPP
2 #define VIENNACL_SCHEDULER_EXECUTE_SCALAR_ASSIGN_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 "viennacl/forwards.h"
29 
30 namespace viennacl
31 {
32  namespace scheduler
33  {
35  inline void execute_scalar_assign_composite(statement const & s, statement_node const & root_node)
36  {
37  statement_node const & leaf = s.array()[root_node.rhs.node_index];
38 
39  if (leaf.op.type == OPERATION_BINARY_INNER_PROD_TYPE) // alpha = inner_prod( (x), (y) ) with x, y being either vectors or expressions
40  {
41  assert(root_node.lhs.type_family == SCALAR_TYPE_FAMILY && bool("Inner product requires assignment to scalar type!"));
42 
45 
46  {
47  detail::inner_prod_impl(leaf.lhs, leaf.rhs, root_node.lhs);
48  }
49  else if ( leaf.lhs.type_family == COMPOSITE_OPERATION_FAMILY // temporary for (x)
51  {
52  statement_node new_root_x;
53 
54  detail::new_element(new_root_x.lhs, leaf.rhs);
55 
58 
60  new_root_x.rhs.subtype = INVALID_SUBTYPE;
62  new_root_x.rhs.node_index = leaf.lhs.node_index;
63 
64  // work on subexpression:
65  // TODO: Catch exception, free temporary, then rethrow
66  detail::execute_composite(s, new_root_x);
67 
68  detail::inner_prod_impl(new_root_x.lhs, leaf.rhs, root_node.lhs);
69 
70  detail::delete_element(new_root_x.lhs);
71  }
72  else if ( leaf.lhs.type_family == VECTOR_TYPE_FAMILY
73  && leaf.rhs.type_family == COMPOSITE_OPERATION_FAMILY) // temporary for (y)
74  {
75  statement_node new_root_y;
76 
77  detail::new_element(new_root_y.lhs, leaf.lhs);
78 
81 
83  new_root_y.rhs.subtype = INVALID_SUBTYPE;
85  new_root_y.rhs.node_index = leaf.rhs.node_index;
86 
87  // work on subexpression:
88  // TODO: Catch exception, free temporary, then rethrow
89  detail::execute_composite(s, new_root_y);
90 
91  detail::inner_prod_impl(leaf.lhs, new_root_y.lhs, root_node.lhs);
92 
93  detail::delete_element(new_root_y.lhs);
94  }
95  else if ( leaf.lhs.type_family == COMPOSITE_OPERATION_FAMILY // temporary for (x)
96  && leaf.rhs.type_family == COMPOSITE_OPERATION_FAMILY) // temporary for (y)
97  {
98  // extract size information from vectors:
99  lhs_rhs_element const & temp_node = detail::extract_representative_vector(s, leaf.lhs);
100 
101  // temporary for (x)
102  statement_node new_root_x;
103  detail::new_element(new_root_x.lhs, temp_node);
104 
106  new_root_x.op.type = OPERATION_BINARY_ASSIGN_TYPE;
107 
109  new_root_x.rhs.subtype = INVALID_SUBTYPE;
111  new_root_x.rhs.node_index = leaf.lhs.node_index;
112 
113  // work on subexpression:
114  // TODO: Catch exception, free temporary, then rethrow
115  detail::execute_composite(s, new_root_x);
116 
117  // temporary for (y)
118  statement_node new_root_y;
119  detail::new_element(new_root_y.lhs, temp_node);
120 
122  new_root_y.op.type = OPERATION_BINARY_ASSIGN_TYPE;
123 
125  new_root_y.rhs.subtype = INVALID_SUBTYPE;
127  new_root_y.rhs.node_index = leaf.rhs.node_index;
128 
129  // work on subexpression:
130  // TODO: Catch exception, free temporary, then rethrow
131  detail::execute_composite(s, new_root_y);
132 
133  // compute inner product:
134  detail::inner_prod_impl(new_root_x.lhs, new_root_y.lhs, root_node.lhs);
135 
136  detail::delete_element(new_root_x.lhs);
137  detail::delete_element(new_root_y.lhs);
138  }
139  else
140  throw statement_not_supported_exception("Cannot deal with inner product of the provided arguments");
141  }
142  else if ( leaf.op.type == OPERATION_UNARY_NORM_1_TYPE
145  {
146  assert(root_node.lhs.type_family == SCALAR_TYPE_FAMILY && bool("Inner product requires assignment to scalar type!"));
147 
148  if (leaf.lhs.type_family == VECTOR_TYPE_FAMILY)
149  {
150  detail::norm_impl(leaf.lhs, root_node.lhs, leaf.op.type);
151  }
152  else if (leaf.lhs.type_family == COMPOSITE_OPERATION_FAMILY) //introduce temporary:
153  {
154  lhs_rhs_element const & temp_node = detail::extract_representative_vector(s, leaf.lhs);
155 
156  statement_node new_root_y;
157 
158  detail::new_element(new_root_y.lhs, temp_node);
159 
161  new_root_y.op.type = OPERATION_BINARY_ASSIGN_TYPE;
162 
164  new_root_y.rhs.subtype = INVALID_SUBTYPE;
166  new_root_y.rhs.node_index = leaf.lhs.node_index;
167 
168  // work on subexpression:
169  // TODO: Catch exception, free temporary, then rethrow
170  detail::execute_composite(s, new_root_y);
171 
172  detail::norm_impl(new_root_y.lhs, root_node.lhs, leaf.op.type);
173 
174  detail::delete_element(new_root_y.lhs);
175  }
176  else
177  throw statement_not_supported_exception("Cannot deal with norm_inf of the provided arguments");
178  }
179  else
180  throw statement_not_supported_exception("Unsupported operation for scalar.");
181  }
182 
183 
184  }
185 
186 } //namespace viennacl
187 
188 #endif
189 
statement_node_subtype subtype
Definition: forwards.h:270
void inner_prod_impl(lhs_rhs_element const &x, lhs_rhs_element const &y, lhs_rhs_element const &s)
Dispatcher interface for computing s = inner_prod(x, y)
Definition: execute_vector_dispatcher.hpp:163
Definition: forwards.h:182
Provides wrappers for av(), avbv(), avbv_v(), etc. in viennacl/linalg/vector_operations.hpp such that scheduler logic is not cluttered with numeric type decutions.
vcl_size_t node_index
Definition: forwards.h:276
void new_element(lhs_rhs_element &new_elem, lhs_rhs_element const &old_element)
Definition: execute_util.hpp:102
lhs_rhs_element lhs
Definition: forwards.h:422
void norm_impl(lhs_rhs_element const &x, lhs_rhs_element const &s, operation_node_type op_type)
Dispatcher interface for computing s = norm_1(x)
Definition: execute_vector_dispatcher.hpp:127
void execute_scalar_assign_composite(statement const &s, statement_node const &root_node)
Deals with x = RHS where RHS is a vector expression.
Definition: execute_scalar_assign.hpp:35
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
operation_node_type_family type_family
Definition: forwards.h:415
lhs_rhs_element rhs
Definition: forwards.h:424
void delete_element(lhs_rhs_element &elem)
Definition: execute_util.hpp:179
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:29
Definition: forwards.h:170
statement_node_numeric_type numeric_type
Definition: forwards.h:271
Definition: forwards.h:173
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
container_type const & array() const
Definition: forwards.h:473
void execute_composite(statement const &s, statement_node const &root_node)
Deals with x = RHS where RHS is an expression and x is either a scalar, a vector, or a matrix...
Definition: execute.hpp:41
lhs_rhs_element const & extract_representative_vector(statement const &s, lhs_rhs_element const &element)
Definition: execute_util.hpp:41
statement_node_type_family type_family
Definition: forwards.h:269
The main class for representing a statement such as x = inner_prod(y,z); at runtime.
Definition: forwards.h:447
op_element op
Definition: forwards.h:423
Main datastructure for an node in the statement tree.
Definition: forwards.h:420
Exception for the case the scheduler is unable to deal with the operation.
Definition: forwards.h:36
operation_node_type type
Definition: forwards.h:416