All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
blas2_host.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 basic scalar and vector types of ViennaCL
#include "viennacl/scalar.hpp"
#include "viennacl/vector.hpp"
#include "viennacl/vector.hpp"
#include "viennacl/matrix.hpp"
#include "viennacl/linalg/direct_solve.hpp"
#include "viennacl/linalg/prod.hpp"
// xGEMV
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSgemv(ViennaCLBackend /*backend*/,
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)
{
typedef viennacl::vector_base<float>::size_type size_type;
typedef viennacl::vector_base<float>::size_type difference_type;
viennacl::vector_base<float> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::vector_base<float> v2(y, viennacl::MAIN_MEMORY, size_type(m), size_type(offy), difference_type(incy));
viennacl::matrix_base<float> mat(A, viennacl::MAIN_MEMORY,
size_type(m), size_type(offA_row), difference_type(incA_row), size_type(m),
size_type(n), size_type(offA_col), difference_type(incA_col), size_type(lda), order == ViennaCLRowMajor);
v2 *= beta;
if (transA == ViennaCLTrans)
v2 += alpha * viennacl::linalg::prod(viennacl::trans(mat), v1);
else
v2 += alpha * viennacl::linalg::prod(mat, v1);
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDgemv(ViennaCLBackend /*backend*/,
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)
{
typedef viennacl::vector_base<double>::size_type size_type;
typedef viennacl::vector_base<double>::size_type difference_type;
viennacl::vector_base<double> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::vector_base<double> v2(y, viennacl::MAIN_MEMORY, size_type(m), size_type(offy), difference_type(incy));
viennacl::matrix_base<double> mat(A, viennacl::MAIN_MEMORY,
size_type(m), size_type(offA_row), difference_type(incA_row), size_type(m),
size_type(n), size_type(offA_col), difference_type(incA_col), size_type(lda), order == ViennaCLRowMajor);
v2 *= beta;
if (transA == ViennaCLTrans)
v2 += alpha * viennacl::linalg::prod(viennacl::trans(mat), v1);
else
v2 += alpha * viennacl::linalg::prod(mat, v1);
return ViennaCLSuccess;
}
// xTRSV
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostStrsv(ViennaCLBackend /*backend*/,
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)
{
typedef viennacl::vector_base<float>::size_type size_type;
typedef viennacl::vector_base<float>::size_type difference_type;
viennacl::vector_base<float> v(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::matrix_base<float> mat(A, viennacl::MAIN_MEMORY,
size_type(n), size_type(offA_row), difference_type(incA_row), size_type(n),
size_type(n), size_type(offA_col), difference_type(incA_col), size_type(lda), order == ViennaCLRowMajor);
if (transA == ViennaCLTrans)
{
if (uplo == ViennaCLUpper)
if (diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::unit_upper_tag());
else
viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::upper_tag());
else
if (diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::unit_lower_tag());
else
viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::lower_tag());
}
else
{
if (uplo == ViennaCLUpper)
if (diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::unit_upper_tag());
else
viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::upper_tag());
else
if (diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::unit_lower_tag());
else
viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::lower_tag());
}
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDtrsv(ViennaCLBackend /*backend*/,
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)
{
typedef viennacl::vector_base<double>::size_type size_type;
typedef viennacl::vector_base<double>::size_type difference_type;
viennacl::vector_base<double> v(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::matrix_base<double> mat(A, viennacl::MAIN_MEMORY,
size_type(n), size_type(offA_row), difference_type(incA_row), size_type(n),
size_type(n), size_type(offA_col), difference_type(incA_col), size_type(lda), order == ViennaCLRowMajor);
if (transA == ViennaCLTrans)
{
if (uplo == ViennaCLUpper)
if (diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::unit_upper_tag());
else
viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::upper_tag());
else
if (diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::unit_lower_tag());
else
viennacl::linalg::inplace_solve(viennacl::trans(mat), v, viennacl::linalg::lower_tag());
}
else
{
if (uplo == ViennaCLUpper)
if (diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::unit_upper_tag());
else
viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::upper_tag());
else
if (diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::unit_lower_tag());
else
viennacl::linalg::inplace_solve(mat, v, viennacl::linalg::lower_tag());
}
return ViennaCLSuccess;
}
// xGER
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostSger(ViennaCLBackend /*backend*/,
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)
{
typedef viennacl::vector_base<float>::size_type size_type;
typedef viennacl::vector_base<float>::size_type difference_type;
viennacl::vector_base<float> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::vector_base<float> v2(y, viennacl::MAIN_MEMORY, size_type(m), size_type(offy), difference_type(incy));
viennacl::matrix_base<float> mat(A, viennacl::MAIN_MEMORY,
size_type(m), size_type(offA_row), difference_type(incA_row), size_type(m),
size_type(n), size_type(offA_col), difference_type(incA_col), size_type(lda), order == ViennaCLRowMajor);
mat += alpha * viennacl::linalg::outer_prod(v1, v2);
return ViennaCLSuccess;
}
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLHostDger(ViennaCLBackend /*backend*/,
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)
{
typedef viennacl::vector_base<double>::size_type size_type;
typedef viennacl::vector_base<double>::size_type difference_type;
viennacl::vector_base<double> v1(x, viennacl::MAIN_MEMORY, size_type(n), size_type(offx), difference_type(incx));
viennacl::vector_base<double> v2(y, viennacl::MAIN_MEMORY, size_type(m), size_type(offy), difference_type(incy));
viennacl::matrix_base<double> mat(A, viennacl::MAIN_MEMORY,
size_type(m), size_type(offA_row), difference_type(incA_row), size_type(m),
size_type(n), size_type(offA_col), difference_type(incA_col), size_type(lda), order == ViennaCLRowMajor);
mat += alpha * viennacl::linalg::outer_prod(v1, v2);
return ViennaCLSuccess;
}
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