ViennaCL - The Vienna Computing Library  1.5.1
execute_vector_dispatcher.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_SCHEDULER_EXECUTE_VECTOR_DISPATCHER_HPP
2 #define VIENNACL_SCHEDULER_EXECUTE_VECTOR_DISPATCHER_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 <assert.h>
27 
28 #include "viennacl/forwards.h"
32 
33 namespace viennacl
34 {
35  namespace scheduler
36  {
37  namespace detail
38  {
40  template <typename ScalarType1>
41  void av(lhs_rhs_element & vec1,
42  lhs_rhs_element const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
43  {
44  assert( vec1.type_family == VECTOR_TYPE_FAMILY && vec1.subtype == DENSE_VECTOR_TYPE
46  && bool("Arguments are not vector types!"));
47 
48  switch (vec1.numeric_type)
49  {
50  case FLOAT_TYPE:
51  assert(vec2.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type"));
53  *vec2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha);
54  break;
55  case DOUBLE_TYPE:
56  assert(vec2.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type"));
58  *vec2.vector_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha);
59  break;
60  default:
61  throw statement_not_supported_exception("Invalid arguments in scheduler when calling av()");
62  }
63  }
64 
66  template <typename ScalarType1, typename ScalarType2>
67  void avbv(lhs_rhs_element & vec1,
68  lhs_rhs_element const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
69  lhs_rhs_element const & vec3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
70  {
71  assert( vec1.type_family == VECTOR_TYPE_FAMILY && vec1.subtype == DENSE_VECTOR_TYPE
74  && bool("Arguments are not vector types!"));
75 
76  switch (vec1.numeric_type)
77  {
78  case FLOAT_TYPE:
79  assert(vec2.numeric_type == FLOAT_TYPE && vec3.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type"));
81  *vec2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
82  *vec3.vector_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta);
83  break;
84  case DOUBLE_TYPE:
85  assert(vec2.numeric_type == DOUBLE_TYPE && vec3.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type"));
87  *vec2.vector_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
88  *vec3.vector_double, convert_to_double(beta), len_beta, reciprocal_beta, flip_sign_beta);
89  break;
90  default:
91  throw statement_not_supported_exception("Invalid arguments in scheduler when calling avbv()");
92  }
93  }
94 
96  template <typename ScalarType1, typename ScalarType2>
97  void avbv_v(lhs_rhs_element & vec1,
98  lhs_rhs_element const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
99  lhs_rhs_element const & vec3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
100  {
101  assert( vec1.type_family == VECTOR_TYPE_FAMILY && vec1.subtype == DENSE_VECTOR_TYPE
104  && bool("Arguments are not vector types!"));
105 
106  switch (vec1.numeric_type)
107  {
108  case FLOAT_TYPE:
109  assert(vec2.numeric_type == FLOAT_TYPE && vec3.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type"));
111  *vec2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
112  *vec3.vector_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta);
113  break;
114  case DOUBLE_TYPE:
115  assert(vec2.numeric_type == DOUBLE_TYPE && vec3.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type"));
117  *vec2.vector_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
118  *vec3.vector_double, convert_to_double(beta), len_beta, reciprocal_beta, flip_sign_beta);
119  break;
120  default:
121  throw statement_not_supported_exception("Invalid arguments in scheduler when calling avbv_v()");
122  }
123  }
124 
125 
127  inline void norm_impl(lhs_rhs_element const & x,
128  lhs_rhs_element const & s,
129  operation_node_type op_type)
130  {
131  assert( x.type_family == VECTOR_TYPE_FAMILY && x.subtype == DENSE_VECTOR_TYPE && bool("Argument is not a dense vector type!"));
132  assert( s.type_family == SCALAR_TYPE_FAMILY && s.subtype == DEVICE_SCALAR_TYPE && bool("Argument is not a scalar type!"));
133 
134  switch (x.numeric_type)
135  {
136  case FLOAT_TYPE:
137  assert(s.numeric_type == FLOAT_TYPE && bool("Vector and scalar do not have the same numeric type"));
138  if (op_type == OPERATION_UNARY_NORM_1_TYPE)
140  else if (op_type == OPERATION_UNARY_NORM_2_TYPE)
142  else if (op_type == OPERATION_UNARY_NORM_INF_TYPE)
144  else
145  throw statement_not_supported_exception("Invalid norm type in scheduler::detail::norm_impl()");
146  break;
147  case DOUBLE_TYPE:
148  if (op_type == OPERATION_UNARY_NORM_1_TYPE)
150  else if (op_type == OPERATION_UNARY_NORM_2_TYPE)
152  else if (op_type == OPERATION_UNARY_NORM_INF_TYPE)
154  else
155  throw statement_not_supported_exception("Invalid norm type in scheduler::detail::norm_impl()");
156  break;
157  default:
158  throw statement_not_supported_exception("Invalid numeric type in scheduler when calling norm_impl()");
159  }
160  }
161 
163  inline void inner_prod_impl(lhs_rhs_element const & x,
164  lhs_rhs_element const & y,
165  lhs_rhs_element const & s)
166  {
167  assert( x.type_family == VECTOR_TYPE_FAMILY && x.subtype == DENSE_VECTOR_TYPE && bool("Argument is not a dense vector type!"));
168  assert( y.type_family == VECTOR_TYPE_FAMILY && y.subtype == DENSE_VECTOR_TYPE && bool("Argument is not a dense vector type!"));
169  assert( s.type_family == SCALAR_TYPE_FAMILY && s.subtype == DEVICE_SCALAR_TYPE && bool("Argument is not a scalar type!"));
170 
171  switch (x.numeric_type)
172  {
173  case FLOAT_TYPE:
174  assert(y.numeric_type == FLOAT_TYPE && s.numeric_type == FLOAT_TYPE && bool("Vector and scalar do not have the same numeric type"));
176  break;
177  case DOUBLE_TYPE:
178  assert(y.numeric_type == DOUBLE_TYPE && s.numeric_type == DOUBLE_TYPE && bool("Vector and scalar do not have the same numeric type"));
180  break;
181  default:
182  throw statement_not_supported_exception("Invalid arguments in scheduler when calling av()");
183  }
184  }
185 
186  } // namespace detail
187  } // namespace scheduler
188 } // namespace viennacl
189 
190 #endif
191 
statement_node_subtype subtype
Definition: forwards.h:270
std::size_t vcl_size_t
Definition: forwards.h:58
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
Implementations of vector operations.
void inner_prod_impl(vector_base< T > const &vec1, vector_base< T > const &vec2, scalar< T > &result)
Computes the inner product of two vectors - dispatcher interface.
Definition: vector_operations.hpp:351
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
Definition: forwards.h:217
Definition: forwards.h:185
void avbv_v(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< T > const &vec3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:115
double convert_to_double(float d)
Definition: execute_util.hpp:88
viennacl::scalar< float > * scalar_float
Definition: forwards.h:303
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
void avbv(lhs_rhs_element &vec1, lhs_rhs_element const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, lhs_rhs_element const &vec3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Wrapper for viennacl::linalg::avbv(), taking care of the argument unwrapping.
Definition: execute_vector_dispatcher.hpp:67
viennacl::scalar< double > * scalar_double
Definition: forwards.h:304
Definition: forwards.h:170
viennacl::vector_base< float > * vector_float
Definition: forwards.h:315
statement_node_numeric_type numeric_type
Definition: forwards.h:271
void norm_1_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the l^1-norm of a vector - dispatcher interface.
Definition: vector_operations.hpp:530
viennacl::vector_base< double > * vector_double
Definition: forwards.h:316
Definition: forwards.h:173
void avbv_v(lhs_rhs_element &vec1, lhs_rhs_element const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, lhs_rhs_element const &vec3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Wrapper for viennacl::linalg::avbv_v(), taking care of the argument unwrapping.
Definition: execute_vector_dispatcher.hpp:97
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
operation_node_type
Enumeration for identifying the possible operations.
Definition: forwards.h:61
void avbv(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< T > const &vec3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:78
void av(lhs_rhs_element &vec1, lhs_rhs_element const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Wrapper for viennacl::linalg::av(), taking care of the argument unwrapping.
Definition: execute_vector_dispatcher.hpp:41
void av(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: vector_operations.hpp:49
float convert_to_float(float f)
Definition: execute_util.hpp:75
void norm_2_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the l^2-norm of a vector - dispatcher interface.
Definition: vector_operations.hpp:624
statement_node_type_family type_family
Definition: forwards.h:269
Definition: forwards.h:187
Definition: forwards.h:216
Provides various utilities for implementing the execution of statements.
void norm_inf_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:716
Exception for the case the scheduler is unable to deal with the operation.
Definition: forwards.h:36