ViennaCL - The Vienna Computing Library: libviennacl/src/blas2_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
blas2_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 "viennacl/vector.hpp"
29 #include "viennacl/matrix.hpp"
30 #include "viennacl/linalg/direct_solve.hpp"
31 #include "viennacl/linalg/prod.hpp"
32
33
34 // xGEMV
35
36 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSgemv(ViennaCLBackend /*backend*/,
37 ViennaCLOrder order, ViennaCLTranspose transA,
38 ViennaCLInt m, ViennaCLInt n, float alpha, float *A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda,
39 float *x, ViennaCLInt offx, ViennaCLInt incx,
40 float beta,
41 float *y, ViennaCLInt offy, ViennaCLInt incy)
42 {
43 typedef viennacl::vector_base<float>::size_type size_type;
44 typedef viennacl::vector_base<float>::size_type difference_type;
45
46 viennacl::vector_base<float> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
47 viennacl::vector_base<float> v2(y, viennacl::MAIN_MEMORY, size_type(m), size_type(offy), difference_type(incy));
48 viennacl::matrix_base<float> mat(A, viennacl::MAIN_MEMORY,
49 size_type(m), size_type(offA_row), difference_type(incA_row), size_type(m),
50 size_type(n), size_type(offA_col), difference_type(incA_col), size_type(lda), order == ViennaCLRowMajor);
51 v2 *= beta;
52 if (transA == ViennaCLTrans)
53 v2 += alpha * viennacl::linalg::prod(viennacl::trans(mat), v1);
54 else
55 v2 += alpha * viennacl::linalg::prod(mat, v1);
56
57 return ViennaCLSuccess;
58 }
59
60 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDgemv(ViennaCLBackend /*backend*/,
61 ViennaCLOrder order, ViennaCLTranspose transA,
62 ViennaCLInt m, ViennaCLInt n, double alpha, double *A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda,
63 double *x, ViennaCLInt offx, ViennaCLInt incx,
64 double beta,
65 double *y, ViennaCLInt offy, ViennaCLInt incy)
66 {
67 typedef viennacl::vector_base<double>::size_type size_type;
68 typedef viennacl::vector_base<double>::size_type difference_type;
69
70 viennacl::vector_base<double> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
71 viennacl::vector_base<double> v2(y, viennacl::MAIN_MEMORY, size_type(m), size_type(offy), difference_type(incy));
72 viennacl::matrix_base<double> mat(A, viennacl::MAIN_MEMORY,
73 size_type(m), size_type(offA_row), difference_type(incA_row), size_type(m),
74 size_type(n), size_type(offA_col), difference_type(incA_col), size_type(lda), order == ViennaCLRowMajor);
75 v2 *= beta;
76 if (transA == ViennaCLTrans)
77 v2 += alpha * viennacl::linalg::prod(viennacl::trans(mat), v1);
78 else
79 v2 += alpha * viennacl::linalg::prod(mat, v1);
80
81 return ViennaCLSuccess;
82 }
83
84
85
86 // xTRSV
87
88 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostStrsv(ViennaCLBackend /*backend*/,
89 ViennaCLUplo uplo, ViennaCLOrder order, ViennaCLTranspose transA, ViennaCLDiag diag,
90 ViennaCLInt n, float *A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda,
91 float *x, ViennaCLInt offx, ViennaCLInt incx)
92 {
93 typedef viennacl::vector_base<float>::size_type size_type;
94 typedef viennacl::vector_base<float>::size_type difference_type;
95
96 viennacl::vector_base<float> v(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
97 viennacl::matrix_base<float> mat(A, viennacl::MAIN_MEMORY,
98 size_type(n), size_type(offA_row), difference_type(incA_row), size_type(n),
99 size_type(n), size_type(offA_col), difference_type(incA_col), size_type(lda), order == ViennaCLRowMajor);
100 if (transA == ViennaCLTrans)
101 {
102 if (uplo == ViennaCLUpper)
103 if (diag == ViennaCLUnit)
104 viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::unit_upper_tag());
105 else
106 viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::upper_tag());
107 else
108 if (diag == ViennaCLUnit)
109 viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::unit_lower_tag());
110 else
111 viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::lower_tag());
112 }
113 else
114 {
115 if (uplo == ViennaCLUpper)
116 if (diag == ViennaCLUnit)
117 viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::unit_upper_tag());
118 else
119 viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::upper_tag());
120 else
121 if (diag == ViennaCLUnit)
122 viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::unit_lower_tag());
123 else
124 viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::lower_tag());
125 }
126
127 return ViennaCLSuccess;
128 }
129
130 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDtrsv(ViennaCLBackend /*backend*/,
131 ViennaCLUplo uplo, ViennaCLOrder order, ViennaCLTranspose transA, ViennaCLDiag diag,
132 ViennaCLInt n, double *A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda,
133 double *x, ViennaCLInt offx, ViennaCLInt incx)
134 {
135 typedef viennacl::vector_base<double>::size_type size_type;
136 typedef viennacl::vector_base<double>::size_type difference_type;
137
138 viennacl::vector_base<double> v(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
139 viennacl::matrix_base<double> mat(A, viennacl::MAIN_MEMORY,
140 size_type(n), size_type(offA_row), difference_type(incA_row), size_type(n),
141 size_type(n), size_type(offA_col), difference_type(incA_col), size_type(lda), order == ViennaCLRowMajor);
142 if (transA == ViennaCLTrans)
143 {
144 if (uplo == ViennaCLUpper)
145 if (diag == ViennaCLUnit)
146 viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::unit_upper_tag());
147 else
148 viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::upper_tag());
149 else
150 if (diag == ViennaCLUnit)
151 viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::unit_lower_tag());
152 else
153 viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::lower_tag());
154 }
155 else
156 {
157 if (uplo == ViennaCLUpper)
158 if (diag == ViennaCLUnit)
159 viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::unit_upper_tag());
160 else
161 viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::upper_tag());
162 else
163 if (diag == ViennaCLUnit)
164 viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::unit_lower_tag());
165 else
166 viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::lower_tag());
167 }
168
169 return ViennaCLSuccess;
170 }
171
172
173
174 // xGER
175
176 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSger(ViennaCLBackend /*backend*/,
177 ViennaCLOrder order,
178 ViennaCLInt m, ViennaCLInt n,
179 float alpha,
180 float *x, ViennaCLInt offx, ViennaCLInt incx,
181 float *y, ViennaCLInt offy, ViennaCLInt incy,
182 float *A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda)
183 {
184 typedef viennacl::vector_base<float>::size_type size_type;
185 typedef viennacl::vector_base<float>::size_type difference_type;
186
187 viennacl::vector_base<float> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
188 viennacl::vector_base<float> v2(y, viennacl::MAIN_MEMORY, size_type(m), size_type(offy), difference_type(incy));
189 viennacl::matrix_base<float> mat(A, viennacl::MAIN_MEMORY,
190 size_type(m), size_type(offA_row), difference_type(incA_row), size_type(m),
191 size_type(n), size_type(offA_col), difference_type(incA_col), size_type(lda), order == ViennaCLRowMajor);
192
193 mat += alpha * viennacl::linalg::outer_prod(v1, v2);
194
195 return ViennaCLSuccess;
196 }
197
198 VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDger(ViennaCLBackend /*backend*/,
199 ViennaCLOrder order,
200 ViennaCLInt m, ViennaCLInt n,
201 double alpha,
202 double *x, ViennaCLInt offx, ViennaCLInt incx,
203 double *y, ViennaCLInt offy, ViennaCLInt incy,
204 double *A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda)
205 {
206 typedef viennacl::vector_base<double>::size_type size_type;
207 typedef viennacl::vector_base<double>::size_type difference_type;
208
209 viennacl::vector_base<double> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
210 viennacl::vector_base<double> v2(y, viennacl::MAIN_MEMORY, size_type(m), size_type(offy), difference_type(incy));
211 viennacl::matrix_base<double> mat(A, viennacl::MAIN_MEMORY,
212 size_type(m), size_type(offA_row), difference_type(incA_row), size_type(m),
213 size_type(n), size_type(offA_col), difference_type(incA_col), size_type(lda), order == ViennaCLRowMajor);
214
215 mat += alpha * viennacl::linalg::outer_prod(v1, v2);
216
217 return ViennaCLSuccess;
218 }
219
viennacl::linalg::inplace_solve
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...
Definition: direct_solve.hpp:217
ViennaCLTranspose
ViennaCLTranspose
Definition: viennacl.hpp:68
viennacl::trans
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.
Definition: sparse_matrix_operations.hpp:376
ViennaCLBackend_impl
Generic backend for CUDA, OpenCL, host-based stuff.
Definition: viennacl_private.hpp:54
ViennaCLHostSger
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSger(ViennaCLBackend, ViennaCLOrder order, ViennaCLInt m, ViennaCLInt n, float alpha, float *x, ViennaCLInt offx, ViennaCLInt incx, float *y, ViennaCLInt offy, ViennaCLInt incy, float *A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda)
Definition: blas2_host.cpp:176
prod.hpp
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
matrix.hpp
Implementation of the dense matrix class.
viennacl::linalg::lower_tag
A tag class representing a lower triangular matrix.
Definition: forwards.h:849
ViennaCLUnit
Definition: viennacl.hpp:85
viennacl::matrix_base< float >
ViennaCLDiag
ViennaCLDiag
Definition: viennacl.hpp:82
ViennaCLStatus
ViennaCLStatus
Definition: viennacl.hpp:97
ViennaCLHostSgemv
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSgemv(ViennaCLBackend, ViennaCLOrder order, ViennaCLTranspose transA, ViennaCLInt m, ViennaCLInt n, float alpha, float *A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda, float *x, ViennaCLInt offx, ViennaCLInt incx, float beta, float *y, ViennaCLInt offy, ViennaCLInt incy)
Definition: blas2_host.cpp:36
ViennaCLMatrix_impl::order
ViennaCLOrder order
Definition: viennacl_private.hpp:117
VIENNACL_EXPORTED_FUNCTION
#define VIENNACL_EXPORTED_FUNCTION
Definition: viennacl.hpp:40
v1
viennacl::vector< float > v1
Definition: global_variables.cpp:60
ViennaCLHostDtrsv
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDtrsv(ViennaCLBackend, ViennaCLUplo uplo, ViennaCLOrder order, ViennaCLTranspose transA, ViennaCLDiag diag, ViennaCLInt n, double *A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda, double *x, ViennaCLInt offx, ViennaCLInt incx)
Definition: blas2_host.cpp:130
viennacl::linalg::prod
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
Definition: prod.hpp:102
viennacl_private.hpp
ViennaCLUplo
ViennaCLUplo
Definition: viennacl.hpp:75
viennacl::linalg::upper_tag
A tag class representing an upper triangular matrix.
Definition: forwards.h:854
ViennaCLOrder
ViennaCLOrder
Definition: viennacl.hpp:61
ViennaCLHostDger
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDger(ViennaCLBackend, ViennaCLOrder order, ViennaCLInt m, ViennaCLInt n, double alpha, double *x, ViennaCLInt offx, ViennaCLInt incx, double *y, ViennaCLInt offy, ViennaCLInt incy, double *A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda)
Definition: blas2_host.cpp:198
viennacl::vector_base< float >
ViennaCLInt
int ViennaCLInt
Definition: viennacl.hpp:48
viennacl::diag
vector_expression< const matrix_base< NumericT >, const int, op_matrix_diag > diag(const matrix_base< NumericT > &A, int k=0)
Definition: matrix.hpp:895
ViennaCLHostStrsv
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostStrsv(ViennaCLBackend, ViennaCLUplo uplo, ViennaCLOrder order, ViennaCLTranspose transA, ViennaCLDiag diag, ViennaCLInt n, float *A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda, float *x, ViennaCLInt offx, ViennaCLInt incx)
Definition: blas2_host.cpp:88
direct_solve.hpp
Implementations of dense direct solvers are found here.
viennacl::MAIN_MEMORY
Definition: forwards.h:348
viennacl::linalg::outer_prod
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.
Definition: matrix_operations.hpp:840
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 ...
ViennaCLRowMajor
Definition: viennacl.hpp:64
viennacl::linalg::unit_lower_tag
A tag class representing a lower triangular matrix with unit diagonal.
Definition: forwards.h:859
ViennaCLUpper
Definition: viennacl.hpp:78
ViennaCLTrans
Definition: viennacl.hpp:72
ViennaCLHostDgemv
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDgemv(ViennaCLBackend, ViennaCLOrder order, ViennaCLTranspose transA, ViennaCLInt m, ViennaCLInt n, double alpha, double *A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda, double *x, ViennaCLInt offx, ViennaCLInt incx, double beta, double *y, ViennaCLInt offy, ViennaCLInt incy)
Definition: blas2_host.cpp:60
scalar.hpp
Implementation of the ViennaCL scalar class.
viennacl.hpp
viennacl::linalg::unit_upper_tag
A tag class representing an upper triangular matrix with unit diagonal.
Definition: forwards.h:864
ViennaCLSuccess
Definition: viennacl.hpp:99
viennacl::vector_base::size_type
SizeT size_type
Definition: vector_def.hpp:112