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_opencl.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"
31 #include "viennacl/linalg/prod.hpp"
32 
33 
34 // xGEMV
35 
38  ViennaCLInt m, ViennaCLInt n, float alpha, cl_mem A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda,
39  cl_mem x, ViennaCLInt offx, ViennaCLInt incx,
40  float beta,
41  cl_mem y, ViennaCLInt offy, ViennaCLInt incy)
42 {
44  typedef viennacl::vector_base<float>::size_type difference_type;
45 
46  viennacl::vector_base<float> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
47  viennacl::vector_base<float> v2(y, size_type(m), size_type(offy), difference_type(incy), viennacl::ocl::get_context(backend->opencl_backend.context_id));
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 
62  ViennaCLInt m, ViennaCLInt n, double alpha, cl_mem A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda,
63  cl_mem x, ViennaCLInt offx, ViennaCLInt incx,
64  double beta,
65  cl_mem y, ViennaCLInt offy, ViennaCLInt incy)
66 {
68  typedef viennacl::vector_base<double>::size_type difference_type;
69 
70  viennacl::vector_base<double> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
71  viennacl::vector_base<double> v2(y, size_type(m), size_type(offy), difference_type(incy), viennacl::ocl::get_context(backend->opencl_backend.context_id));
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 
90  ViennaCLInt n, cl_mem A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda,
91  cl_mem x, ViennaCLInt offx, ViennaCLInt incx)
92 {
94  typedef viennacl::vector_base<float>::size_type difference_type;
95 
96  viennacl::vector_base<float> v(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
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)
105  else
107  else
108  if (diag == ViennaCLUnit)
110  else
112  }
113  else
114  {
115  if (uplo == ViennaCLUpper)
116  if (diag == ViennaCLUnit)
118  else
120  else
121  if (diag == ViennaCLUnit)
123  else
125  }
126 
127  return ViennaCLSuccess;
128 }
129 
132  ViennaCLInt n, cl_mem A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda,
133  cl_mem x, ViennaCLInt offx, ViennaCLInt incx)
134 {
136  typedef viennacl::vector_base<double>::size_type difference_type;
137 
138  viennacl::vector_base<double> v(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
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)
147  else
149  else
150  if (diag == ViennaCLUnit)
152  else
154  }
155  else
156  {
157  if (uplo == ViennaCLUpper)
158  if (diag == ViennaCLUnit)
160  else
162  else
163  if (diag == ViennaCLUnit)
165  else
167  }
168 
169  return ViennaCLSuccess;
170 }
171 
172 
173 
174 // xGER
175 
179  float alpha,
180  cl_mem x, ViennaCLInt offx, ViennaCLInt incx,
181  cl_mem y, ViennaCLInt offy, ViennaCLInt incy,
182  cl_mem 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, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
188  viennacl::vector_base<float> v2(y, size_type(m), size_type(offy), difference_type(incy), viennacl::ocl::get_context(backend->opencl_backend.context_id));
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 
201  double alpha,
202  cl_mem x, ViennaCLInt offx, ViennaCLInt incx,
203  cl_mem y, ViennaCLInt offy, ViennaCLInt incy,
204  cl_mem A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda)
205 {
207  typedef viennacl::vector_base<double>::size_type difference_type;
208 
209  viennacl::vector_base<double> v1(x, size_type(n), size_type(offx), difference_type(incx), viennacl::ocl::get_context(backend->opencl_backend.context_id));
210  viennacl::vector_base<double> v2(y, size_type(m), size_type(offy), difference_type(incy), viennacl::ocl::get_context(backend->opencl_backend.context_id));
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 
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...
ViennaCLTranspose
Definition: viennacl.hpp:68
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 backend for CUDA, OpenCL, host-based stuff.
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Implementation of the dense matrix class.
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLDgemv(ViennaCLBackend backend, ViennaCLOrder order, ViennaCLTranspose transA, ViennaCLInt m, ViennaCLInt n, double alpha, cl_mem A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda, cl_mem x, ViennaCLInt offx, ViennaCLInt incx, double beta, cl_mem y, ViennaCLInt offy, ViennaCLInt incy)
A tag class representing a lower triangular matrix.
Definition: forwards.h:849
ViennaCLDiag
Definition: viennacl.hpp:82
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
ViennaCLBackend backend
ViennaCLUplo
Definition: viennacl.hpp:75
A tag class representing an upper triangular matrix.
Definition: forwards.h:854
ViennaCLOpenCLBackend_impl opencl_backend
ViennaCLOrder
Definition: viennacl.hpp:61
int ViennaCLInt
Definition: viennacl.hpp:48
vector_expression< const matrix_base< NumericT >, const int, op_matrix_diag > diag(const matrix_base< NumericT > &A, int k=0)
Definition: matrix.hpp:895
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLSger(ViennaCLBackend backend, ViennaCLOrder order, ViennaCLInt m, ViennaCLInt n, float alpha, cl_mem x, ViennaCLInt offx, ViennaCLInt incx, cl_mem y, ViennaCLInt offy, ViennaCLInt incy, cl_mem A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda)
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_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLDtrsv(ViennaCLBackend backend, ViennaCLUplo uplo, ViennaCLOrder order, ViennaCLTranspose transA, ViennaCLDiag diag, ViennaCLInt n, cl_mem A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda, cl_mem x, ViennaCLInt offx, ViennaCLInt incx)
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLSgemv(ViennaCLBackend backend, ViennaCLOrder order, ViennaCLTranspose transA, ViennaCLInt m, ViennaCLInt n, float alpha, cl_mem A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda, cl_mem x, ViennaCLInt offx, ViennaCLInt incx, float beta, cl_mem y, ViennaCLInt offy, ViennaCLInt incy)
viennacl::vector< int > v2
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLDger(ViennaCLBackend backend, ViennaCLOrder order, ViennaCLInt m, ViennaCLInt n, double alpha, cl_mem x, ViennaCLInt offx, ViennaCLInt incx, cl_mem y, ViennaCLInt offy, ViennaCLInt incy, cl_mem A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda)
A tag class representing a lower triangular matrix with unit diagonal.
Definition: forwards.h:859
viennacl::ocl::context & get_context(long i)
Convenience function for returning the current context.
Definition: backend.hpp:225
Implementation of the ViennaCL scalar class.
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLOpenCLStrsv(ViennaCLBackend backend, ViennaCLUplo uplo, ViennaCLOrder order, ViennaCLTranspose transA, ViennaCLDiag diag, ViennaCLInt n, cl_mem A, ViennaCLInt offA_row, ViennaCLInt offA_col, ViennaCLInt incA_row, ViennaCLInt incA_col, ViennaCLInt lda, cl_mem x, ViennaCLInt offx, ViennaCLInt incx)
A tag class representing an upper triangular matrix with unit diagonal.
Definition: forwards.h:864