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
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-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 
28 #include "viennacl/forwards.h"
29 
30 #include <vector>
31 
32 namespace viennacl
33 {
34 namespace scheduler
35 {
36 
38 class statement_not_supported_exception : public std::exception
39 {
40 public:
42  statement_not_supported_exception(std::string message) : message_("ViennaCL: Internal error: The scheduler encountered a problem with the operation provided: " + message) {}
43 
44  virtual const char* what() const throw() { return message_.c_str(); }
45 
47 private:
48  std::string message_;
49 };
50 
51 
54 {
56 
57  // unary or binary expression
60 
61  //reductions
65 };
66 
69 {
71 
72  // unary operator
74 
75  // unary expression
87 
105 
112 
113  // binary expression
120  OPERATION_BINARY_MULT_TYPE, // scalar times vector/matrix
121  OPERATION_BINARY_DIV_TYPE, // vector/matrix divided by scalar
139 
147 
148 };
149 
150 
151 
152 namespace result_of
153 {
155  template<typename T>
157  {
158  typedef typename T::ERROR_UNKNOWN_OP_TYPE error_type;
159  };
160 
162  // elementwise casts
163  template<> struct op_type_info<op_element_cast<char> > { enum { id = OPERATION_UNARY_CAST_CHAR_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
164  template<> struct op_type_info<op_element_cast<unsigned char> > { enum { id = OPERATION_UNARY_CAST_UCHAR_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
165  template<> struct op_type_info<op_element_cast<short> > { enum { id = OPERATION_UNARY_CAST_SHORT_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
166  template<> struct op_type_info<op_element_cast<unsigned short> > { enum { id = OPERATION_UNARY_CAST_USHORT_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
167  template<> struct op_type_info<op_element_cast<int> > { enum { id = OPERATION_UNARY_CAST_INT_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
168  template<> struct op_type_info<op_element_cast<unsigned int> > { enum { id = OPERATION_UNARY_CAST_UINT_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
169  template<> struct op_type_info<op_element_cast<long> > { enum { id = OPERATION_UNARY_CAST_LONG_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
170  template<> struct op_type_info<op_element_cast<unsigned long> > { enum { id = OPERATION_UNARY_CAST_ULONG_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
171  template<> struct op_type_info<op_element_cast<float> > { enum { id = OPERATION_UNARY_CAST_FLOAT_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
172  template<> struct op_type_info<op_element_cast<double> > { enum { id = OPERATION_UNARY_CAST_DOUBLE_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
173 
174  // elementwise functions
175  template<> struct op_type_info<op_element_unary<op_abs> > { enum { id = OPERATION_UNARY_ABS_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
176  template<> struct op_type_info<op_element_unary<op_acos> > { enum { id = OPERATION_UNARY_ACOS_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
177  template<> struct op_type_info<op_element_unary<op_asin> > { enum { id = OPERATION_UNARY_ASIN_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
178  template<> struct op_type_info<op_element_unary<op_atan> > { enum { id = OPERATION_UNARY_ATAN_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
179  template<> struct op_type_info<op_element_unary<op_ceil> > { enum { id = OPERATION_UNARY_CEIL_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
180  template<> struct op_type_info<op_element_unary<op_cos> > { enum { id = OPERATION_UNARY_COS_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
181  template<> struct op_type_info<op_element_unary<op_cosh> > { enum { id = OPERATION_UNARY_COSH_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
182  template<> struct op_type_info<op_element_unary<op_exp> > { enum { id = OPERATION_UNARY_EXP_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
183  template<> struct op_type_info<op_element_unary<op_fabs> > { enum { id = OPERATION_UNARY_FABS_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
184  template<> struct op_type_info<op_element_unary<op_floor> > { enum { id = OPERATION_UNARY_FLOOR_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
185  template<> struct op_type_info<op_element_unary<op_log> > { enum { id = OPERATION_UNARY_LOG_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
186  template<> struct op_type_info<op_element_unary<op_log10> > { enum { id = OPERATION_UNARY_LOG10_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
187  template<> struct op_type_info<op_element_unary<op_sin> > { enum { id = OPERATION_UNARY_SIN_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
188  template<> struct op_type_info<op_element_unary<op_sinh> > { enum { id = OPERATION_UNARY_SINH_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
189  template<> struct op_type_info<op_element_unary<op_sqrt> > { enum { id = OPERATION_UNARY_SQRT_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
190  template<> struct op_type_info<op_element_unary<op_tan> > { enum { id = OPERATION_UNARY_TAN_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
191  template<> struct op_type_info<op_element_unary<op_tanh> > { enum { id = OPERATION_UNARY_TANH_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
192 
193  template<> struct op_type_info<op_element_binary<op_argmax> > { enum { id = OPERATION_BINARY_ELEMENT_ARGMAX_TYPE , family = OPERATION_BINARY_TYPE_FAMILY}; };
194  template<> struct op_type_info<op_element_binary<op_argmin> > { enum { id = OPERATION_BINARY_ELEMENT_ARGMIN_TYPE , family = OPERATION_BINARY_TYPE_FAMILY}; };
195  template<> struct op_type_info<op_element_binary<op_pow> > { enum { id = OPERATION_BINARY_ELEMENT_POW_TYPE , family = OPERATION_BINARY_TYPE_FAMILY}; };
196  template<> struct op_type_info<op_element_binary<op_eq> > { enum { id = OPERATION_BINARY_ELEMENT_EQ_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
197  template<> struct op_type_info<op_element_binary<op_neq> > { enum { id = OPERATION_BINARY_ELEMENT_NEQ_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
198  template<> struct op_type_info<op_element_binary<op_greater> > { enum { id = OPERATION_BINARY_ELEMENT_GREATER_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
199  template<> struct op_type_info<op_element_binary<op_less> > { enum { id = OPERATION_BINARY_ELEMENT_LESS_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
200  template<> struct op_type_info<op_element_binary<op_geq> > { enum { id = OPERATION_BINARY_ELEMENT_GEQ_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
201  template<> struct op_type_info<op_element_binary<op_leq> > { enum { id = OPERATION_BINARY_ELEMENT_LEQ_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
202  template<> struct op_type_info<op_element_binary<op_fmax> > { enum { id = OPERATION_BINARY_ELEMENT_FMAX_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
203  template<> struct op_type_info<op_element_binary<op_fmin> > { enum { id = OPERATION_BINARY_ELEMENT_FMIN_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
204 
205 
206  //structurewise function
207  template<> struct op_type_info<op_norm_1 > { enum { id = OPERATION_UNARY_NORM_1_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
208  template<> struct op_type_info<op_norm_2 > { enum { id = OPERATION_UNARY_NORM_2_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
209  template<> struct op_type_info<op_norm_inf > { enum { id = OPERATION_UNARY_NORM_INF_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
210  template<> struct op_type_info<op_max > { enum { id = OPERATION_UNARY_MAX_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
211  template<> struct op_type_info<op_min > { enum { id = OPERATION_UNARY_MIN_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
212 
213  template<> struct op_type_info<op_trans > { enum { id = OPERATION_UNARY_TRANS_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
214  template<> struct op_type_info<op_row > { enum { id = OPERATION_BINARY_MATRIX_ROW_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
215  template<> struct op_type_info<op_column > { enum { id = OPERATION_BINARY_MATRIX_COLUMN_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
216 
217  template<> struct op_type_info<op_matrix_diag> { enum { id = OPERATION_BINARY_MATRIX_DIAG_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
218  template<> struct op_type_info<op_vector_diag> { enum { id = OPERATION_BINARY_VECTOR_DIAG_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
219 
220  template<> struct op_type_info<op_prod> { enum { id = OPERATION_BINARY_MAT_VEC_PROD_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
221  template<> struct op_type_info<op_mat_mat_prod> { enum { id = OPERATION_BINARY_MAT_MAT_PROD_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
222  template<> struct op_type_info<op_inner_prod> { enum { id = OPERATION_BINARY_INNER_PROD_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
223 
224  //elementwise operator
225  template<> struct op_type_info<op_assign> { enum { id = OPERATION_BINARY_ASSIGN_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
226  template<> struct op_type_info<op_inplace_add> { enum { id = OPERATION_BINARY_INPLACE_ADD_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
227  template<> struct op_type_info<op_inplace_sub> { enum { id = OPERATION_BINARY_INPLACE_SUB_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
228  template<> struct op_type_info<op_add> { enum { id = OPERATION_BINARY_ADD_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
229  template<> struct op_type_info<op_sub> { enum { id = OPERATION_BINARY_SUB_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
230  template<> struct op_type_info<op_element_binary<op_prod> > { enum { id = OPERATION_BINARY_ELEMENT_PROD_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
231  template<> struct op_type_info<op_element_binary<op_div> > { enum { id = OPERATION_BINARY_ELEMENT_DIV_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
232  template<> struct op_type_info<op_mult> { enum { id = OPERATION_BINARY_MULT_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
233  template<> struct op_type_info<op_div> { enum { id = OPERATION_BINARY_DIV_TYPE, family = OPERATION_BINARY_TYPE_FAMILY}; };
234 
235  template<> struct op_type_info<op_flip_sign> { enum { id = OPERATION_UNARY_MINUS_TYPE, family = OPERATION_UNARY_TYPE_FAMILY}; };
236 
237 
239 } // namespace result_of
240 
241 
242 
243 
244 
247 {
249 
250  // LHS or RHS are again an expression:
252 
253  // device scalars:
255 
256  // vector:
258 
259  // matrices:
261 };
262 
265 {
266  INVALID_SUBTYPE = 0, //when type is COMPOSITE_OPERATION_FAMILY
267 
270 
273 
276 
281 
282  // other matrix types to be added here
283 };
284 
287 {
288  INVALID_NUMERIC_TYPE = 0, //when type is COMPOSITE_OPERATION_FAMILY
289 
301 };
302 
303 
304 namespace result_of
305 {
307 
309  template<typename T>
310  struct numeric_type_id {};
311 
314  template<> struct numeric_type_id<char> { enum { value = CHAR_TYPE }; };
315  template<> struct numeric_type_id<unsigned char> { enum { value = UCHAR_TYPE }; };
316  template<> struct numeric_type_id<short> { enum { value = SHORT_TYPE }; };
317  template<> struct numeric_type_id<unsigned short> { enum { value = USHORT_TYPE }; };
318  template<> struct numeric_type_id<int> { enum { value = INT_TYPE }; };
319  template<> struct numeric_type_id<unsigned int> { enum { value = UINT_TYPE }; };
320  template<> struct numeric_type_id<long> { enum { value = LONG_TYPE }; };
321  template<> struct numeric_type_id<unsigned long> { enum { value = ULONG_TYPE }; };
322  template<> struct numeric_type_id<float> { enum { value = FLOAT_TYPE }; };
323  template<> struct numeric_type_id<double> { enum { value = DOUBLE_TYPE }; };
324 
326 }
327 
328 
329 
338 {
342 
343  union
344  {
347 
349 
350  // host scalars:
351  char host_char;
352  unsigned char host_uchar;
353  short host_short;
354  unsigned short host_ushort;
355  int host_int;
356  unsigned int host_uint;
357  long host_long;
358  unsigned long host_ulong;
359  float host_float;
360  double host_double;
361 
362  // Note: ViennaCL types have potentially expensive copy-CTORs, hence using pointers:
363 
364  // scalars:
375 
376  // vectors:
387 
388  // implicit vectors:
399 
400  // dense matrices:
411 
422 
423  //viennacl::compressed_matrix<float> *compressed_matrix_char;
424  //viennacl::compressed_matrix<double> *compressed_matrix_uchar;
425  //viennacl::compressed_matrix<float> *compressed_matrix_short;
426  //viennacl::compressed_matrix<double> *compressed_matrix_ushort;
427  //viennacl::compressed_matrix<float> *compressed_matrix_int;
428  //viennacl::compressed_matrix<double> *compressed_matrix_uint;
429  //viennacl::compressed_matrix<float> *compressed_matrix_long;
430  //viennacl::compressed_matrix<double> *compressed_matrix_ulong;
433 
434  //viennacl::coordinate_matrix<float> *coordinate_matrix_char;
435  //viennacl::coordinate_matrix<double> *coordinate_matrix_uchar;
436  //viennacl::coordinate_matrix<float> *coordinate_matrix_short;
437  //viennacl::coordinate_matrix<double> *coordinate_matrix_ushort;
438  //viennacl::coordinate_matrix<float> *coordinate_matrix_int;
439  //viennacl::coordinate_matrix<double> *coordinate_matrix_uint;
440  //viennacl::coordinate_matrix<float> *coordinate_matrix_long;
441  //viennacl::coordinate_matrix<double> *coordinate_matrix_ulong;
444 
445  //viennacl::ell_matrix<float> *ell_matrix_char;
446  //viennacl::ell_matrix<double> *ell_matrix_uchar;
447  //viennacl::ell_matrix<float> *ell_matrix_short;
448  //viennacl::ell_matrix<double> *ell_matrix_ushort;
449  //viennacl::ell_matrix<float> *ell_matrix_int;
450  //viennacl::ell_matrix<double> *ell_matrix_uint;
451  //viennacl::ell_matrix<float> *ell_matrix_long;
452  //viennacl::ell_matrix<double> *ell_matrix_ulong;
455 
456  //viennacl::hyb_matrix<float> *hyb_matrix_char;
457  //viennacl::hyb_matrix<double> *hyb_matrix_uchar;
458  //viennacl::hyb_matrix<float> *hyb_matrix_short;
459  //viennacl::hyb_matrix<double> *hyb_matrix_ushort;
460  //viennacl::hyb_matrix<float> *hyb_matrix_int;
461  //viennacl::hyb_matrix<double> *hyb_matrix_uint;
462  //viennacl::hyb_matrix<float> *hyb_matrix_long;
463  //viennacl::hyb_matrix<double> *hyb_matrix_ulong;
466  };
467 };
468 
469 
472 {
475 };
476 
479 {
483 };
484 
485 namespace result_of
486 {
487 
488  template<class T> struct num_nodes { enum { value = 0 }; };
489  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 + num_nodes<OP>::value }; };
490  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 + num_nodes<OP>::value }; };
491  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 + num_nodes<OP>::value }; };
492  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 + num_nodes<OP>::value }; };
493  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 + num_nodes<OP>::value }; };
494  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 + num_nodes<OP>::value }; };
495 
496 }
497 
503 {
504 public:
507  typedef std::vector<value_type> container_type;
508 
509  statement(container_type const & custom_array) : array_(custom_array) {}
510 
514  template<typename LHS, typename OP, typename RHS>
515  statement(LHS & lhs, OP const &, RHS const & rhs) : array_(1 + result_of::num_nodes<RHS>::value)
516  {
517  // set OP:
520 
521  // set LHS:
522  add_lhs(0, 1, lhs);
523 
524  // set RHS:
525  add_rhs(0, 1, rhs);
526  }
527 
528  container_type const & array() const { return array_; }
529 
530  size_type root() const { return 0; }
531 
534 
535  static void assign_element(lhs_rhs_element & elem, char const & t) { elem.host_char = t; }
536  static void assign_element(lhs_rhs_element & elem, unsigned char const & t) { elem.host_uchar = t; }
537  static void assign_element(lhs_rhs_element & elem, short const & t) { elem.host_short = t; }
538  static void assign_element(lhs_rhs_element & elem, unsigned short const & t) { elem.host_ushort = t; }
539  static void assign_element(lhs_rhs_element & elem, int const & t) { elem.host_int = t; }
540  static void assign_element(lhs_rhs_element & elem, unsigned int const & t) { elem.host_uint = t; }
541  static void assign_element(lhs_rhs_element & elem, long const & t) { elem.host_long = t; }
542  static void assign_element(lhs_rhs_element & elem, unsigned long const & t) { elem.host_ulong = t; }
543  static void assign_element(lhs_rhs_element & elem, float const & t) { elem.host_float = t; }
544  static void assign_element(lhs_rhs_element & elem, double const & t) { elem.host_double = t; }
545 
546  static void assign_element(lhs_rhs_element & elem, viennacl::scalar<char> const & t) { elem.scalar_char = const_cast<viennacl::scalar<char> *>(&t); }
548  static void assign_element(lhs_rhs_element & elem, viennacl::scalar<short> const & t) { elem.scalar_short = const_cast<viennacl::scalar<short> *>(&t); }
550  static void assign_element(lhs_rhs_element & elem, viennacl::scalar<int> const & t) { elem.scalar_int = const_cast<viennacl::scalar<int> *>(&t); }
552  static void assign_element(lhs_rhs_element & elem, viennacl::scalar<long> const & t) { elem.scalar_long = const_cast<viennacl::scalar<long> *>(&t); }
554  static void assign_element(lhs_rhs_element & elem, viennacl::scalar<float> const & t) { elem.scalar_float = const_cast<viennacl::scalar<float> *>(&t); }
555  static void assign_element(lhs_rhs_element & elem, viennacl::scalar<double> const & t) { elem.scalar_double = const_cast<viennacl::scalar<double> *>(&t); }
556 
558  static void assign_element(lhs_rhs_element & elem, viennacl::vector_base<char> const & t) { elem.vector_char = const_cast<viennacl::vector_base<char> *>(&t); }
560  static void assign_element(lhs_rhs_element & elem, viennacl::vector_base<short> const & t) { elem.vector_short = const_cast<viennacl::vector_base<short> *>(&t); }
562  static void assign_element(lhs_rhs_element & elem, viennacl::vector_base<int> const & t) { elem.vector_int = const_cast<viennacl::vector_base<int> *>(&t); }
564  static void assign_element(lhs_rhs_element & elem, viennacl::vector_base<long> const & t) { elem.vector_long = const_cast<viennacl::vector_base<long> *>(&t); }
566  static void assign_element(lhs_rhs_element & elem, viennacl::vector_base<float> const & t) { elem.vector_float = const_cast<viennacl::vector_base<float> *>(&t); }
568 
579 
581  // TODO: add integer matrix overloads here
582  static void assign_element(lhs_rhs_element & elem, viennacl::matrix_base<char> const & t) { elem.matrix_char = const_cast<viennacl::matrix_base<char> *>(&t); }
584  static void assign_element(lhs_rhs_element & elem, viennacl::matrix_base<short> const & t) { elem.matrix_short = const_cast<viennacl::matrix_base<short> *>(&t); }
586  static void assign_element(lhs_rhs_element & elem, viennacl::matrix_base<int> const & t) { elem.matrix_int = const_cast<viennacl::matrix_base<int> *>(&t); }
588  static void assign_element(lhs_rhs_element & elem, viennacl::matrix_base<long> const & t) { elem.matrix_long = const_cast<viennacl::matrix_base<long> *>(&t); }
590  static void assign_element(lhs_rhs_element & elem, viennacl::matrix_base<float> const & t) { elem.matrix_float = const_cast<viennacl::matrix_base<float> *>(&t); }
592 
603 
606 
609 
612 
615 
617 
618  template<class T>
621  lhs_rhs_element & elem,
622  T const & t)
623  {
625  elem.subtype = HOST_SCALAR_TYPE;
627  assign_element(elem, t);
628  return next_free;
629  }
630 
631  template<typename T>
633  lhs_rhs_element & elem,
634  viennacl::scalar<T> const & t)
635  {
639  assign_element(elem, t);
640  return next_free;
641  }
642 
643 
644  template<typename T>
646  lhs_rhs_element & elem,
647  viennacl::vector_base<T> const & t)
648  {
650  elem.subtype = DENSE_VECTOR_TYPE;
652  assign_element(elem, t);
653  return next_free;
654  }
655 
656  template<typename T>
658  lhs_rhs_element & elem,
660  {
664  assign_element(elem, t);
665  return next_free;
666  }
667 
668  template<typename T>
670  lhs_rhs_element & elem,
671  viennacl::matrix_base<T> const & t)
672  {
674  elem.subtype = DENSE_MATRIX_TYPE;
676  assign_element(elem, t);
677  return next_free;
678  }
679 
680  template<typename T>
682  lhs_rhs_element & elem,
684  {
688  assign_element(elem, t);
689  return next_free;
690  }
691 
692  template<typename T>
694  lhs_rhs_element & elem,
696  {
700  assign_element(elem, t);
701  return next_free;
702  }
703 
704  template<typename T>
706  lhs_rhs_element & elem,
708  {
712  assign_element(elem, t);
713  return next_free;
714  }
715 
716  template<typename T>
718  lhs_rhs_element & elem,
719  viennacl::ell_matrix<T> const & t)
720  {
722  elem.subtype = ELL_MATRIX_TYPE;
724  assign_element(elem, t);
725  return next_free;
726  }
727 
728  template<typename T>
730  lhs_rhs_element & elem,
731  viennacl::hyb_matrix<T> const & t)
732  {
734  elem.subtype = HYB_MATRIX_TYPE;
736  assign_element(elem, t);
737  return next_free;
738  }
739 
740 private:
741 
743 
744  template<typename LHS, typename RHS, typename OP>
746  lhs_rhs_element & elem,
748  {
750  elem.subtype = INVALID_SUBTYPE;
752  elem.node_index = next_free;
753  return add_node(next_free, next_free + 1, t);
754  }
755 
756  template<typename LHS, typename RHS, typename OP>
758  lhs_rhs_element & elem,
760  {
761  elem.type_family = COMPOSITE_OPERATION_FAMILY;
762  elem.subtype = INVALID_SUBTYPE;
763  elem.numeric_type = INVALID_NUMERIC_TYPE;
764  elem.node_index = next_free;
765  return add_node(next_free, next_free + 1, t);
766  }
767 
768  template<typename LHS, typename RHS, typename OP>
770  lhs_rhs_element & elem,
772  {
773  elem.type_family = COMPOSITE_OPERATION_FAMILY;
774  elem.subtype = INVALID_SUBTYPE;
775  elem.numeric_type = INVALID_NUMERIC_TYPE;
776  elem.node_index = next_free;
777  return add_node(next_free, next_free + 1, t);
778  }
779 
781 
782 
783  template<typename T>
784  vcl_size_t add_lhs(vcl_size_t current_index, vcl_size_t next_free, T const & t)
785  {
786  return add_element(next_free, array_[current_index].lhs, t);
787  }
788 
789  template<typename T>
790  vcl_size_t add_rhs(vcl_size_t current_index, vcl_size_t next_free, T const & t)
791  {
792  return add_element(next_free, array_[current_index].rhs, t);
793  }
794 
796 
797  template<template<typename, typename, typename> class ExpressionT, typename LHS, typename RHS, typename OP>
798  vcl_size_t add_node(vcl_size_t current_index, vcl_size_t next_free, ExpressionT<LHS, RHS, OP> const & proxy)
799  {
800  // set OP:
801  array_[current_index].op.type_family = operation_node_type_family(result_of::op_type_info<OP>::family);
802  array_[current_index].op.type = operation_node_type(result_of::op_type_info<OP>::id);
803 
804  // set LHS and RHS:
805  if (array_[current_index].op.type_family == OPERATION_UNARY_TYPE_FAMILY)
806  {
807  // unary expression: set rhs to invalid:
808  array_[current_index].rhs.type_family = INVALID_TYPE_FAMILY;
809  array_[current_index].rhs.subtype = INVALID_SUBTYPE;
810  array_[current_index].rhs.numeric_type = INVALID_NUMERIC_TYPE;
811  return add_lhs(current_index, next_free, proxy.lhs());
812  }
813 
814  return add_rhs(current_index, add_lhs(current_index, next_free, proxy.lhs()), proxy.rhs());
815  }
816 
817  container_type array_;
818 };
819 
820 namespace detail
821 {
823  inline void execute_composite(statement const & /* s */, statement_node const & /* root_node */);
824 }
825 
826 } // namespace scheduler
827 } // namespace viennacl
828 
829 #endif
830 
Simple enable-if variant that uses the SFINAE pattern.
Definition: enable_if.hpp:30
static void assign_element(lhs_rhs_element &elem, unsigned short const &t)
Definition: forwards.h:538
viennacl::implicit_vector_base< float > * implicit_vector_float
Definition: forwards.h:397
viennacl::scalar< float > * scalar_float
Definition: forwards.h:373
viennacl::vector_base< unsigned short > * vector_ushort
Definition: forwards.h:380
viennacl::implicit_vector_base< int > * implicit_vector_int
Definition: forwards.h:393
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_vector_base< char > const &t)
Definition: forwards.h:569
static void assign_element(lhs_rhs_element &elem, viennacl::scalar< float > const &t)
Definition: forwards.h:554
viennacl::vector_base< unsigned int > * vector_uint
Definition: forwards.h:382
viennacl::implicit_vector_base< unsigned char > * implicit_vector_uchar
Definition: forwards.h:390
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_vector_base< unsigned char > const &t)
Definition: forwards.h:570
viennacl::matrix_base< short > * matrix_short
Definition: forwards.h:403
viennacl::vector_base< short > * vector_short
Definition: forwards.h:379
viennacl::scalar< short > * scalar_short
Definition: forwards.h:367
static void assign_element(lhs_rhs_element &elem, viennacl::matrix_base< short > const &t)
Definition: forwards.h:584
statement(LHS &lhs, OP const &, RHS const &rhs)
Generate the runtime statement from an expression template.
Definition: forwards.h:515
viennacl::matrix_base< char > * matrix_char
Definition: forwards.h:401
viennacl::implicit_matrix_base< unsigned long > * implicit_matrix_ulong
Definition: forwards.h:419
static void assign_element(lhs_rhs_element &elem, char const &t)
Definition: forwards.h:535
static void assign_element(lhs_rhs_element &elem, double const &t)
Definition: forwards.h:544
static void assign_element(lhs_rhs_element &elem, viennacl::hyb_matrix< float > const &m)
Definition: forwards.h:613
static void assign_element(lhs_rhs_element &elem, viennacl::matrix_base< unsigned char > const &t)
Definition: forwards.h:583
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_matrix_base< unsigned long > const &t)
Definition: forwards.h:600
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_matrix_base< short > const &t)
Definition: forwards.h:595
viennacl::vector_base< int > * vector_int
Definition: forwards.h:381
statement_node_subtype subtype
Definition: forwards.h:340
Expression template class for representing a tree of expressions which ultimately result in a matrix...
Definition: forwards.h:341
static void assign_element(lhs_rhs_element &elem, unsigned char const &t)
Definition: forwards.h:536
static void assign_element(lhs_rhs_element &elem, viennacl::vector_base< short > const &t)
Definition: forwards.h:560
viennacl::vcl_size_t size_type
Definition: forwards.h:506
T::ERROR_UNKNOWN_OP_TYPE error_type
Definition: forwards.h:158
viennacl::coordinate_matrix< double > * coordinate_matrix_double
Definition: forwards.h:443
static void assign_element(lhs_rhs_element &elem, viennacl::matrix_base< long > const &t)
Definition: forwards.h:588
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::implicit_vector_base< long > * implicit_vector_long
Definition: forwards.h:395
statement_node_type_family type_family
Definition: forwards.h:339
static void assign_element(lhs_rhs_element &elem, viennacl::scalar< unsigned int > const &t)
Definition: forwards.h:551
viennacl::implicit_matrix_base< double > * implicit_matrix_double
Definition: forwards.h:421
static void assign_element(lhs_rhs_element &elem, viennacl::matrix_base< unsigned short > const &t)
Definition: forwards.h:585
static void assign_element(lhs_rhs_element &elem, viennacl::vector_base< unsigned short > const &t)
Definition: forwards.h:561
static void assign_element(lhs_rhs_element &elem, viennacl::vector_base< double > const &t)
Definition: forwards.h:567
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_matrix_base< long > const &t)
Definition: forwards.h:599
A class representing the 'data' for the LHS or RHS operand of the respective node.
Definition: forwards.h:337
viennacl::matrix_base< unsigned char > * matrix_uchar
Definition: forwards.h:402
container_type const & array() const
Definition: forwards.h:528
viennacl::scalar< unsigned int > * scalar_uint
Definition: forwards.h:370
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_matrix_base< char > const &t)
Definition: forwards.h:593
viennacl::scalar< long > * scalar_long
Definition: forwards.h:371
statement_node_numeric_type
Encodes the type of a node in the statement tree.
Definition: forwards.h:286
static void assign_element(lhs_rhs_element &elem, float const &t)
Definition: forwards.h:543
A proxy for scalar expressions (e.g. from inner vector products)
Definition: forwards.h:230
An expression template class that represents a binary operation that yields a vector.
Definition: forwards.h:239
static viennacl::enable_if< viennacl::is_primitive_type< T >::value, vcl_size_t >::type add_element(vcl_size_t next_free, lhs_rhs_element &elem, T const &t)
Definition: forwards.h:620
static void assign_element(lhs_rhs_element &elem, viennacl::ell_matrix< float > const &m)
Definition: forwards.h:610
operation_node_type_family type_family
Definition: forwards.h:473
Struct for holding the type family as well as the type of an operation (could be addition, subtraction, norm, etc.)
Definition: forwards.h:471
static void assign_element(lhs_rhs_element &elem, viennacl::vector_base< char > const &t)
Definition: forwards.h:558
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_vector_base< unsigned int > const &t)
Definition: forwards.h:574
static vcl_size_t add_element(vcl_size_t next_free, lhs_rhs_element &elem, viennacl::matrix_base< T > const &t)
Definition: forwards.h:669
viennacl::matrix_base< double > * matrix_double
Definition: forwards.h:410
viennacl::hyb_matrix< double > * hyb_matrix_double
Definition: forwards.h:465
viennacl::implicit_matrix_base< unsigned int > * implicit_matrix_uint
Definition: forwards.h:417
viennacl::scalar< unsigned long > * scalar_ulong
Definition: forwards.h:372
viennacl::implicit_vector_base< unsigned int > * implicit_vector_uint
Definition: forwards.h:394
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_matrix_base< int > const &t)
Definition: forwards.h:597
static void assign_element(lhs_rhs_element &elem, viennacl::compressed_matrix< float > const &m)
Definition: forwards.h:604
statement_node_subtype
Encodes the type of a node in the statement tree.
Definition: forwards.h:264
std::vector< value_type > container_type
Definition: forwards.h:507
viennacl::matrix_base< long > * matrix_long
Definition: forwards.h:407
viennacl::matrix_base< unsigned short > * matrix_ushort
Definition: forwards.h:404
static vcl_size_t add_element(vcl_size_t next_free, lhs_rhs_element &elem, viennacl::ell_matrix< T > const &t)
Definition: forwards.h:717
viennacl::implicit_matrix_base< unsigned short > * implicit_matrix_ushort
Definition: forwards.h:415
viennacl::compressed_matrix< float > * compressed_matrix_float
Definition: forwards.h:431
static void assign_element(lhs_rhs_element &elem, viennacl::scalar< int > const &t)
Definition: forwards.h:550
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_matrix_base< float > const &t)
Definition: forwards.h:601
static void assign_element(lhs_rhs_element &elem, viennacl::scalar< double > const &t)
Definition: forwards.h:555
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_vector_base< unsigned long > const &t)
Definition: forwards.h:576
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_matrix_base< unsigned short > const &t)
Definition: forwards.h:596
static void assign_element(lhs_rhs_element &elem, viennacl::coordinate_matrix< float > const &m)
Definition: forwards.h:607
viennacl::implicit_matrix_base< unsigned char > * implicit_matrix_uchar
Definition: forwards.h:413
static vcl_size_t add_element(vcl_size_t next_free, lhs_rhs_element &elem, viennacl::implicit_vector_base< T > const &t)
Definition: forwards.h:657
statement_node_numeric_type numeric_type
Definition: forwards.h:341
viennacl::vector_base< unsigned long > * vector_ulong
Definition: forwards.h:384
static void assign_element(lhs_rhs_element &elem, viennacl::matrix_base< float > const &t)
Definition: forwards.h:590
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_vector_base< double > const &t)
Definition: forwards.h:578
viennacl::vector_base< float > * vector_float
Definition: forwards.h:385
static vcl_size_t add_element(vcl_size_t next_free, lhs_rhs_element &elem, viennacl::hyb_matrix< T > const &t)
Definition: forwards.h:729
static void assign_element(lhs_rhs_element &elem, viennacl::vector_base< unsigned int > const &t)
Definition: forwards.h:563
Metafunction for querying type informations.
Definition: forwards.h:156
viennacl::matrix_base< float > * matrix_float
Definition: forwards.h:409
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_vector_base< float > const &t)
Definition: forwards.h:577
viennacl::implicit_vector_base< char > * implicit_vector_char
Definition: forwards.h:389
viennacl::implicit_vector_base< unsigned long > * implicit_vector_ulong
Definition: forwards.h:396
static void assign_element(lhs_rhs_element &elem, viennacl::ell_matrix< double > const &m)
Definition: forwards.h:611
std::size_t vcl_size_t
Definition: forwards.h:75
viennacl::vector_base< double > * vector_double
Definition: forwards.h:386
viennacl::compressed_matrix< double > * compressed_matrix_double
Definition: forwards.h:432
viennacl::ell_matrix< double > * ell_matrix_double
Definition: forwards.h:454
viennacl::matrix_base< unsigned long > * matrix_ulong
Definition: forwards.h:408
viennacl::hyb_matrix< float > * hyb_matrix_float
Definition: forwards.h:464
viennacl::scalar< double > * scalar_double
Definition: forwards.h:374
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_matrix_base< unsigned int > const &t)
Definition: forwards.h:598
viennacl::scalar< unsigned short > * scalar_ushort
Definition: forwards.h:368
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:42
static void assign_element(lhs_rhs_element &elem, viennacl::scalar< unsigned char > const &t)
Definition: forwards.h:547
operation_node_type
Enumeration for identifying the possible operations.
Definition: forwards.h:68
static void assign_element(lhs_rhs_element &elem, viennacl::matrix_base< double > const &t)
Definition: forwards.h:591
viennacl::vector_base< char > * vector_char
Definition: forwards.h:377
viennacl::implicit_vector_base< short > * implicit_vector_short
Definition: forwards.h:391
statement(container_type const &custom_array)
Definition: forwards.h:509
All the predicates used within ViennaCL. Checks for expressions to be vectors, etc.
static void assign_element(lhs_rhs_element &elem, viennacl::scalar< unsigned long > const &t)
Definition: forwards.h:553
static void assign_element(lhs_rhs_element &elem, viennacl::scalar< long > const &t)
Definition: forwards.h:552
Helper metafunction for obtaining the runtime type ID for a numerical type.
Definition: forwards.h:310
viennacl::scalar< unsigned char > * scalar_uchar
Definition: forwards.h:366
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_vector_base< short > const &t)
Definition: forwards.h:571
static void assign_element(lhs_rhs_element &elem, int const &t)
Definition: forwards.h:539
static vcl_size_t add_element(vcl_size_t next_free, lhs_rhs_element &elem, viennacl::vector_base< T > const &t)
Definition: forwards.h:645
static void assign_element(lhs_rhs_element &elem, viennacl::coordinate_matrix< double > const &m)
Definition: forwards.h:608
static void assign_element(lhs_rhs_element &elem, long const &t)
Definition: forwards.h:541
static void assign_element(lhs_rhs_element &elem, viennacl::vector_base< int > const &t)
Definition: forwards.h:562
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_vector_base< unsigned short > const &t)
Definition: forwards.h:572
static void assign_element(lhs_rhs_element &elem, viennacl::scalar< unsigned short > const &t)
Definition: forwards.h:549
viennacl::vector_base< unsigned char > * vector_uchar
Definition: forwards.h:378
scheduler::lhs_rhs_element & lhs_rhs_element(scheduler::statement const &st, vcl_size_t idx, leaf_t leaf)
Definition: utils.hpp:525
static void assign_element(lhs_rhs_element &elem, viennacl::matrix_base< unsigned long > const &t)
Definition: forwards.h:589
viennacl::implicit_matrix_base< float > * implicit_matrix_float
Definition: forwards.h:420
viennacl::ell_matrix< float > * ell_matrix_float
Definition: forwards.h:453
static vcl_size_t add_element(vcl_size_t next_free, lhs_rhs_element &elem, viennacl::compressed_matrix< T > const &t)
Definition: forwards.h:693
static void assign_element(lhs_rhs_element &elem, unsigned long const &t)
Definition: forwards.h:542
viennacl::scalar< int > * scalar_int
Definition: forwards.h:369
viennacl::implicit_vector_base< double > * implicit_vector_double
Definition: forwards.h:398
operation_node_type type
Definition: forwards.h:474
static void assign_element(lhs_rhs_element &elem, viennacl::vector_base< unsigned long > const &t)
Definition: forwards.h:565
static void assign_element(lhs_rhs_element &elem, viennacl::compressed_matrix< double > const &m)
Definition: forwards.h:605
static void assign_element(lhs_rhs_element &elem, unsigned int const &t)
Definition: forwards.h:540
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_matrix_base< unsigned char > const &t)
Definition: forwards.h:594
viennacl::implicit_vector_base< unsigned short > * implicit_vector_ushort
Definition: forwards.h:392
size_type root() const
Definition: forwards.h:530
The main class for representing a statement such as x = inner_prod(y,z); at runtime.
Definition: forwards.h:502
viennacl::scalar< char > * scalar_char
Definition: forwards.h:365
viennacl::implicit_matrix_base< short > * implicit_matrix_short
Definition: forwards.h:414
static vcl_size_t add_element(vcl_size_t next_free, lhs_rhs_element &elem, viennacl::implicit_matrix_base< T > const &t)
Definition: forwards.h:681
static void assign_element(lhs_rhs_element &elem, viennacl::matrix_base< unsigned int > const &t)
Definition: forwards.h:587
static void assign_element(lhs_rhs_element &elem, viennacl::matrix_base< int > const &t)
Definition: forwards.h:586
static vcl_size_t add_element(vcl_size_t next_free, lhs_rhs_element &elem, viennacl::scalar< T > const &t)
Definition: forwards.h:632
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_vector_base< long > const &t)
Definition: forwards.h:575
static void assign_element(lhs_rhs_element &elem, viennacl::vector_base< float > const &t)
Definition: forwards.h:566
static void assign_element(lhs_rhs_element &elem, viennacl::matrix_base< char > const &t)
Definition: forwards.h:582
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_matrix_base< double > const &t)
Definition: forwards.h:602
static void assign_element(lhs_rhs_element &elem, viennacl::implicit_vector_base< int > const &t)
Definition: forwards.h:573
viennacl::matrix_base< int > * matrix_int
Definition: forwards.h:405
viennacl::implicit_matrix_base< long > * implicit_matrix_long
Definition: forwards.h:418
static vcl_size_t add_element(vcl_size_t next_free, lhs_rhs_element &elem, viennacl::coordinate_matrix< T > const &t)
Definition: forwards.h:705
viennacl::vector_base< long > * vector_long
Definition: forwards.h:383
viennacl::coordinate_matrix< float > * coordinate_matrix_float
Definition: forwards.h:442
static void assign_element(lhs_rhs_element &elem, viennacl::hyb_matrix< double > const &m)
Definition: forwards.h:614
viennacl::implicit_matrix_base< char > * implicit_matrix_char
Definition: forwards.h:412
static void assign_element(lhs_rhs_element &elem, viennacl::scalar< char > const &t)
Definition: forwards.h:546
static void assign_element(lhs_rhs_element &elem, viennacl::scalar< short > const &t)
Definition: forwards.h:548
Main datastructure for an node in the statement tree.
Definition: forwards.h:478
Exception for the case the scheduler is unable to deal with the operation.
Definition: forwards.h:38
Simple enable-if variant that uses the SFINAE pattern.
static void assign_element(lhs_rhs_element &elem, short const &t)
Definition: forwards.h:537
statement_node_type_family
Groups the type of a node in the statement tree. Used for faster dispatching.
Definition: forwards.h:246
viennacl::matrix_base< unsigned int > * matrix_uint
Definition: forwards.h:406
operation_node_type_family
Optimization enum for grouping operations into unary or binary operations. Just for optimization of l...
Definition: forwards.h:53
viennacl::implicit_matrix_base< int > * implicit_matrix_int
Definition: forwards.h:416
static void assign_element(lhs_rhs_element &elem, viennacl::vector_base< long > const &t)
Definition: forwards.h:564
static void assign_element(lhs_rhs_element &elem, viennacl::vector_base< unsigned char > const &t)
Definition: forwards.h:559
A tag class representing element-wise casting operations on vectors and matrices. ...
Definition: forwards.h:126