ViennaCL - The Vienna Computing Library  1.5.2
forwards.h
Go to the documentation of this file.
1 #ifndef VIENNACL_SCHEDULER_STATEMENT_HPP
2 #define VIENNACL_SCHEDULER_STATEMENT_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"
27 
28 #include <vector>
29 
30 namespace viennacl
31 {
32  namespace scheduler
33  {
34 
36  class statement_not_supported_exception : public std::exception
37  {
38  public:
40  statement_not_supported_exception(std::string message) : message_("ViennaCL: Internal error: The scheduler encountered a problem with the operation provided: " + message) {}
41 
42  virtual const char* what() const throw() { return message_.c_str(); }
43 
45  private:
46  std::string message_;
47  };
48 
49 
52  {
54 
55  // unary or binary expression
58  };
59 
62  {
64 
65  // unary expression
87 
88  // binary expression
97  OPERATION_BINARY_MULT_TYPE, // scalar times vector/matrix
98  OPERATION_BINARY_DIV_TYPE, // vector/matrix divided by scalar
102  };
103 
104 
105 
106  namespace result_of
107  {
109  template <typename T>
111  {
112  typedef typename T::ERROR_UNKNOWN_OP_TYPE error_type;
113  };
114 
117  // unary operations
118  template <> struct op_type_info<op_element_unary<op_abs> > { enum { id = OPERATION_UNARY_ABS_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
119  template <> struct op_type_info<op_element_unary<op_acos> > { enum { id = OPERATION_UNARY_ACOS_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
120  template <> struct op_type_info<op_element_unary<op_asin> > { enum { id = OPERATION_UNARY_ASIN_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
121  template <> struct op_type_info<op_element_unary<op_atan> > { enum { id = OPERATION_UNARY_ATAN_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
122  template <> struct op_type_info<op_element_unary<op_ceil> > { enum { id = OPERATION_UNARY_CEIL_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
123  template <> struct op_type_info<op_element_unary<op_cos> > { enum { id = OPERATION_UNARY_COS_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
124  template <> struct op_type_info<op_element_unary<op_cosh> > { enum { id = OPERATION_UNARY_COSH_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
125  template <> struct op_type_info<op_element_unary<op_exp> > { enum { id = OPERATION_UNARY_EXP_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
126  template <> struct op_type_info<op_element_unary<op_fabs> > { enum { id = OPERATION_UNARY_FABS_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
127  template <> struct op_type_info<op_element_unary<op_floor> > { enum { id = OPERATION_UNARY_FLOOR_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
128  template <> struct op_type_info<op_element_unary<op_log> > { enum { id = OPERATION_UNARY_LOG_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
129  template <> struct op_type_info<op_element_unary<op_log10> > { enum { id = OPERATION_UNARY_LOG10_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
130  template <> struct op_type_info<op_element_unary<op_sin> > { enum { id = OPERATION_UNARY_SIN_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
131  template <> struct op_type_info<op_element_unary<op_sinh> > { enum { id = OPERATION_UNARY_SINH_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
132  template <> struct op_type_info<op_element_unary<op_sqrt> > { enum { id = OPERATION_UNARY_SQRT_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
133  template <> struct op_type_info<op_element_unary<op_tan> > { enum { id = OPERATION_UNARY_TAN_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
134  template <> struct op_type_info<op_element_unary<op_tanh> > { enum { id = OPERATION_UNARY_TANH_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
135  template <> struct op_type_info<op_norm_1 > { enum { id = OPERATION_UNARY_NORM_1_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
136  template <> struct op_type_info<op_norm_2 > { enum { id = OPERATION_UNARY_NORM_2_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
137  template <> struct op_type_info<op_norm_inf > { enum { id = OPERATION_UNARY_NORM_INF_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
138  template <> struct op_type_info<op_trans > { enum { id = OPERATION_UNARY_TRANS_TYPE, family = OPERATION_UNARY_TYPE_FAMILY }; };
139 
140  // binary operations
141  template <> struct op_type_info<op_assign> { enum { id = OPERATION_BINARY_ASSIGN_TYPE, family = OPERATION_BINARY_TYPE_FAMILY }; };
142  template <> struct op_type_info<op_inplace_add> { enum { id = OPERATION_BINARY_INPLACE_ADD_TYPE, family = OPERATION_BINARY_TYPE_FAMILY }; };
143  template <> struct op_type_info<op_inplace_sub> { enum { id = OPERATION_BINARY_INPLACE_SUB_TYPE, family = OPERATION_BINARY_TYPE_FAMILY }; };
144  template <> struct op_type_info<op_add> { enum { id = OPERATION_BINARY_ADD_TYPE, family = OPERATION_BINARY_TYPE_FAMILY }; };
145  template <> struct op_type_info<op_sub> { enum { id = OPERATION_BINARY_SUB_TYPE, family = OPERATION_BINARY_TYPE_FAMILY }; };
146  template <> struct op_type_info<op_prod> { enum { id = OPERATION_BINARY_MAT_VEC_PROD_TYPE, family = OPERATION_BINARY_TYPE_FAMILY }; };
147  template <> struct op_type_info<op_mat_mat_prod> { enum { id = OPERATION_BINARY_MAT_MAT_PROD_TYPE, family = OPERATION_BINARY_TYPE_FAMILY }; };
148  template <> struct op_type_info<op_mult> { enum { id = OPERATION_BINARY_MULT_TYPE, family = OPERATION_BINARY_TYPE_FAMILY }; };
149  template <> struct op_type_info<op_div> { enum { id = OPERATION_BINARY_DIV_TYPE, family = OPERATION_BINARY_TYPE_FAMILY }; };
150  template <> struct op_type_info<op_element_binary<op_prod> > { enum { id = OPERATION_BINARY_ELEMENT_PROD_TYPE, family = OPERATION_BINARY_TYPE_FAMILY }; };
151  template <> struct op_type_info<op_element_binary<op_div> > { enum { id = OPERATION_BINARY_ELEMENT_DIV_TYPE, family = OPERATION_BINARY_TYPE_FAMILY }; };
152  template <> struct op_type_info<op_inner_prod> { enum { id = OPERATION_BINARY_INNER_PROD_TYPE, family = OPERATION_BINARY_TYPE_FAMILY }; };
153 
155  } // namespace result_of
156 
157 
158 
159 
160 
163  {
165 
166  // LHS or RHS are again an expression:
168 
169  // device scalars:
171 
172  // vector:
174 
175  // matrices:
177  };
178 
181  {
182  INVALID_SUBTYPE = 0, //when type is COMPOSITE_OPERATION_FAMILY
183 
186 
189 
193 
198 
199  // other matrix types to be added here
200  };
201 
204  {
205  INVALID_NUMERIC_TYPE = 0, //when type is COMPOSITE_OPERATION_FAMILY
206 
218  };
219 
220 
221  namespace result_of
222  {
224 
226  template <typename T>
227  struct numeric_type_id {};
228 
231  template <> struct numeric_type_id<char> { enum { value = CHAR_TYPE }; };
232  template <> struct numeric_type_id<unsigned char> { enum { value = UCHAR_TYPE }; };
233  template <> struct numeric_type_id<short> { enum { value = SHORT_TYPE }; };
234  template <> struct numeric_type_id<unsigned short> { enum { value = USHORT_TYPE }; };
235  template <> struct numeric_type_id<int> { enum { value = INT_TYPE }; };
236  template <> struct numeric_type_id<unsigned int> { enum { value = UINT_TYPE }; };
237  template <> struct numeric_type_id<long> { enum { value = LONG_TYPE }; };
238  template <> struct numeric_type_id<unsigned long> { enum { value = ULONG_TYPE }; };
239  template <> struct numeric_type_id<float> { enum { value = FLOAT_TYPE }; };
240  template <> struct numeric_type_id<double> { enum { value = DOUBLE_TYPE }; };
241 
244 
247  template <typename F>
248  struct layout_type_id {};
249 
252  template <> struct layout_type_id<viennacl::column_major> { enum { value = DENSE_COL_MATRIX_TYPE }; };
253  template <> struct layout_type_id<viennacl::row_major > { enum { value = DENSE_ROW_MATRIX_TYPE }; };
254 
256  }
257 
258 
259 
268  {
272 
273  union
274  {
277 
279 
280  // host scalars:
281  char host_char;
282  unsigned char host_uchar;
283  short host_short;
284  unsigned short host_ushort;
285  int host_int;
286  unsigned int host_uint;
287  long host_long;
288  unsigned long host_ulong;
289  float host_float;
290  double host_double;
291 
292  // Note: ViennaCL types have potentially expensive copy-CTORs, hence using pointers:
293 
294  // scalars:
295  //viennacl::scalar<char> *scalar_char;
296  //viennacl::scalar<unsigned char> *scalar_uchar;
297  //viennacl::scalar<short> *scalar_short;
298  //viennacl::scalar<unsigned short> *scalar_ushort;
299  //viennacl::scalar<int> *scalar_int;
300  //viennacl::scalar<unsigned int> *scalar_uint;
301  //viennacl::scalar<long> *scalar_long;
302  //viennacl::scalar<unsigned long> *scalar_ulong;
305 
306  // vectors:
307  //viennacl::vector_base<char> *vector_char;
308  //viennacl::vector_base<unsigned char> *vector_uchar;
309  //viennacl::vector_base<short> *vector_short;
310  //viennacl::vector_base<unsigned short> *vector_ushort;
311  //viennacl::vector_base<int> *vector_int;
312  //viennacl::vector_base<unsigned int> *vector_uint;
313  //viennacl::vector_base<long> *vector_long;
314  //viennacl::vector_base<unsigned long> *vector_ulong;
317 
318  // implicit vectors:
319  //viennacl::implicit_vector_base<char> *implicit_vector_char;
320  //viennacl::implicit_vector_base<unsigned char> *implicit_vector_uchar;
321  //viennacl::implicit_vector_base<short> *implicit_vector_short;
322  //viennacl::implicit_vector_base<unsigned short> *implicit_vector_ushort;
323  //viennacl::implicit_vector_base<int> *implicit_vector_int;
324  //viennacl::implicit_vector_base<unsigned int> *implicit_vector_uint;
325  //viennacl::implicit_vector_base<long> *implicit_vector_long;
326  //viennacl::implicit_vector_base<unsigned long> *implicit_vector_ulong;
329 
330  // row-major matrices:
331  //viennacl::matrix_base<char> *matrix_row_char;
332  //viennacl::matrix_base<unsigned char> *matrix_row_uchar;
333  //viennacl::matrix_base<short> *matrix_row_short;
334  //viennacl::matrix_base<unsigned short> *matrix_row_ushort;
335  //viennacl::matrix_base<int> *matrix_row_int;
336  //viennacl::matrix_base<unsigned int> *matrix_row_uint;
337  //viennacl::matrix_base<long> *matrix_row_long;
338  //viennacl::matrix_base<unsigned long> *matrix_row_ulong;
341 
342  // column-major matrices:
343  //viennacl::matrix_base<char, viennacl::column_major> *matrix_col_char;
344  //viennacl::matrix_base<unsigned char, viennacl::column_major> *matrix_col_uchar;
345  //viennacl::matrix_base<short, viennacl::column_major> *matrix_col_short;
346  //viennacl::matrix_base<unsigned short, viennacl::column_major> *matrix_col_ushort;
347  //viennacl::matrix_base<int, viennacl::column_major> *matrix_col_int;
348  //viennacl::matrix_base<unsigned int, viennacl::column_major> *matrix_col_uint;
349  //viennacl::matrix_base<long, viennacl::column_major> *matrix_col_long;
350  //viennacl::matrix_base<unsigned long, viennacl::column_major> *matrix_col_ulong;
353 
354  //viennacl::implicit_matrix_base<char> *implicit_matrix_char;
355  //viennacl::implicit_matrix_base<unsigned char> *implicit_matrix_uchar;
356  //viennacl::implicit_matrix_base<short> *implicit_matrix_short;
357  //viennacl::implicit_matrix_base<unsigned short> *implicit_matrix_ushort;
358  //viennacl::implicit_matrix_base<int> *implicit_matrix_int;
359  //viennacl::implicit_matrix_base<unsigned int> *implicit_matrix_uint;
360  //viennacl::implicit_matrix_base<long> *implicit_matrix_long;
361  //viennacl::implicit_matrix_base<unsigned long> *implicit_matrix_ulong;
364 
365  //viennacl::compressed_matrix<float> *compressed_matrix_char;
366  //viennacl::compressed_matrix<double> *compressed_matrix_uchar;
367  //viennacl::compressed_matrix<float> *compressed_matrix_short;
368  //viennacl::compressed_matrix<double> *compressed_matrix_ushort;
369  //viennacl::compressed_matrix<float> *compressed_matrix_int;
370  //viennacl::compressed_matrix<double> *compressed_matrix_uint;
371  //viennacl::compressed_matrix<float> *compressed_matrix_long;
372  //viennacl::compressed_matrix<double> *compressed_matrix_ulong;
375 
376  //viennacl::coordinate_matrix<float> *coordinate_matrix_char;
377  //viennacl::coordinate_matrix<double> *coordinate_matrix_uchar;
378  //viennacl::coordinate_matrix<float> *coordinate_matrix_short;
379  //viennacl::coordinate_matrix<double> *coordinate_matrix_ushort;
380  //viennacl::coordinate_matrix<float> *coordinate_matrix_int;
381  //viennacl::coordinate_matrix<double> *coordinate_matrix_uint;
382  //viennacl::coordinate_matrix<float> *coordinate_matrix_long;
383  //viennacl::coordinate_matrix<double> *coordinate_matrix_ulong;
386 
387  //viennacl::ell_matrix<float> *ell_matrix_char;
388  //viennacl::ell_matrix<double> *ell_matrix_uchar;
389  //viennacl::ell_matrix<float> *ell_matrix_short;
390  //viennacl::ell_matrix<double> *ell_matrix_ushort;
391  //viennacl::ell_matrix<float> *ell_matrix_int;
392  //viennacl::ell_matrix<double> *ell_matrix_uint;
393  //viennacl::ell_matrix<float> *ell_matrix_long;
394  //viennacl::ell_matrix<double> *ell_matrix_ulong;
397 
398  //viennacl::hyb_matrix<float> *hyb_matrix_char;
399  //viennacl::hyb_matrix<double> *hyb_matrix_uchar;
400  //viennacl::hyb_matrix<float> *hyb_matrix_short;
401  //viennacl::hyb_matrix<double> *hyb_matrix_ushort;
402  //viennacl::hyb_matrix<float> *hyb_matrix_int;
403  //viennacl::hyb_matrix<double> *hyb_matrix_uint;
404  //viennacl::hyb_matrix<float> *hyb_matrix_long;
405  //viennacl::hyb_matrix<double> *hyb_matrix_ulong;
408  };
409  };
410 
411 
413  struct op_element
414  {
417  };
418 
421  {
425  };
426 
427  namespace result_of
428  {
429 
431  template <class T> struct num_nodes { enum { value = 0 }; };
433  template <class LHS, class OP, class RHS> struct num_nodes< vector_expression<LHS, RHS, OP> > { enum { value = 1 + num_nodes<LHS>::value + num_nodes<RHS>::value }; };
434  template <class LHS, class OP, class RHS> struct num_nodes< const vector_expression<LHS, RHS, OP> > { enum { value = 1 + num_nodes<LHS>::value + num_nodes<RHS>::value }; };
435  template <class LHS, class OP, class RHS> struct num_nodes< matrix_expression<LHS, RHS, OP> > { enum { value = 1 + num_nodes<LHS>::value + num_nodes<RHS>::value }; };
436  template <class LHS, class OP, class RHS> struct num_nodes< const matrix_expression<LHS, RHS, OP> > { enum { value = 1 + num_nodes<LHS>::value + num_nodes<RHS>::value }; };
437  template <class LHS, class OP, class RHS> struct num_nodes< scalar_expression<LHS, RHS, OP> > { enum { value = 1 + num_nodes<LHS>::value + num_nodes<RHS>::value }; };
438  template <class LHS, class OP, class RHS> struct num_nodes< const scalar_expression<LHS, RHS, OP> > { enum { value = 1 + num_nodes<LHS>::value + num_nodes<RHS>::value }; };
441  }
442 
447  class statement
448  {
449  public:
452  typedef std::vector<value_type> container_type;
453 
454  statement(container_type const & custom_array) : array_(custom_array) {}
455 
459  template <typename LHS, typename OP, typename RHS>
460  statement(LHS & lhs, OP const &, RHS const & rhs) : array_(1 + result_of::num_nodes<RHS>::value)
461  {
462  // set OP:
465 
466  // set LHS:
467  add_lhs(0, 1, lhs);
468 
469  // set RHS:
470  add_rhs(0, 1, rhs);
471  }
472 
473  container_type const & array() const { return array_; }
474 
475  size_type root() const { return 0; }
476 
477  private:
478 
480 
481  // TODO: add integer vector overloads here
482  void assign_element(lhs_rhs_element & elem, viennacl::scalar<float> const & t) { elem.scalar_float = const_cast<viennacl::scalar<float> *>(&t); }
483  void assign_element(lhs_rhs_element & elem, viennacl::scalar<double> const & t) { elem.scalar_double = const_cast<viennacl::scalar<double> *>(&t); }
484 
486  // TODO: add integer vector overloads here
487  void assign_element(lhs_rhs_element & elem, viennacl::vector_base<float> const & t) { elem.vector_float = const_cast<viennacl::vector_base<float> *>(&t); }
488  void assign_element(lhs_rhs_element & elem, viennacl::vector_base<double> const & t) { elem.vector_double = const_cast<viennacl::vector_base<double> *>(&t); }
489 
491  // TODO: add integer matrix overloads here
492  void assign_element(lhs_rhs_element & elem, viennacl::matrix_base<float, viennacl::column_major> const & t) { elem.matrix_col_float = const_cast<viennacl::matrix_base<float, viennacl::column_major> *>(&t); }
493  void assign_element(lhs_rhs_element & elem, viennacl::matrix_base<float, viennacl::row_major> const & t) { elem.matrix_row_float = const_cast<viennacl::matrix_base<float, viennacl::row_major> *>(&t); }
494  void assign_element(lhs_rhs_element & elem, viennacl::matrix_base<double, viennacl::column_major> const & t) { elem.matrix_col_double = const_cast<viennacl::matrix_base<double, viennacl::column_major> *>(&t); }
495  void assign_element(lhs_rhs_element & elem, viennacl::matrix_base<double, viennacl::row_major> const & t) { elem.matrix_row_double = const_cast<viennacl::matrix_base<double, viennacl::row_major> *>(&t); }
496 
497  void assign_element(lhs_rhs_element & elem, viennacl::compressed_matrix<float> const & m) { elem.compressed_matrix_float = const_cast<viennacl::compressed_matrix<float> *>(&m); }
498  void assign_element(lhs_rhs_element & elem, viennacl::compressed_matrix<double> const & m) { elem.compressed_matrix_double = const_cast<viennacl::compressed_matrix<double> *>(&m); }
499 
500  void assign_element(lhs_rhs_element & elem, viennacl::coordinate_matrix<float> const & m) { elem.coordinate_matrix_float = const_cast<viennacl::coordinate_matrix<float> *>(&m); }
501  void assign_element(lhs_rhs_element & elem, viennacl::coordinate_matrix<double> const & m) { elem.coordinate_matrix_double = const_cast<viennacl::coordinate_matrix<double> *>(&m); }
502 
503  void assign_element(lhs_rhs_element & elem, viennacl::ell_matrix<float> const & m) { elem.ell_matrix_float = const_cast<viennacl::ell_matrix<float> *>(&m); }
504  void assign_element(lhs_rhs_element & elem, viennacl::ell_matrix<double> const & m) { elem.ell_matrix_double = const_cast<viennacl::ell_matrix<double> *>(&m); }
505 
506  void assign_element(lhs_rhs_element & elem, viennacl::hyb_matrix<float> const & m) { elem.hyb_matrix_float = const_cast<viennacl::hyb_matrix<float> *>(&m); }
507  void assign_element(lhs_rhs_element & elem, viennacl::hyb_matrix<double> const & m) { elem.hyb_matrix_double = const_cast<viennacl::hyb_matrix<double> *>(&m); }
508 
510 
511  vcl_size_t add_element(vcl_size_t next_free,
512  lhs_rhs_element & elem,
513  float const & t)
514  {
515  elem.type_family = SCALAR_TYPE_FAMILY;
516  elem.subtype = HOST_SCALAR_TYPE;
517  elem.numeric_type = FLOAT_TYPE;
518  elem.host_float = t;
519  return next_free;
520  }
521 
522  vcl_size_t add_element(vcl_size_t next_free,
523  lhs_rhs_element & elem,
524  double const & t)
525  {
526  elem.type_family = SCALAR_TYPE_FAMILY;
527  elem.subtype = HOST_SCALAR_TYPE;
528  elem.numeric_type = DOUBLE_TYPE;
529  elem.host_double = t;
530  return next_free;
531  }
532 
533  template <typename T>
534  vcl_size_t add_element(vcl_size_t next_free,
535  lhs_rhs_element & elem,
536  viennacl::scalar<T> const & t)
537  {
538  elem.type_family = SCALAR_TYPE_FAMILY;
539  elem.subtype = DEVICE_SCALAR_TYPE;
540  elem.numeric_type = statement_node_numeric_type(result_of::numeric_type_id<T>::value);
541  assign_element(elem, t);
542  return next_free;
543  }
544 
545 
546  template <typename T>
547  vcl_size_t add_element(vcl_size_t next_free,
548  lhs_rhs_element & elem,
549  viennacl::vector_base<T> const & t)
550  {
551  elem.type_family = VECTOR_TYPE_FAMILY;
552  elem.subtype = DENSE_VECTOR_TYPE;
553  elem.numeric_type = statement_node_numeric_type(result_of::numeric_type_id<T>::value);
554  assign_element(elem, t);
555  return next_free;
556  }
557 
558  template <typename T, typename F>
559  vcl_size_t add_element(vcl_size_t next_free,
560  lhs_rhs_element & elem,
561  viennacl::matrix_base<T, F> const & t)
562  {
563  elem.type_family = MATRIX_TYPE_FAMILY;
564  elem.subtype = statement_node_subtype(result_of::layout_type_id<F>::value);
565  elem.numeric_type = statement_node_numeric_type(result_of::numeric_type_id<T>::value);
566  assign_element(elem, t);
567  return next_free;
568  }
569 
570  template <typename T>
571  vcl_size_t add_element(vcl_size_t next_free,
572  lhs_rhs_element & elem,
574  {
575  elem.type_family = MATRIX_TYPE_FAMILY;
576  elem.subtype = COMPRESSED_MATRIX_TYPE;
577  elem.numeric_type = statement_node_numeric_type(result_of::numeric_type_id<T>::value);
578  assign_element(elem, t);
579  return next_free;
580  }
581 
582  template <typename T>
583  vcl_size_t add_element(vcl_size_t next_free,
584  lhs_rhs_element & elem,
586  {
587  elem.type_family = MATRIX_TYPE_FAMILY;
588  elem.subtype = COORDINATE_MATRIX_TYPE;
589  elem.numeric_type = statement_node_numeric_type(result_of::numeric_type_id<T>::value);
590  assign_element(elem, t);
591  return next_free;
592  }
593 
594  template <typename T>
595  vcl_size_t add_element(vcl_size_t next_free,
596  lhs_rhs_element & elem,
597  viennacl::ell_matrix<T> const & t)
598  {
599  elem.type_family = MATRIX_TYPE_FAMILY;
600  elem.subtype = ELL_MATRIX_TYPE;
601  elem.numeric_type = statement_node_numeric_type(result_of::numeric_type_id<T>::value);
602  assign_element(elem, t);
603  return next_free;
604  }
605 
606  template <typename T>
607  vcl_size_t add_element(vcl_size_t next_free,
608  lhs_rhs_element & elem,
609  viennacl::hyb_matrix<T> const & t)
610  {
611  elem.type_family = MATRIX_TYPE_FAMILY;
612  elem.subtype = HYB_MATRIX_TYPE;
613  elem.numeric_type = statement_node_numeric_type(result_of::numeric_type_id<T>::value);
614  assign_element(elem, t);
615  return next_free;
616  }
617 
618 
620 
621  template <typename LHS, typename RHS, typename OP>
622  vcl_size_t add_element(vcl_size_t next_free,
623  lhs_rhs_element & elem,
625  {
626  elem.type_family = COMPOSITE_OPERATION_FAMILY;
627  elem.subtype = INVALID_SUBTYPE;
628  elem.numeric_type = INVALID_NUMERIC_TYPE;
629  elem.node_index = next_free;
630  return add_node(next_free, next_free + 1, t);
631  }
632 
633  template <typename LHS, typename RHS, typename OP>
634  vcl_size_t add_element(vcl_size_t next_free,
635  lhs_rhs_element & elem,
637  {
638  elem.type_family = COMPOSITE_OPERATION_FAMILY;
639  elem.subtype = INVALID_SUBTYPE;
640  elem.numeric_type = INVALID_NUMERIC_TYPE;
641  elem.node_index = next_free;
642  return add_node(next_free, next_free + 1, t);
643  }
644 
645  template <typename LHS, typename RHS, typename OP>
646  vcl_size_t add_element(vcl_size_t next_free,
647  lhs_rhs_element & elem,
649  {
650  elem.type_family = COMPOSITE_OPERATION_FAMILY;
651  elem.subtype = INVALID_SUBTYPE;
652  elem.numeric_type = INVALID_NUMERIC_TYPE;
653  elem.node_index = next_free;
654  return add_node(next_free, next_free + 1, t);
655  }
656 
657 
659 
660 
661  template <typename T>
662  vcl_size_t add_lhs(vcl_size_t current_index, vcl_size_t next_free, T const & t)
663  {
664  return add_element(next_free, array_[current_index].lhs, t);
665  }
666 
667  template <typename T>
668  vcl_size_t add_rhs(vcl_size_t current_index, vcl_size_t next_free, T const & t)
669  {
670  return add_element(next_free, array_[current_index].rhs, t);
671  }
672 
674 
675  template <template <typename, typename, typename> class ExpressionT, typename LHS, typename RHS, typename OP>
676  vcl_size_t add_node(vcl_size_t current_index, vcl_size_t next_free, ExpressionT<LHS, RHS, OP> const & proxy)
677  {
678  // set OP:
679  array_[current_index].op.type_family = operation_node_type_family(result_of::op_type_info<OP>::family);
680  array_[current_index].op.type = operation_node_type(result_of::op_type_info<OP>::id);
681 
682  // set LHS and RHS:
683  if (array_[current_index].op.type_family == OPERATION_UNARY_TYPE_FAMILY)
684  {
685  // unary expression: set rhs to invalid:
686  array_[current_index].rhs.type_family = INVALID_TYPE_FAMILY;
687  array_[current_index].rhs.subtype = INVALID_SUBTYPE;
688  array_[current_index].rhs.numeric_type = INVALID_NUMERIC_TYPE;
689  return add_lhs(current_index, next_free, proxy.lhs());
690  }
691 
692  return add_rhs(current_index, add_lhs(current_index, next_free, proxy.lhs()), proxy.rhs());
693 
694  }
695 
696  container_type array_;
697  };
698 
699  namespace detail
700  {
702  inline void execute_composite(statement const & /* s */, statement_node const & /* root_node */);
703  }
704 
705  } // namespace scheduler
706 
707 } // namespace viennacl
708 
709 #endif
710 
statement_node_subtype subtype
Definition: forwards.h:270
viennacl::hyb_matrix< float > * hyb_matrix_float
Definition: forwards.h:406
viennacl::matrix_base< float > * matrix_row_float
Definition: forwards.h:339
std::size_t vcl_size_t
Definition: forwards.h:58
int host_int
Definition: forwards.h:285
Definition: forwards.h:210
Definition: forwards.h:182
viennacl::vcl_size_t size_type
Definition: forwards.h:451
vcl_size_t node_index
Definition: forwards.h:276
statement(container_type const &custom_array)
Definition: forwards.h:454
virtual const char * what() const
Definition: forwards.h:42
lhs_rhs_element lhs
Definition: forwards.h:422
Definition: forwards.h:176
char host_char
Definition: forwards.h:281
Definition: forwards.h:217
Definition: forwards.h:185
viennacl::implicit_vector_base< double > * implicit_vector_double
Definition: forwards.h:328
Definition: forwards.h:196
A tag class representing the modulus function for integers.
Definition: forwards.h:93
viennacl::scalar< float > * scalar_float
Definition: forwards.h:303
Expression template class for representing a tree of expressions which ultimately result in a matrix...
Definition: forwards.h:283
viennacl::coordinate_matrix< float > * coordinate_matrix_float
Definition: forwards.h:384
viennacl::implicit_matrix_base< float > * implicit_matrix_float
Definition: forwards.h:362
operation_node_type_family
Optimization enum for grouping operations into unary or binary operations. Just for optimization of l...
Definition: forwards.h:51
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
Helper metafunction for obtaining the number of nodes of an expression template tree.
Definition: forwards.h:431
statement(LHS &lhs, OP const &, RHS const &rhs)
Generate the runtime statement from an expression template.
Definition: forwards.h:460
operation_node_type_family type_family
Definition: forwards.h:415
statement_not_supported_exception(std::string message)
Definition: forwards.h:40
viennacl::compressed_matrix< double > * compressed_matrix_double
Definition: forwards.h:374
Helper metafunction for obtaining the memory layout (row-/column-major) for a matrix.
Definition: forwards.h:248
A proxy for scalar expressions (e.g. from inner vector products)
Definition: forwards.h:175
An expression template class that represents a binary operation that yields a vector.
Definition: forwards.h:181
unsigned char host_uchar
Definition: forwards.h:282
lhs_rhs_element rhs
Definition: forwards.h:424
Struct for holding the type family as well as the type of an operation (could be addition, subtraction, norm, etc.)
Definition: forwards.h:413
viennacl::matrix_base< float, viennacl::column_major > * matrix_col_float
Definition: forwards.h:351
T::ERROR_UNKNOWN_OP_TYPE error_type
Definition: forwards.h:112
viennacl::scalar< double > * scalar_double
Definition: forwards.h:304
Definition: forwards.h:214
statement_not_supported_exception()
Definition: forwards.h:39
Definition: forwards.h:197
viennacl::matrix_base< double, viennacl::column_major > * matrix_col_double
Definition: forwards.h:352
Definition: forwards.h:170
viennacl::vector_base< float > * vector_float
Definition: forwards.h:315
statement_node_numeric_type numeric_type
Definition: forwards.h:271
statement_node_type_family
Groups the type of a node in the statement tree. Used for faster dispatching.
Definition: forwards.h:162
statement_node_numeric_type
Encodes the type of a node in the statement tree.
Definition: forwards.h:203
viennacl::coordinate_matrix< double > * coordinate_matrix_double
Definition: forwards.h:385
viennacl::vector_base< double > * vector_double
Definition: forwards.h:316
Helper metafunction for obtaining the operation ID as well as the operation family for unary and bina...
Definition: forwards.h:110
Definition: forwards.h:184
size_type root() const
Definition: forwards.h:475
Definition: forwards.h:173
Definition: forwards.h:209
double host_double
Definition: forwards.h:290
Definition: forwards.h:215
float host_float
Definition: forwards.h:289
viennacl::implicit_vector_base< float > * implicit_vector_float
Definition: forwards.h:327
std::vector< value_type > container_type
Definition: forwards.h:452
statement_node value_type
Definition: forwards.h:450
unsigned long host_ulong
Definition: forwards.h:288
viennacl::compressed_matrix< float > * compressed_matrix_float
Definition: forwards.h:373
short host_short
Definition: forwards.h:283
operation_node_type
Enumeration for identifying the possible operations.
Definition: forwards.h:61
unsigned int host_uint
Definition: forwards.h:286
Helper metafunction for obtaining the runtime type ID for a numerical type.
Definition: forwards.h:227
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
Definition: forwards.h:211
statement_node_subtype
Encodes the type of a node in the statement tree.
Definition: forwards.h:180
Definition: forwards.h:207
Definition: forwards.h:212
virtual ~statement_not_supported_exception()
Definition: forwards.h:44
viennacl::implicit_matrix_base< double > * implicit_matrix_double
Definition: forwards.h:363
viennacl::matrix_base< double > * matrix_row_double
Definition: forwards.h:340
A tag for column-major storage of a dense matrix.
Definition: forwards.h:263
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
viennacl::ell_matrix< float > * ell_matrix_float
Definition: forwards.h:395
A tag class representing the acos() function.
Definition: forwards.h:95
long host_long
Definition: forwards.h:287
viennacl::ell_matrix< double > * ell_matrix_double
Definition: forwards.h:396
Definition: forwards.h:187
op_element op
Definition: forwards.h:423
A tag class representing element-wise unary operations (like sin()) on vectors or matrices...
Definition: forwards.h:90
Definition: forwards.h:208
A tag for row-major storage of a dense matrix.
Definition: forwards.h:246
Definition: forwards.h:216
Main datastructure for an node in the statement tree.
Definition: forwards.h:420
Definition: forwards.h:213
Exception for the case the scheduler is unable to deal with the operation.
Definition: forwards.h:36
unsigned short host_ushort
Definition: forwards.h:284
operation_node_type type
Definition: forwards.h:416
viennacl::hyb_matrix< double > * hyb_matrix_double
Definition: forwards.h:407