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
blas2.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 "init_vector.hpp"
25 #include "init_matrix.hpp"
26 
27 //include basic scalar and vector types of ViennaCL
28 #include "viennacl/scalar.hpp"
29 #include "viennacl/vector.hpp"
30 #include "viennacl/matrix.hpp"
32 #include "viennacl/linalg/prod.hpp"
33 
34 // GEMV
35 
37 {
41 
42  if (init_vector(v1_handle, x) != ViennaCLSuccess)
44 
45  if (init_vector(v2_handle, y) != ViennaCLSuccess)
47 
48  if (init_matrix(A_handle, A) != ViennaCLSuccess)
50 
51  switch (x->precision)
52  {
53  case ViennaCLFloat:
54  {
56  typedef viennacl::vector_base<float>::size_type difference_type;
57 
58  viennacl::vector_base<float> v1(v1_handle, size_type(x->size), size_type(x->offset), difference_type(x->inc));
59  viennacl::vector_base<float> v2(v2_handle, size_type(y->size), size_type(y->offset), difference_type(y->inc));
60 
61  viennacl::matrix_base<float> mat(A_handle,
62  size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
63  size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
64  v2 *= beta->value_float;
65  if (A->trans == ViennaCLTrans)
66  v2 += alpha->value_float * viennacl::linalg::prod(viennacl::trans(mat), v1);
67  else
68  v2 += alpha->value_float * viennacl::linalg::prod(mat, v1);
69 
70  return ViennaCLSuccess;
71  }
72 
73  case ViennaCLDouble:
74  {
76  typedef viennacl::vector_base<double>::size_type difference_type;
77 
78  viennacl::vector_base<double> v1(v1_handle, size_type(x->size), size_type(x->offset), difference_type(x->inc));
79  viennacl::vector_base<double> v2(v2_handle, size_type(y->size), size_type(y->offset), difference_type(y->inc));
80 
81  viennacl::matrix_base<double> mat(A_handle,
82  size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
83  size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
84  v2 *= beta->value_double;
85  if (A->trans == ViennaCLTrans)
86  v2 += alpha->value_double * viennacl::linalg::prod(viennacl::trans(mat), v1);
87  else
88  v2 += alpha->value_double * viennacl::linalg::prod(mat, v1);
89 
90  return ViennaCLSuccess;
91  }
92 
93  default:
95  }
96 }
97 
98 
99 // xTRSV
100 
102 {
105 
106  if (init_vector(v1_handle, x) != ViennaCLSuccess)
107  return ViennaCLGenericFailure;
108 
109  if (init_matrix(A_handle, A) != ViennaCLSuccess)
110  return ViennaCLGenericFailure;
111 
112  switch (x->precision)
113  {
114  case ViennaCLFloat:
115  {
116  typedef viennacl::vector_base<float>::size_type size_type;
117  typedef viennacl::vector_base<float>::size_type difference_type;
118 
119  viennacl::vector_base<float> v1(v1_handle, size_type(x->size), size_type(x->offset), difference_type(x->inc));
120 
121  viennacl::matrix_base<float> mat(A_handle,
122  size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
123  size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
124  if (A->trans == ViennaCLTrans)
125  {
126  if (uplo == ViennaCLUpper)
128  else
130  }
131  else
132  {
133  if (uplo == ViennaCLUpper)
135  else
137  }
138 
139  return ViennaCLSuccess;
140  }
141  case ViennaCLDouble:
142  {
144  typedef viennacl::vector_base<double>::size_type difference_type;
145 
146  viennacl::vector_base<double> v1(v1_handle, size_type(x->size), size_type(x->offset), difference_type(x->inc));
147 
148  viennacl::matrix_base<double> mat(A_handle,
149  size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
150  size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
151  if (A->trans == ViennaCLTrans)
152  {
153  if (uplo == ViennaCLUpper)
155  else
157  }
158  else
159  {
160  if (uplo == ViennaCLUpper)
162  else
164  }
165 
166  return ViennaCLSuccess;
167  }
168 
169  default:
170  return ViennaCLGenericFailure;
171  }
172 }
173 
174 
175 // xGER
176 
178 {
182 
183  if (init_vector(v1_handle, x) != ViennaCLSuccess)
184  return ViennaCLGenericFailure;
185 
186  if (init_vector(v2_handle, y) != ViennaCLSuccess)
187  return ViennaCLGenericFailure;
188 
189  if (init_matrix(A_handle, A) != ViennaCLSuccess)
190  return ViennaCLGenericFailure;
191 
192  switch (x->precision)
193  {
194  case ViennaCLFloat:
195  {
196  typedef viennacl::vector_base<float>::size_type size_type;
197  typedef viennacl::vector_base<float>::size_type difference_type;
198 
199  viennacl::vector_base<float> v1(v1_handle, size_type(x->size), size_type(x->offset), difference_type(x->inc));
200  viennacl::vector_base<float> v2(v2_handle, size_type(y->size), size_type(y->offset), difference_type(y->inc));
201 
202  viennacl::matrix_base<float> mat(A_handle,
203  size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
204  size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
205 
206  mat += alpha->value_float * viennacl::linalg::outer_prod(v1, v2);
207 
208  return ViennaCLSuccess;
209  }
210  case ViennaCLDouble:
211  {
213  typedef viennacl::vector_base<double>::size_type difference_type;
214 
215  viennacl::vector_base<double> v1(v1_handle, size_type(x->size), size_type(x->offset), difference_type(x->inc));
216  viennacl::vector_base<double> v2(v2_handle, size_type(y->size), size_type(y->offset), difference_type(y->inc));
217 
218  viennacl::matrix_base<double> mat(A_handle,
219  size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
220  size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
221 
222  mat += alpha->value_double * viennacl::linalg::outer_prod(v1, v2);
223 
224  return ViennaCLSuccess;
225  }
226  default:
227  return ViennaCLGenericFailure;
228  }
229 }
230 
231 
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLtrsv(ViennaCLMatrix A, ViennaCLVector x, ViennaCLUplo uplo)
Definition: blas2.cpp:101
void inplace_solve(const matrix_base< NumericT > &A, matrix_base< NumericT > &B, SolverTagT)
Direct inplace solver for triangular systems with multiple right hand sides, i.e. A \ B (MATLAB notat...
viennacl::enable_if< viennacl::is_any_sparse_matrix< M1 >::value, matrix_expression< const M1, const M1, op_trans > >::type trans(const M1 &mat)
Returns an expression template class representing a transposed matrix.
ViennaCLPrecision precision
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Implementation of the dense matrix class.
A tag class representing a lower triangular matrix.
Definition: forwards.h:849
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLgemv(ViennaCLHostScalar alpha, ViennaCLMatrix A, ViennaCLVector x, ViennaCLHostScalar beta, ViennaCLVector y)
Definition: blas2.cpp:36
ViennaCLStatus
Definition: viennacl.hpp:97
#define VIENNACL_EXPORTED_FUNCTION
Definition: viennacl.hpp:40
viennacl::vector< float > v1
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
Definition: prod.hpp:102
ViennaCLUplo
Definition: viennacl.hpp:75
A tag class representing an upper triangular matrix.
Definition: forwards.h:854
Implementations of dense direct solvers are found here.
viennacl::matrix_expression< const vector_base< NumericT >, const vector_base< NumericT >, op_prod > outer_prod(const vector_base< NumericT > &vec1, const vector_base< NumericT > &vec2)
Returns a proxy class for the operation mat += vec1 * vec2^T, i.e. a rank 1 update.
viennacl::vector< int > v2
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:89
ViennaCLTranspose trans
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLger(ViennaCLHostScalar alpha, ViennaCLVector x, ViennaCLVector y, ViennaCLMatrix A)
Definition: blas2.cpp:177
Implementation of the ViennaCL scalar class.