ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
blas3.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_matrix.hpp"
25 
26 //include basic scalar and vector types of ViennaCL
27 #include "viennacl/scalar.hpp"
28 #include "viennacl/vector.hpp"
29 #include "viennacl/matrix.hpp"
31 #include "viennacl/linalg/prod.hpp"
32 
33 // GEMV
34 
36 {
40 
41  if (init_matrix(A_handle, A) != ViennaCLSuccess)
43 
44  if (init_matrix(B_handle, B) != ViennaCLSuccess)
46 
47  if (init_matrix(C_handle, C) != ViennaCLSuccess)
49 
50  switch (A->precision)
51  {
52  case ViennaCLFloat:
53  {
55  typedef viennacl::matrix_base<float>::size_type difference_type;
56 
57  viennacl::matrix_base<float> mat_A(A_handle,
58  size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
59  size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
60  viennacl::matrix_base<float> mat_B(B_handle,
61  size_type(B->size1), size_type(B->start1), difference_type(B->stride1), size_type(B->internal_size1),
62  size_type(B->size2), size_type(B->start2), difference_type(B->stride2), size_type(B->internal_size2), B->order == ViennaCLRowMajor);
63  viennacl::matrix_base<float> mat_C(C_handle,
64  size_type(C->size1), size_type(C->start1), difference_type(C->stride1), size_type(C->internal_size1),
65  size_type(C->size2), size_type(C->start2), difference_type(C->stride2), size_type(C->internal_size2), C->order == ViennaCLRowMajor);
66 
67  if (A->trans == ViennaCLTrans && B->trans == ViennaCLTrans)
69  else if (A->trans == ViennaCLTrans && B->trans == ViennaCLNoTrans)
70  viennacl::linalg::prod_impl(viennacl::trans(mat_A), mat_B, mat_C, alpha->value_float, beta->value_float);
71  else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLTrans)
72  viennacl::linalg::prod_impl(mat_A, viennacl::trans(mat_B), mat_C, alpha->value_float, beta->value_float);
73  else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLNoTrans)
74  viennacl::linalg::prod_impl(mat_A, mat_B, mat_C, alpha->value_float, beta->value_float);
75  else
77 
78  return ViennaCLSuccess;
79  }
80 
81  case ViennaCLDouble:
82  {
84  typedef viennacl::matrix_base<double>::size_type difference_type;
85 
86  viennacl::matrix_base<double> mat_A(A_handle,
87  size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
88  size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
89  viennacl::matrix_base<double> mat_B(B_handle,
90  size_type(B->size1), size_type(B->start1), difference_type(B->stride1), size_type(B->internal_size1),
91  size_type(B->size2), size_type(B->start2), difference_type(B->stride2), size_type(B->internal_size2), B->order == ViennaCLRowMajor);
92  viennacl::matrix_base<double> mat_C(C_handle,
93  size_type(C->size1), size_type(C->start1), difference_type(C->stride1), size_type(C->internal_size1),
94  size_type(C->size2), size_type(C->start2), difference_type(C->stride2), size_type(C->internal_size2), C->order == ViennaCLRowMajor);
95 
96  if (A->trans == ViennaCLTrans && B->trans == ViennaCLTrans)
98  else if (A->trans == ViennaCLTrans && B->trans == ViennaCLNoTrans)
99  viennacl::linalg::prod_impl(viennacl::trans(mat_A), mat_B, mat_C, alpha->value_double, beta->value_double);
100  else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLTrans)
101  viennacl::linalg::prod_impl(mat_A, viennacl::trans(mat_B), mat_C, alpha->value_double, beta->value_double);
102  else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLNoTrans)
103  viennacl::linalg::prod_impl(mat_A, mat_B, mat_C, alpha->value_double, beta->value_double);
104  else
105  return ViennaCLGenericFailure;
106 
107  return ViennaCLSuccess;
108  }
109 
110  default:
111  return ViennaCLGenericFailure;
112  }
113 }
114 
115 
116 // xTRSV
117 
119 {
122 
123  if (init_matrix(A_handle, A) != ViennaCLSuccess)
124  return ViennaCLGenericFailure;
125 
126  if (init_matrix(B_handle, B) != ViennaCLSuccess)
127  return ViennaCLGenericFailure;
128 
129  switch (A->precision)
130  {
131  case ViennaCLFloat:
132  {
133  typedef viennacl::matrix_base<float>::size_type size_type;
134  typedef viennacl::matrix_base<float>::size_type difference_type;
135 
136  viennacl::matrix_base<float> mat_A(A_handle,
137  size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
138  size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
139  viennacl::matrix_base<float> mat_B(B_handle,
140  size_type(B->size1), size_type(B->start1), difference_type(B->stride1), size_type(B->internal_size1),
141  size_type(B->size2), size_type(B->start2), difference_type(B->stride2), size_type(B->internal_size2), B->order == ViennaCLRowMajor);
142 
143  if (A->trans == ViennaCLTrans && B->trans == ViennaCLTrans)
144  {
145  if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
147  else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
149  else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
151  else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
153  else
154  return ViennaCLGenericFailure;
155  }
156  else if (A->trans == ViennaCLTrans && B->trans == ViennaCLNoTrans)
157  {
158  if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
160  else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
162  else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
164  else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
166  else
167  return ViennaCLGenericFailure;
168  }
169  else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLTrans)
170  {
171  if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
173  else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
175  else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
177  else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
179  else
180  return ViennaCLGenericFailure;
181  }
182  else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLNoTrans)
183  {
184  if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
186  else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
188  else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
190  else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
192  else
193  return ViennaCLGenericFailure;
194  }
195 
196  return ViennaCLSuccess;
197  }
198  case ViennaCLDouble:
199  {
201  typedef viennacl::matrix_base<double>::size_type difference_type;
202 
203  viennacl::matrix_base<double> mat_A(A_handle,
204  size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
205  size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
206  viennacl::matrix_base<double> mat_B(B_handle,
207  size_type(B->size1), size_type(B->start1), difference_type(B->stride1), size_type(B->internal_size1),
208  size_type(B->size2), size_type(B->start2), difference_type(B->stride2), size_type(B->internal_size2), B->order == ViennaCLRowMajor);
209 
210  if (A->trans == ViennaCLTrans && B->trans == ViennaCLTrans)
211  {
212  if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
214  else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
216  else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
218  else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
220  else
221  return ViennaCLGenericFailure;
222  }
223  else if (A->trans == ViennaCLTrans && B->trans == ViennaCLNoTrans)
224  {
225  if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
227  else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
229  else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
231  else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
233  else
234  return ViennaCLGenericFailure;
235  }
236  else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLTrans)
237  {
238  if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
240  else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
242  else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
244  else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
246  else
247  return ViennaCLGenericFailure;
248  }
249  else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLNoTrans)
250  {
251  if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
253  else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
255  else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
257  else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
259  else
260  return ViennaCLGenericFailure;
261  }
262 
263  return ViennaCLSuccess;
264  }
265 
266  default:
267  return ViennaCLGenericFailure;
268  }
269 }
270 
271 
272 
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.
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 ViennaCLgemm(ViennaCLHostScalar alpha, ViennaCLMatrix A, ViennaCLMatrix B, ViennaCLHostScalar beta, ViennaCLMatrix C)
Definition: blas3.cpp:35
ViennaCLDiag
Definition: viennacl.hpp:82
ViennaCLStatus
Definition: viennacl.hpp:97
#define VIENNACL_EXPORTED_FUNCTION
Definition: viennacl.hpp:40
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLtrsm(ViennaCLMatrix A, ViennaCLUplo uplo, ViennaCLDiag diag, ViennaCLMatrix B)
Definition: blas3.cpp:118
ViennaCLUplo
Definition: viennacl.hpp:75
A tag class representing an upper triangular matrix.
Definition: forwards.h:854
vector_expression< const matrix_base< NumericT >, const int, op_matrix_diag > diag(const matrix_base< NumericT > &A, int k=0)
Definition: matrix.hpp:885
Implementations of dense direct solvers are found here.
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
A tag class representing a lower triangular matrix with unit diagonal.
Definition: forwards.h:859
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:89
ViennaCLTranspose trans
ViennaCLPrecision precision
void prod_impl(const matrix_base< NumericT > &mat, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
Implementation of the ViennaCL scalar class.
A tag class representing an upper triangular matrix with unit diagonal.
Definition: forwards.h:864