All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
blas2.cpp
Go to the documentation of this file.
/* =========================================================================
Copyright (c) 2010-2014, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the PDF manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
// include necessary system headers
#include <iostream>
#include "viennacl.hpp"
#include "viennacl_private.hpp"
#include "init_vector.hpp"
#include "init_matrix.hpp"
//include basic scalar and vector types of ViennaCL
#include "viennacl/scalar.hpp"
#include "viennacl/vector.hpp"
#include "viennacl/matrix.hpp"
#include "viennacl/linalg/direct_solve.hpp"
#include "viennacl/linalg/prod.hpp"
// GEMV
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLgemv(ViennaCLHostScalar alpha, ViennaCLMatrix A, ViennaCLVector x, ViennaCLHostScalar beta, ViennaCLVector y)
{
viennacl::backend::mem_handle v1_handle;
viennacl::backend::mem_handle v2_handle;
viennacl::backend::mem_handle A_handle;
if (init_vector(v1_handle, x) != ViennaCLSuccess)
return ViennaCLGenericFailure;
if (init_vector(v2_handle, y) != ViennaCLSuccess)
return ViennaCLGenericFailure;
if (init_matrix(A_handle, A) != ViennaCLSuccess)
return ViennaCLGenericFailure;
switch (x->precision)
{
case ViennaCLFloat:
{
typedef viennacl::vector_base<float>::size_type size_type;
typedef viennacl::vector_base<float>::size_type difference_type;
viennacl::vector_base<float> v1(v1_handle, size_type(x->size), size_type(x->offset), difference_type(x->inc));
viennacl::vector_base<float> v2(v2_handle, size_type(y->size), size_type(y->offset), difference_type(y->inc));
viennacl::matrix_base<float> mat(A_handle,
size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
v2 *= beta->value_float;
if (A->trans == ViennaCLTrans)
v2 += alpha->value_float * viennacl::linalg::prod(viennacl::trans(mat), v1);
else
v2 += alpha->value_float * viennacl::linalg::prod(mat, v1);
return ViennaCLSuccess;
}
case ViennaCLDouble:
{
typedef viennacl::vector_base<double>::size_type size_type;
typedef viennacl::vector_base<double>::size_type difference_type;
viennacl::vector_base<double> v1(v1_handle, size_type(x->size), size_type(x->offset), difference_type(x->inc));
viennacl::vector_base<double> v2(v2_handle, size_type(y->size), size_type(y->offset), difference_type(y->inc));
viennacl::matrix_base<double> mat(A_handle,
size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
v2 *= beta->value_double;
if (A->trans == ViennaCLTrans)
v2 += alpha->value_double * viennacl::linalg::prod(viennacl::trans(mat), v1);
else
v2 += alpha->value_double * viennacl::linalg::prod(mat, v1);
return ViennaCLSuccess;
}
default:
return ViennaCLGenericFailure;
}
}
// xTRSV
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLtrsv(ViennaCLMatrix A, ViennaCLVector x, ViennaCLUplo uplo)
{
viennacl::backend::mem_handle v1_handle;
viennacl::backend::mem_handle A_handle;
if (init_vector(v1_handle, x) != ViennaCLSuccess)
return ViennaCLGenericFailure;
if (init_matrix(A_handle, A) != ViennaCLSuccess)
return ViennaCLGenericFailure;
switch (x->precision)
{
case ViennaCLFloat:
{
typedef viennacl::vector_base<float>::size_type size_type;
typedef viennacl::vector_base<float>::size_type difference_type;
viennacl::vector_base<float> v1(v1_handle, size_type(x->size), size_type(x->offset), difference_type(x->inc));
viennacl::matrix_base<float> mat(A_handle,
size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
if (A->trans == ViennaCLTrans)
{
if (uplo == ViennaCLUpper)
viennacl::linalg::inplace_solve(viennacl::trans(mat), v1, viennacl::linalg::upper_tag());
else
viennacl::linalg::inplace_solve(viennacl::trans(mat), v1, viennacl::linalg::lower_tag());
}
else
{
if (uplo == ViennaCLUpper)
viennacl::linalg::inplace_solve(mat, v1, viennacl::linalg::upper_tag());
else
viennacl::linalg::inplace_solve(mat, v1, viennacl::linalg::lower_tag());
}
return ViennaCLSuccess;
}
case ViennaCLDouble:
{
typedef viennacl::vector_base<double>::size_type size_type;
typedef viennacl::vector_base<double>::size_type difference_type;
viennacl::vector_base<double> v1(v1_handle, size_type(x->size), size_type(x->offset), difference_type(x->inc));
viennacl::matrix_base<double> mat(A_handle,
size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
if (A->trans == ViennaCLTrans)
{
if (uplo == ViennaCLUpper)
viennacl::linalg::inplace_solve(viennacl::trans(mat), v1, viennacl::linalg::upper_tag());
else
viennacl::linalg::inplace_solve(viennacl::trans(mat), v1, viennacl::linalg::lower_tag());
}
else
{
if (uplo == ViennaCLUpper)
viennacl::linalg::inplace_solve(mat, v1, viennacl::linalg::upper_tag());
else
viennacl::linalg::inplace_solve(mat, v1, viennacl::linalg::lower_tag());
}
return ViennaCLSuccess;
}
default:
return ViennaCLGenericFailure;
}
}
// xGER
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLger(ViennaCLHostScalar alpha, ViennaCLVector x, ViennaCLVector y, ViennaCLMatrix A)
{
viennacl::backend::mem_handle v1_handle;
viennacl::backend::mem_handle v2_handle;
viennacl::backend::mem_handle A_handle;
if (init_vector(v1_handle, x) != ViennaCLSuccess)
return ViennaCLGenericFailure;
if (init_vector(v2_handle, y) != ViennaCLSuccess)
return ViennaCLGenericFailure;
if (init_matrix(A_handle, A) != ViennaCLSuccess)
return ViennaCLGenericFailure;
switch (x->precision)
{
case ViennaCLFloat:
{
typedef viennacl::vector_base<float>::size_type size_type;
typedef viennacl::vector_base<float>::size_type difference_type;
viennacl::vector_base<float> v1(v1_handle, size_type(x->size), size_type(x->offset), difference_type(x->inc));
viennacl::vector_base<float> v2(v2_handle, size_type(y->size), size_type(y->offset), difference_type(y->inc));
viennacl::matrix_base<float> mat(A_handle,
size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
mat += alpha->value_float * viennacl::linalg::outer_prod(v1, v2);
return ViennaCLSuccess;
}
case ViennaCLDouble:
{
typedef viennacl::vector_base<double>::size_type size_type;
typedef viennacl::vector_base<double>::size_type difference_type;
viennacl::vector_base<double> v1(v1_handle, size_type(x->size), size_type(x->offset), difference_type(x->inc));
viennacl::vector_base<double> v2(v2_handle, size_type(y->size), size_type(y->offset), difference_type(y->inc));
viennacl::matrix_base<double> mat(A_handle,
size_type(A->size1), size_type(A->start1), difference_type(A->stride1), size_type(A->internal_size1),
size_type(A->size2), size_type(A->start2), difference_type(A->stride2), size_type(A->internal_size2), A->order == ViennaCLRowMajor);
mat += alpha->value_double * viennacl::linalg::outer_prod(v1, v2);
return ViennaCLSuccess;
}
default:
return ViennaCLGenericFailure;
}
}
ViennaCLtrsv
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLtrsv(ViennaCLMatrix A, ViennaCLVector x, ViennaCLUplo uplo)
Definition: blas2.cpp:101
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
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
ViennaCLVector_impl::precision
ViennaCLPrecision precision
Definition: viennacl_private.hpp:97
ViennaCLHostScalar_impl::value_float
float value_float
Definition: viennacl_private.hpp:72
prod.hpp
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
ViennaCLMatrix_impl::start1
ViennaCLInt start1
Definition: viennacl_private.hpp:130
matrix.hpp
Implementation of the dense matrix class.
ViennaCLMatrix_impl::stride2
ViennaCLInt stride2
Definition: viennacl_private.hpp:136
viennacl::linalg::lower_tag
A tag class representing a lower triangular matrix.
Definition: forwards.h:849
ViennaCLgemv
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLgemv(ViennaCLHostScalar alpha, ViennaCLMatrix A, ViennaCLVector x, ViennaCLHostScalar beta, ViennaCLVector y)
Definition: blas2.cpp:36
viennacl::matrix_base< float >
ViennaCLDouble
Definition: viennacl.hpp:93
ViennaCLStatus
ViennaCLStatus
Definition: viennacl.hpp:97
ViennaCLMatrix_impl::internal_size2
ViennaCLInt internal_size2
Definition: viennacl_private.hpp:137
ViennaCLVector_impl::size
ViennaCLInt size
Definition: viennacl_private.hpp:110
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
viennacl::linalg::prod
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
Definition: prod.hpp:102
ViennaCLMatrix_impl
Definition: viennacl_private.hpp:113
ViennaCLVector_impl::inc
ViennaCLInt inc
Definition: viennacl_private.hpp:109
ViennaCLVector_impl
Definition: viennacl_private.hpp:94
viennacl_private.hpp
init_matrix.hpp
ViennaCLMatrix_impl::stride1
ViennaCLInt stride1
Definition: viennacl_private.hpp:131
ViennaCLUplo
ViennaCLUplo
Definition: viennacl.hpp:75
viennacl::linalg::upper_tag
A tag class representing an upper triangular matrix.
Definition: forwards.h:854
ViennaCLMatrix_impl::start2
ViennaCLInt start2
Definition: viennacl_private.hpp:135
ViennaCLMatrix_impl::size1
ViennaCLInt size1
Definition: viennacl_private.hpp:129
ViennaCLMatrix_impl::internal_size1
ViennaCLInt internal_size1
Definition: viennacl_private.hpp:132
viennacl::vector_base< float >
init_vector.hpp
ViennaCLGenericFailure
Definition: viennacl.hpp:100
direct_solve.hpp
Implementations of dense direct solvers are found here.
ViennaCLVector_impl::offset
ViennaCLInt offset
Definition: viennacl_private.hpp:108
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
ViennaCLHostScalar_impl
Definition: viennacl_private.hpp:67
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 ...
ViennaCLMatrix_impl::size2
ViennaCLInt size2
Definition: viennacl_private.hpp:134
ViennaCLRowMajor
Definition: viennacl.hpp:64
viennacl::backend::mem_handle
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:89
ViennaCLMatrix_impl::trans
ViennaCLTranspose trans
Definition: viennacl_private.hpp:118
ViennaCLger
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLger(ViennaCLHostScalar alpha, ViennaCLVector x, ViennaCLVector y, ViennaCLMatrix A)
Definition: blas2.cpp:177
ViennaCLUpper
Definition: viennacl.hpp:78
ViennaCLTrans
Definition: viennacl.hpp:72
scalar.hpp
Implementation of the ViennaCL scalar class.
viennacl.hpp
ViennaCLHostScalar_impl::value_double
double value_double
Definition: viennacl_private.hpp:73
ViennaCLFloat
Definition: viennacl.hpp:92
ViennaCLSuccess
Definition: viennacl.hpp:99
viennacl::vector_base::size_type
SizeT size_type
Definition: vector_def.hpp:112