ViennaCL - The Vienna Computing Library: libviennacl/src/blas1_host.cpp 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
blas1_host.cpp
Go to the documentation of this file.
1 /* =========================================================================
2 Copyright (c) 2010-2014, Institute for Microelectronics,
3 Institute for Analysis and Scientific Computing,
4 TU Wien.
5 Portions of this software are copyright by UChicago Argonne, LLC.
6
7 -----------------
8 ViennaCL - The Vienna Computing Library
9 -----------------
10
11 Project Head: Karl Rupp rupp@iue.tuwien.ac.at
12
13 (A list of authors and contributors can be found in the PDF manual)
14
15 License: MIT (X11), see file LICENSE in the base directory
16 ============================================================================= */
17
18 // include necessary system headers
19 #include <iostream>
20
21 #include "viennacl.hpp"
22 #include "viennacl_private.hpp"
23
24 //include basic scalar and vector types of ViennaCL
25 #include "viennacl/scalar.hpp"
26 #include "viennacl/vector.hpp"
27
28 //include the generic inner product functions of ViennaCL
29 #include "viennacl/linalg/inner_prod.hpp"
30
31 //include the generic norm functions of ViennaCL
32 #include "viennacl/linalg/norm_1.hpp"
33 #include "viennacl/linalg/norm_2.hpp"
34 #include "viennacl/linalg/norm_inf.hpp"
35
36
37 // IxAMAX
38
39 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostiSamax(ViennaCLBackend /*backend*/, ViennaCLInt n,
40 ViennaCLInt *index,
41 float *x, ViennaCLInt offx, int incx)
42 {
43 typedef viennacl::vector_base<float>::size_type size_type;
44 typedef viennacl::vector_base<float>::size_type difference_type;
45 viennacl::vector_base<float> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
46
47 *index = static_cast<ViennaCLInt>(viennacl::linalg::index_norm_inf(v1));
48 return ViennaCLSuccess;
49 }
50
51 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostiDamax(ViennaCLBackend /*backend*/, ViennaCLInt n,
52 ViennaCLInt *index,
53 double *x, ViennaCLInt offx, int incx)
54 {
55 typedef viennacl::vector_base<double>::size_type size_type;
56 typedef viennacl::vector_base<double>::size_type difference_type;
57 viennacl::vector_base<double> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
58
59 *index = static_cast<ViennaCLInt>(viennacl::linalg::index_norm_inf(v1));
60 return ViennaCLSuccess;
61 }
62
63
64
65 // xASUM
66
67 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSasum(ViennaCLBackend /*backend*/, ViennaCLInt n,
68 float *alpha,
69 float *x, ViennaCLInt offx, int incx)
70 {
71 typedef viennacl::vector_base<float>::size_type size_type;
72 typedef viennacl::vector_base<float>::size_type difference_type;
73 viennacl::vector_base<float> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
74
75 *alpha = viennacl::linalg::norm_1(v1);
76 return ViennaCLSuccess;
77 }
78
79 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDasum(ViennaCLBackend /*backend*/, ViennaCLInt n,
80 double *alpha,
81 double *x, ViennaCLInt offx, int incx)
82 {
83 typedef viennacl::vector_base<double>::size_type size_type;
84 typedef viennacl::vector_base<double>::size_type difference_type;
85 viennacl::vector_base<double> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
86
87 *alpha = viennacl::linalg::norm_1(v1);
88 return ViennaCLSuccess;
89 }
90
91
92
93 // xAXPY
94
95 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSaxpy(ViennaCLBackend /*backend*/, ViennaCLInt n,
96 float alpha,
97 float *x, ViennaCLInt offx, int incx,
98 float *y, ViennaCLInt offy, int incy)
99 {
100 typedef viennacl::vector_base<float>::size_type size_type;
101 typedef viennacl::vector_base<float>::size_type difference_type;
102 viennacl::vector_base<float> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
103 viennacl::vector_base<float> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
104
105 v2 += alpha * v1;
106 return ViennaCLSuccess;
107 }
108
109 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDaxpy(ViennaCLBackend /*backend*/, ViennaCLInt n,
110 double alpha,
111 double *x, ViennaCLInt offx, int incx,
112 double *y, ViennaCLInt offy, int incy)
113 {
114 typedef viennacl::vector_base<double>::size_type size_type;
115 typedef viennacl::vector_base<double>::size_type difference_type;
116 viennacl::vector_base<double> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
117 viennacl::vector_base<double> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
118
119 v2 += alpha * v1;
120 return ViennaCLSuccess;
121 }
122
123
124 // xCOPY
125
126 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostScopy(ViennaCLBackend /*backend*/, ViennaCLInt n,
127 float *x, ViennaCLInt offx, int incx,
128 float *y, ViennaCLInt offy, int incy)
129 {
130 typedef viennacl::vector_base<float>::size_type size_type;
131 typedef viennacl::vector_base<float>::size_type difference_type;
132 viennacl::vector_base<float> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
133 viennacl::vector_base<float> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
134
135 v2 = v1;
136 return ViennaCLSuccess;
137 }
138
139 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDcopy(ViennaCLBackend /*backend*/, ViennaCLInt n,
140 double *x, ViennaCLInt offx, int incx,
141 double *y, ViennaCLInt offy, int incy)
142 {
143 typedef viennacl::vector_base<double>::size_type size_type;
144 typedef viennacl::vector_base<double>::size_type difference_type;
145 viennacl::vector_base<double> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
146 viennacl::vector_base<double> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
147
148 v2 = v1;
149 return ViennaCLSuccess;
150 }
151
152 // xAXPY
153
154 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSdot(ViennaCLBackend /*backend*/, ViennaCLInt n,
155 float *alpha,
156 float *x, ViennaCLInt offx, int incx,
157 float *y, ViennaCLInt offy, int incy)
158 {
159 typedef viennacl::vector_base<float>::size_type size_type;
160 typedef viennacl::vector_base<float>::size_type difference_type;
161 viennacl::vector_base<float> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
162 viennacl::vector_base<float> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
163
164 *alpha = viennacl::linalg::inner_prod(v1, v2);
165 return ViennaCLSuccess;
166 }
167
168 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDdot(ViennaCLBackend /*backend*/, ViennaCLInt n,
169 double *alpha,
170 double *x, ViennaCLInt offx, int incx,
171 double *y, ViennaCLInt offy, int incy)
172 {
173 typedef viennacl::vector_base<double>::size_type size_type;
174 typedef viennacl::vector_base<double>::size_type difference_type;
175 viennacl::vector_base<double> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
176 viennacl::vector_base<double> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
177
178 *alpha = viennacl::linalg::inner_prod(v1, v2);
179 return ViennaCLSuccess;
180 }
181
182 // xNRM2
183
184 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSnrm2(ViennaCLBackend /*backend*/, ViennaCLInt n,
185 float *alpha,
186 float *x, ViennaCLInt offx, int incx)
187 {
188 typedef viennacl::vector_base<float>::size_type size_type;
189 typedef viennacl::vector_base<float>::size_type difference_type;
190 viennacl::vector_base<float> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
191
192 *alpha = viennacl::linalg::norm_2(v1);
193 return ViennaCLSuccess;
194 }
195
196 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDnrm2(ViennaCLBackend /*backend*/, ViennaCLInt n,
197 double *alpha,
198 double *x, ViennaCLInt offx, int incx)
199 {
200 typedef viennacl::vector_base<double>::size_type size_type;
201 typedef viennacl::vector_base<double>::size_type difference_type;
202 viennacl::vector_base<double> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
203
204 *alpha = viennacl::linalg::norm_2(v1);
205 return ViennaCLSuccess;
206 }
207
208
209 // xROT
210
211 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSrot(ViennaCLBackend /*backend*/, ViennaCLInt n,
212 float *x, ViennaCLInt offx, int incx,
213 float *y, ViennaCLInt offy, int incy,
214 float c, float s)
215 {
216 typedef viennacl::vector_base<float>::size_type size_type;
217 typedef viennacl::vector_base<float>::size_type difference_type;
218 viennacl::vector_base<float> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
219 viennacl::vector_base<float> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
220
221 viennacl::linalg::plane_rotation(v1, v2, c, s);
222 return ViennaCLSuccess;
223 }
224
225 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDrot(ViennaCLBackend /*backend*/, ViennaCLInt n,
226 double *x, ViennaCLInt offx, int incx,
227 double *y, ViennaCLInt offy, int incy,
228 double c, double s)
229 {
230 typedef viennacl::vector_base<double>::size_type size_type;
231 typedef viennacl::vector_base<double>::size_type difference_type;
232 viennacl::vector_base<double> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
233 viennacl::vector_base<double> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
234
235 viennacl::linalg::plane_rotation(v1, v2, c, s);
236 return ViennaCLSuccess;
237 }
238
239
240
241 // xSCAL
242
243 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSscal(ViennaCLBackend /*backend*/, ViennaCLInt n,
244 float alpha,
245 float *x, ViennaCLInt offx, int incx)
246 {
247 typedef viennacl::vector_base<float>::size_type size_type;
248 typedef viennacl::vector_base<float>::size_type difference_type;
249 viennacl::vector_base<float> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
250
251 v1 *= alpha;
252 return ViennaCLSuccess;
253 }
254
255 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDscal(ViennaCLBackend /*backend*/, ViennaCLInt n,
256 double alpha,
257 double *x, ViennaCLInt offx, int incx)
258 {
259 typedef viennacl::vector_base<double>::size_type size_type;
260 typedef viennacl::vector_base<double>::size_type difference_type;
261 viennacl::vector_base<double> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
262
263 v1 *= alpha;
264 return ViennaCLSuccess;
265 }
266
267 // xSWAP
268
269 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSswap(ViennaCLBackend /*backend*/, ViennaCLInt n,
270 float *x, ViennaCLInt offx, int incx,
271 float *y, ViennaCLInt offy, int incy)
272 {
273 typedef viennacl::vector_base<float>::size_type size_type;
274 typedef viennacl::vector_base<float>::size_type difference_type;
275 viennacl::vector_base<float> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
276 viennacl::vector_base<float> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
277
278 viennacl::swap(v1, v2);
279 return ViennaCLSuccess;
280 }
281
282 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDswap(ViennaCLBackend /*backend*/, ViennaCLInt n,
283 double *x, ViennaCLInt offx, int incx,
284 double *y, ViennaCLInt offy, int incy)
285 {
286 typedef viennacl::vector_base<double>::size_type size_type;
287 typedef viennacl::vector_base<double>::size_type difference_type;
288 viennacl::vector_base<double> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
289 viennacl::vector_base<double> v2(y, viennacl::MAIN_MEMORY, size_type(n), size_type(offy), difference_type(incy));
290
291 viennacl::swap(v1, v2);
292 return ViennaCLSuccess;
293 }
ViennaCLHostDnrm2
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDnrm2(ViennaCLBackend, ViennaCLInt n, double *alpha, double *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:196
viennacl::linalg::norm_2
T norm_2(std::vector< T, A > const &v1)
Definition: norm_2.hpp:96
viennacl::linalg::index_norm_inf
vcl_size_t index_norm_inf(vector_base< T > const &vec)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
Definition: vector_operations.hpp:845
norm_2.hpp
Generic interface for the l^2-norm. See viennacl/linalg/vector_operations.hpp for implementations...
ViennaCLBackend_impl
Generic backend for CUDA, OpenCL, host-based stuff.
Definition: viennacl_private.hpp:54
ViennaCLHostSasum
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSasum(ViennaCLBackend, ViennaCLInt n, float *alpha, float *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:67
ViennaCLHostSrot
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSrot(ViennaCLBackend, ViennaCLInt n, float *x, ViennaCLInt offx, int incx, float *y, ViennaCLInt offy, int incy, float c, float s)
Definition: blas1_host.cpp:211
ViennaCLHostScopy
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostScopy(ViennaCLBackend, ViennaCLInt n, float *x, ViennaCLInt offx, int incx, float *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:126
viennacl::linalg::plane_rotation
void plane_rotation(vector_base< T > &vec1, vector_base< T > &vec2, T alpha, T beta)
Computes a plane rotation of two vectors.
Definition: vector_operations.hpp:1152
ViennaCLHostSaxpy
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSaxpy(ViennaCLBackend, ViennaCLInt n, float alpha, float *x, ViennaCLInt offx, int incx, float *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:95
ViennaCLHostSnrm2
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSnrm2(ViennaCLBackend, ViennaCLInt n, float *alpha, float *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:184
ViennaCLHostiDamax
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostiDamax(ViennaCLBackend, ViennaCLInt n, ViennaCLInt *index, double *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:51
viennacl::linalg::inner_prod
viennacl::enable_if< viennacl::is_stl< typename viennacl::traits::tag_of< VectorT1 >::type >::value, typename VectorT1::value_type >::type inner_prod(VectorT1 const &v1, VectorT2 const &v2)
Definition: inner_prod.hpp:100
ViennaCLStatus
ViennaCLStatus
Definition: viennacl.hpp:97
inner_prod.hpp
Generic interface for the computation of inner products. See viennacl/linalg/vector_operations.hpp for implementations.
norm_1.hpp
Generic interface for the l^1-norm. See viennacl/linalg/vector_operations.hpp for implementations...
viennacl::swap
void swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector.hpp:1648
VIENNACL_EXPORTED_FUNCTION
#define VIENNACL_EXPORTED_FUNCTION
Definition: viennacl.hpp:40
v1
viennacl::vector< float > v1
Definition: global_variables.cpp:60
ViennaCLHostDdot
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDdot(ViennaCLBackend, ViennaCLInt n, double *alpha, double *x, ViennaCLInt offx, int incx, double *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:168
viennacl_private.hpp
ViennaCLHostDrot
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDrot(ViennaCLBackend, ViennaCLInt n, double *x, ViennaCLInt offx, int incx, double *y, ViennaCLInt offy, int incy, double c, double s)
Definition: blas1_host.cpp:225
ViennaCLHostSdot
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSdot(ViennaCLBackend, ViennaCLInt n, float *alpha, float *x, ViennaCLInt offx, int incx, float *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:154
viennacl::vector_base< float >
ViennaCLInt
int ViennaCLInt
Definition: viennacl.hpp:48
ViennaCLHostSswap
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSswap(ViennaCLBackend, ViennaCLInt n, float *x, ViennaCLInt offx, int incx, float *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:269
viennacl::MAIN_MEMORY
Definition: forwards.h:348
v2
viennacl::vector< int > v2
Definition: global_variables.cpp:61
vector.hpp
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
ViennaCLHostDswap
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDswap(ViennaCLBackend, ViennaCLInt n, double *x, ViennaCLInt offx, int incx, double *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:282
ViennaCLHostDasum
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDasum(ViennaCLBackend, ViennaCLInt n, double *alpha, double *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:79
viennacl::linalg::norm_1
T norm_1(std::vector< T, A > const &v1)
Definition: norm_1.hpp:61
ViennaCLHostDaxpy
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDaxpy(ViennaCLBackend, ViennaCLInt n, double alpha, double *x, ViennaCLInt offx, int incx, double *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:109
ViennaCLHostiSamax
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostiSamax(ViennaCLBackend, ViennaCLInt n, ViennaCLInt *index, float *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:39
ViennaCLHostSscal
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSscal(ViennaCLBackend, ViennaCLInt n, float alpha, float *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:243
scalar.hpp
Implementation of the ViennaCL scalar class.
ViennaCLHostDcopy
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDcopy(ViennaCLBackend, ViennaCLInt n, double *x, ViennaCLInt offx, int incx, double *y, ViennaCLInt offy, int incy)
Definition: blas1_host.cpp:139
viennacl.hpp
norm_inf.hpp
Generic interface for the l^infty-norm. See viennacl/linalg/vector_operations.hpp for implementations...
ViennaCLHostDscal
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDscal(ViennaCLBackend, ViennaCLInt n, double alpha, double *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:255
ViennaCLSuccess
Definition: viennacl.hpp:99
viennacl::vector_base::size_type
SizeT size_type
Definition: vector_def.hpp:112