ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
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
30 
31 //include the generic norm functions of ViennaCL
35 
36 
37 // IxAMAX
38 
40  ViennaCLInt *index,
41  float *x, ViennaCLInt offx, int incx)
42 {
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 
52  ViennaCLInt *index,
53  double *x, ViennaCLInt offx, int incx)
54 {
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 
68  float *alpha,
69  float *x, ViennaCLInt offx, int incx)
70 {
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 
80  double *alpha,
81  double *x, ViennaCLInt offx, int incx)
82 {
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 
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 
110  double alpha,
111  double *x, ViennaCLInt offx, int incx,
112  double *y, ViennaCLInt offy, int incy)
113 {
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 
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 
140  double *x, ViennaCLInt offx, int incx,
141  double *y, ViennaCLInt offy, int incy)
142 {
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 
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 
169  double *alpha,
170  double *x, ViennaCLInt offx, int incx,
171  double *y, ViennaCLInt offy, int incy)
172 {
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 
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 
197  double *alpha,
198  double *x, ViennaCLInt offx, int incx)
199 {
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 
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 
226  double *x, ViennaCLInt offx, int incx,
227  double *y, ViennaCLInt offy, int incy,
228  double c, double s)
229 {
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 
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 
256  double alpha,
257  double *x, ViennaCLInt offx, int incx)
258 {
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 
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 
283  double *x, ViennaCLInt offx, int incx,
284  double *y, ViennaCLInt offy, int incy)
285 {
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 }
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDnrm2(ViennaCLBackend, ViennaCLInt n, double *alpha, double *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:196
T norm_2(std::vector< T, A > const &v1)
Definition: norm_2.hpp:96
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.
Generic interface for the l^2-norm. See viennacl/linalg/vector_operations.hpp for implementations...
Generic backend for CUDA, OpenCL, host-based stuff.
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSasum(ViennaCLBackend, ViennaCLInt n, float *alpha, float *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:67
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
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
void plane_rotation(vector_base< T > &vec1, vector_base< T > &vec2, T alpha, T beta)
Computes a plane rotation of two vectors.
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
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSnrm2(ViennaCLBackend, ViennaCLInt n, float *alpha, float *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:184
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostiDamax(ViennaCLBackend, ViennaCLInt n, ViennaCLInt *index, double *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:51
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
Definition: viennacl.hpp:97
Generic interface for the computation of inner products. See viennacl/linalg/vector_operations.hpp for implementations.
Generic interface for the l^1-norm. See viennacl/linalg/vector_operations.hpp for implementations...
void swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector.hpp:1648
#define VIENNACL_EXPORTED_FUNCTION
Definition: viennacl.hpp:40
viennacl::vector< float > v1
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_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
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
int ViennaCLInt
Definition: viennacl.hpp:48
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::vector< int > v2
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
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
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDasum(ViennaCLBackend, ViennaCLInt n, double *alpha, double *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:79
T norm_1(std::vector< T, A > const &v1)
Definition: norm_1.hpp:61
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
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostiSamax(ViennaCLBackend, ViennaCLInt n, ViennaCLInt *index, float *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:39
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSscal(ViennaCLBackend, ViennaCLInt n, float alpha, float *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:243
Implementation of the ViennaCL scalar class.
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
Generic interface for the l^infty-norm. See viennacl/linalg/vector_operations.hpp for implementations...
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDscal(ViennaCLBackend, ViennaCLInt n, double alpha, double *x, ViennaCLInt offx, int incx)
Definition: blas1_host.cpp:255