ViennaCL - The Vienna Computing Library: viennacl/scheduler/execute_vector_dispatcher.hpp Source File

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
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-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
26 #include <assert.h>
27
28 #include "viennacl/forwards.h"
29 #include "viennacl/scheduler/forwards.h"
30 #include "viennacl/scheduler/execute_util.hpp"
31 #include "viennacl/linalg/vector_operations.hpp"
32
33 namespace viennacl
34 {
35 namespace scheduler
36 {
37 namespace detail
38 {
39
41 template<typename ScalarType1>
42 void av(lhs_rhs_element & vec1,
43 lhs_rhs_element const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
44 {
45 assert( vec1.type_family == VECTOR_TYPE_FAMILY && vec1.subtype == DENSE_VECTOR_TYPE
46 && vec2.type_family == VECTOR_TYPE_FAMILY && vec2.subtype == DENSE_VECTOR_TYPE
47 && bool("Arguments are not vector types!"));
48
49 switch (vec1.numeric_type)
50 {
51 case FLOAT_TYPE:
52 assert(vec2.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type"));
53 viennacl::linalg::av(*vec1.vector_float,
54 *vec2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha);
55 break;
56 case DOUBLE_TYPE:
57 assert(vec2.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type"));
58 viennacl::linalg::av(*vec1.vector_double,
59 *vec2.vector_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha);
60 break;
61 default:
62 throw statement_not_supported_exception("Invalid arguments in scheduler when calling av()");
63 }
64 }
65
67 template<typename ScalarType1, typename ScalarType2>
68 void avbv(lhs_rhs_element & vec1,
69 lhs_rhs_element const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
70 lhs_rhs_element const & vec3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
71 {
72 assert( vec1.type_family == VECTOR_TYPE_FAMILY && vec1.subtype == DENSE_VECTOR_TYPE
73 && vec2.type_family == VECTOR_TYPE_FAMILY && vec2.subtype == DENSE_VECTOR_TYPE
74 && vec3.type_family == VECTOR_TYPE_FAMILY && vec3.subtype == DENSE_VECTOR_TYPE
75 && bool("Arguments are not vector types!"));
76
77 switch (vec1.numeric_type)
78 {
79 case FLOAT_TYPE:
80 assert(vec2.numeric_type == FLOAT_TYPE && vec3.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type"));
81 viennacl::linalg::avbv(*vec1.vector_float,
82 *vec2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
83 *vec3.vector_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta);
84 break;
85 case DOUBLE_TYPE:
86 assert(vec2.numeric_type == DOUBLE_TYPE && vec3.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type"));
87 viennacl::linalg::avbv(*vec1.vector_double,
88 *vec2.vector_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
89 *vec3.vector_double, convert_to_double(beta), len_beta, reciprocal_beta, flip_sign_beta);
90 break;
91 default:
92 throw statement_not_supported_exception("Invalid arguments in scheduler when calling avbv()");
93 }
94 }
95
97 template<typename ScalarType1, typename ScalarType2>
98 void avbv_v(lhs_rhs_element & vec1,
99 lhs_rhs_element const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
100 lhs_rhs_element const & vec3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
101 {
102 assert( vec1.type_family == VECTOR_TYPE_FAMILY && vec1.subtype == DENSE_VECTOR_TYPE
103 && vec2.type_family == VECTOR_TYPE_FAMILY && vec2.subtype == DENSE_VECTOR_TYPE
104 && vec3.type_family == VECTOR_TYPE_FAMILY && vec3.subtype == DENSE_VECTOR_TYPE
105 && bool("Arguments are not vector types!"));
106
107 switch (vec1.numeric_type)
108 {
109 case FLOAT_TYPE:
110 assert(vec2.numeric_type == FLOAT_TYPE && vec3.numeric_type == FLOAT_TYPE && bool("Vectors do not have the same scalar type"));
111 viennacl::linalg::avbv_v(*vec1.vector_float,
112 *vec2.vector_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
113 *vec3.vector_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta);
114 break;
115 case DOUBLE_TYPE:
116 assert(vec2.numeric_type == DOUBLE_TYPE && vec3.numeric_type == DOUBLE_TYPE && bool("Vectors do not have the same scalar type"));
117 viennacl::linalg::avbv_v(*vec1.vector_double,
118 *vec2.vector_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
119 *vec3.vector_double, convert_to_double(beta), len_beta, reciprocal_beta, flip_sign_beta);
120 break;
121 default:
122 throw statement_not_supported_exception("Invalid arguments in scheduler when calling avbv_v()");
123 }
124 }
125
126
128 inline void norm_impl(lhs_rhs_element const & x,
129 lhs_rhs_element const & s,
130 operation_node_type op_type)
131 {
132 assert( x.type_family == VECTOR_TYPE_FAMILY && x.subtype == DENSE_VECTOR_TYPE && bool("Argument is not a dense vector type!"));
133 assert( s.type_family == SCALAR_TYPE_FAMILY && s.subtype == DEVICE_SCALAR_TYPE && bool("Argument is not a scalar type!"));
134
135 switch (x.numeric_type)
136 {
137 case FLOAT_TYPE:
138 assert(s.numeric_type == FLOAT_TYPE && bool("Vector and scalar do not have the same numeric type"));
139 if (op_type == OPERATION_UNARY_NORM_1_TYPE)
140 viennacl::linalg::norm_1_impl(*x.vector_float, *s.scalar_float);
141 else if (op_type == OPERATION_UNARY_NORM_2_TYPE)
142 viennacl::linalg::norm_2_impl(*x.vector_float, *s.scalar_float);
143 else if (op_type == OPERATION_UNARY_NORM_INF_TYPE)
144 viennacl::linalg::norm_inf_impl(*x.vector_float, *s.scalar_float);
145 else if (op_type == OPERATION_UNARY_MAX_TYPE)
146 viennacl::linalg::max_impl(*x.vector_float, *s.scalar_float);
147 else if (op_type == OPERATION_UNARY_MIN_TYPE)
148 viennacl::linalg::min_impl(*x.vector_float, *s.scalar_float);
149 else
150 throw statement_not_supported_exception("Invalid norm type in scheduler::detail::norm_impl()");
151 break;
152 case DOUBLE_TYPE:
153 if (op_type == OPERATION_UNARY_NORM_1_TYPE)
154 viennacl::linalg::norm_1_impl(*x.vector_double, *s.scalar_double);
155 else if (op_type == OPERATION_UNARY_NORM_2_TYPE)
156 viennacl::linalg::norm_2_impl(*x.vector_double, *s.scalar_double);
157 else if (op_type == OPERATION_UNARY_NORM_INF_TYPE)
158 viennacl::linalg::norm_inf_impl(*x.vector_double, *s.scalar_double);
159 else if (op_type == OPERATION_UNARY_MAX_TYPE)
160 viennacl::linalg::max_impl(*x.vector_double, *s.scalar_double);
161 else if (op_type == OPERATION_UNARY_MIN_TYPE)
162 viennacl::linalg::min_impl(*x.vector_double, *s.scalar_double);
163 else
164 throw statement_not_supported_exception("Invalid norm type in scheduler::detail::norm_impl()");
165 break;
166 default:
167 throw statement_not_supported_exception("Invalid numeric type in scheduler when calling norm_impl()");
168 }
169 }
170
172 inline void inner_prod_impl(lhs_rhs_element const & x,
173 lhs_rhs_element const & y,
174 lhs_rhs_element const & s)
175 {
176 assert( x.type_family == VECTOR_TYPE_FAMILY && x.subtype == DENSE_VECTOR_TYPE && bool("Argument is not a dense vector type!"));
177 assert( y.type_family == VECTOR_TYPE_FAMILY && y.subtype == DENSE_VECTOR_TYPE && bool("Argument is not a dense vector type!"));
178 assert( s.type_family == SCALAR_TYPE_FAMILY && s.subtype == DEVICE_SCALAR_TYPE && bool("Argument is not a scalar type!"));
179
180 switch (x.numeric_type)
181 {
182 case FLOAT_TYPE:
183 assert(y.numeric_type == FLOAT_TYPE && s.numeric_type == FLOAT_TYPE && bool("Vector and scalar do not have the same numeric type"));
184 viennacl::linalg::inner_prod_impl(*x.vector_float, *y.vector_float, *s.scalar_float);
185 break;
186 case DOUBLE_TYPE:
187 assert(y.numeric_type == DOUBLE_TYPE && s.numeric_type == DOUBLE_TYPE && bool("Vector and scalar do not have the same numeric type"));
188 viennacl::linalg::inner_prod_impl(*x.vector_double, *y.vector_double, *s.scalar_double);
189 break;
190 default:
191 throw statement_not_supported_exception("Invalid arguments in scheduler when calling av()");
192 }
193 }
194
195 } // namespace detail
196 } // namespace scheduler
197 } // namespace viennacl
198
199 #endif
200
viennacl::scheduler::OPERATION_UNARY_NORM_INF_TYPE
Definition: forwards.h:109
viennacl::scheduler::lhs_rhs_element::scalar_float
viennacl::scalar< float > * scalar_float
Definition: forwards.h:373
viennacl::scheduler::detail::inner_prod_impl
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:172
vector_operations.hpp
Implementations of vector operations.
viennacl::scheduler::DEVICE_SCALAR_TYPE
Definition: forwards.h:269
viennacl::scheduler::DENSE_VECTOR_TYPE
Definition: forwards.h:271
viennacl::scheduler::detail::norm_impl
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:128
viennacl::scheduler::DOUBLE_TYPE
Definition: forwards.h:300
viennacl::linalg::avbv_v
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:144
viennacl::scheduler::detail::convert_to_double
double convert_to_double(float d)
Definition: execute_util.hpp:89
viennacl::scheduler::lhs_rhs_element::subtype
statement_node_subtype subtype
Definition: forwards.h:340
viennacl::scheduler::SCALAR_TYPE_FAMILY
Definition: forwards.h:254
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::scheduler::lhs_rhs_element::type_family
statement_node_type_family type_family
Definition: forwards.h:339
viennacl::scheduler::lhs_rhs_element
A class representing the 'data' for the LHS or RHS operand of the respective node.
Definition: forwards.h:337
viennacl::scheduler::detail::avbv
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:68
viennacl::linalg::norm_2_impl
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:660
viennacl::scheduler::OPERATION_UNARY_NORM_2_TYPE
Definition: forwards.h:108
viennacl::linalg::max_impl
void max_impl(vector_base< T > const &vec, scalar< T > &result)
viennacl::linalg::inner_prod_impl
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:387
viennacl::scheduler::OPERATION_UNARY_MAX_TYPE
Definition: forwards.h:110
viennacl::scheduler::lhs_rhs_element::numeric_type
statement_node_numeric_type numeric_type
Definition: forwards.h:341
viennacl::scheduler::lhs_rhs_element::vector_float
viennacl::vector_base< float > * vector_float
Definition: forwards.h:385
viennacl::linalg::norm_inf_impl
void norm_inf_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:752
viennacl::linalg::norm_1_impl
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:566
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
viennacl::linalg::min_impl
void min_impl(vector_base< T > const &vec, scalar< T > &result)
viennacl::scheduler::lhs_rhs_element::vector_double
viennacl::vector_base< double > * vector_double
Definition: forwards.h:386
viennacl::scheduler::detail::avbv_v
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:98
viennacl::scheduler::lhs_rhs_element::scalar_double
viennacl::scalar< double > * scalar_double
Definition: forwards.h:374
forwards.h
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
viennacl::linalg::avbv
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:107
viennacl::scheduler::operation_node_type
operation_node_type
Enumeration for identifying the possible operations.
Definition: forwards.h:68
viennacl::scheduler::detail::av
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:42
viennacl::scheduler::OPERATION_UNARY_MIN_TYPE
Definition: forwards.h:111
viennacl::linalg::av
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:78
viennacl::scheduler::detail::convert_to_float
float convert_to_float(float f)
Definition: execute_util.hpp:76
viennacl::scheduler::FLOAT_TYPE
Definition: forwards.h:299
viennacl::scheduler::VECTOR_TYPE_FAMILY
Definition: forwards.h:257
execute_util.hpp
Provides various utilities for implementing the execution of statements.
viennacl::scheduler::statement_not_supported_exception
Exception for the case the scheduler is unable to deal with the operation.
Definition: forwards.h:38
viennacl::scheduler::OPERATION_UNARY_NORM_1_TYPE
Definition: forwards.h:107