All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
blas3.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_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 ViennaCLgemm(ViennaCLHostScalar alpha, ViennaCLMatrix A, ViennaCLMatrix B, ViennaCLHostScalar beta, ViennaCLMatrix C)
{
viennacl::backend::mem_handle A_handle;
viennacl::backend::mem_handle B_handle;
viennacl::backend::mem_handle C_handle;
if (init_matrix(A_handle, A) != ViennaCLSuccess)
return ViennaCLGenericFailure;
if (init_matrix(B_handle, B) != ViennaCLSuccess)
return ViennaCLGenericFailure;
if (init_matrix(C_handle, C) != ViennaCLSuccess)
return ViennaCLGenericFailure;
switch (A->precision)
{
case ViennaCLFloat:
{
typedef viennacl::matrix_base<float>::size_type size_type;
typedef viennacl::matrix_base<float>::size_type difference_type;
viennacl::matrix_base<float> mat_A(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);
viennacl::matrix_base<float> mat_B(B_handle,
size_type(B->size1), size_type(B->start1), difference_type(B->stride1), size_type(B->internal_size1),
size_type(B->size2), size_type(B->start2), difference_type(B->stride2), size_type(B->internal_size2), B->order == ViennaCLRowMajor);
viennacl::matrix_base<float> mat_C(C_handle,
size_type(C->size1), size_type(C->start1), difference_type(C->stride1), size_type(C->internal_size1),
size_type(C->size2), size_type(C->start2), difference_type(C->stride2), size_type(C->internal_size2), C->order == ViennaCLRowMajor);
if (A->trans == ViennaCLTrans && B->trans == ViennaCLTrans)
viennacl::linalg::prod_impl(viennacl::trans(mat_A), viennacl::trans(mat_B), mat_C, alpha->value_float, beta->value_float);
else if (A->trans == ViennaCLTrans && B->trans == ViennaCLNoTrans)
viennacl::linalg::prod_impl(viennacl::trans(mat_A), mat_B, mat_C, alpha->value_float, beta->value_float);
else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLTrans)
viennacl::linalg::prod_impl(mat_A, viennacl::trans(mat_B), mat_C, alpha->value_float, beta->value_float);
else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLNoTrans)
viennacl::linalg::prod_impl(mat_A, mat_B, mat_C, alpha->value_float, beta->value_float);
else
return ViennaCLGenericFailure;
return ViennaCLSuccess;
}
case ViennaCLDouble:
{
typedef viennacl::matrix_base<double>::size_type size_type;
typedef viennacl::matrix_base<double>::size_type difference_type;
viennacl::matrix_base<double> mat_A(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);
viennacl::matrix_base<double> mat_B(B_handle,
size_type(B->size1), size_type(B->start1), difference_type(B->stride1), size_type(B->internal_size1),
size_type(B->size2), size_type(B->start2), difference_type(B->stride2), size_type(B->internal_size2), B->order == ViennaCLRowMajor);
viennacl::matrix_base<double> mat_C(C_handle,
size_type(C->size1), size_type(C->start1), difference_type(C->stride1), size_type(C->internal_size1),
size_type(C->size2), size_type(C->start2), difference_type(C->stride2), size_type(C->internal_size2), C->order == ViennaCLRowMajor);
if (A->trans == ViennaCLTrans && B->trans == ViennaCLTrans)
viennacl::linalg::prod_impl(viennacl::trans(mat_A), viennacl::trans(mat_B), mat_C, alpha->value_double, beta->value_double);
else if (A->trans == ViennaCLTrans && B->trans == ViennaCLNoTrans)
viennacl::linalg::prod_impl(viennacl::trans(mat_A), mat_B, mat_C, alpha->value_double, beta->value_double);
else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLTrans)
viennacl::linalg::prod_impl(mat_A, viennacl::trans(mat_B), mat_C, alpha->value_double, beta->value_double);
else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLNoTrans)
viennacl::linalg::prod_impl(mat_A, mat_B, mat_C, alpha->value_double, beta->value_double);
else
return ViennaCLGenericFailure;
return ViennaCLSuccess;
}
default:
return ViennaCLGenericFailure;
}
}
// xTRSV
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLtrsm(ViennaCLMatrix A, ViennaCLUplo uplo, ViennaCLDiag diag, ViennaCLMatrix B)
{
viennacl::backend::mem_handle A_handle;
viennacl::backend::mem_handle B_handle;
if (init_matrix(A_handle, A) != ViennaCLSuccess)
return ViennaCLGenericFailure;
if (init_matrix(B_handle, B) != ViennaCLSuccess)
return ViennaCLGenericFailure;
switch (A->precision)
{
case ViennaCLFloat:
{
typedef viennacl::matrix_base<float>::size_type size_type;
typedef viennacl::matrix_base<float>::size_type difference_type;
viennacl::matrix_base<float> mat_A(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);
viennacl::matrix_base<float> mat_B(B_handle,
size_type(B->size1), size_type(B->start1), difference_type(B->stride1), size_type(B->internal_size1),
size_type(B->size2), size_type(B->start2), difference_type(B->stride2), size_type(B->internal_size2), B->order == ViennaCLRowMajor);
if (A->trans == ViennaCLTrans && B->trans == ViennaCLTrans)
{
if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::upper_tag());
else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::unit_upper_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::lower_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::unit_lower_tag());
else
return ViennaCLGenericFailure;
}
else if (A->trans == ViennaCLTrans && B->trans == ViennaCLNoTrans)
{
if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), mat_B, viennacl::linalg::upper_tag());
else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), mat_B, viennacl::linalg::unit_upper_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), mat_B, viennacl::linalg::lower_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), mat_B, viennacl::linalg::unit_lower_tag());
else
return ViennaCLGenericFailure;
}
else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLTrans)
{
if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::upper_tag());
else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::unit_upper_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::lower_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::unit_lower_tag());
else
return ViennaCLGenericFailure;
}
else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLNoTrans)
{
if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(mat_A, mat_B, viennacl::linalg::upper_tag());
else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(mat_A, mat_B, viennacl::linalg::unit_upper_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(mat_A, mat_B, viennacl::linalg::lower_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(mat_A, mat_B, viennacl::linalg::unit_lower_tag());
else
return ViennaCLGenericFailure;
}
return ViennaCLSuccess;
}
case ViennaCLDouble:
{
typedef viennacl::matrix_base<double>::size_type size_type;
typedef viennacl::matrix_base<double>::size_type difference_type;
viennacl::matrix_base<double> mat_A(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);
viennacl::matrix_base<double> mat_B(B_handle,
size_type(B->size1), size_type(B->start1), difference_type(B->stride1), size_type(B->internal_size1),
size_type(B->size2), size_type(B->start2), difference_type(B->stride2), size_type(B->internal_size2), B->order == ViennaCLRowMajor);
if (A->trans == ViennaCLTrans && B->trans == ViennaCLTrans)
{
if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::upper_tag());
else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::unit_upper_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::lower_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::unit_lower_tag());
else
return ViennaCLGenericFailure;
}
else if (A->trans == ViennaCLTrans && B->trans == ViennaCLNoTrans)
{
if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), mat_B, viennacl::linalg::upper_tag());
else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), mat_B, viennacl::linalg::unit_upper_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), mat_B, viennacl::linalg::lower_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), mat_B, viennacl::linalg::unit_lower_tag());
else
return ViennaCLGenericFailure;
}
else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLTrans)
{
if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::upper_tag());
else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::unit_upper_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::lower_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(viennacl::trans(mat_A), viennacl::trans(mat_B), viennacl::linalg::unit_lower_tag());
else
return ViennaCLGenericFailure;
}
else if (A->trans == ViennaCLNoTrans && B->trans == ViennaCLNoTrans)
{
if (uplo == ViennaCLUpper && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(mat_A, mat_B, viennacl::linalg::upper_tag());
else if (uplo == ViennaCLUpper && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(mat_A, mat_B, viennacl::linalg::unit_upper_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLNonUnit)
viennacl::linalg::inplace_solve(mat_A, mat_B, viennacl::linalg::lower_tag());
else if (uplo == ViennaCLLower && diag == ViennaCLUnit)
viennacl::linalg::inplace_solve(mat_A, mat_B, viennacl::linalg::unit_lower_tag());
else
return ViennaCLGenericFailure;
}
return ViennaCLSuccess;
}
default:
return ViennaCLGenericFailure;
}
}
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
ViennaCLNonUnit
Definition: viennacl.hpp:86
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
viennacl::matrix_base::size_type
SizeT size_type
Definition: matrix_def.hpp:112
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
ViennaCLUnit
Definition: viennacl.hpp:85
viennacl::matrix_base< float >
ViennaCLgemm
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLgemm(ViennaCLHostScalar alpha, ViennaCLMatrix A, ViennaCLMatrix B, ViennaCLHostScalar beta, ViennaCLMatrix C)
Definition: blas3.cpp:35
ViennaCLDouble
Definition: viennacl.hpp:93
ViennaCLDiag
ViennaCLDiag
Definition: viennacl.hpp:82
ViennaCLStatus
ViennaCLStatus
Definition: viennacl.hpp:97
ViennaCLMatrix_impl::internal_size2
ViennaCLInt internal_size2
Definition: viennacl_private.hpp:137
ViennaCLLower
Definition: viennacl.hpp:79
ViennaCLMatrix_impl::order
ViennaCLOrder order
Definition: viennacl_private.hpp:117
VIENNACL_EXPORTED_FUNCTION
#define VIENNACL_EXPORTED_FUNCTION
Definition: viennacl.hpp:40
ViennaCLMatrix_impl
Definition: viennacl_private.hpp:113
ViennaCLtrsm
VIENNACL_EXPORTED_FUNCTION ViennaCLStatus ViennaCLtrsm(ViennaCLMatrix A, ViennaCLUplo uplo, ViennaCLDiag diag, ViennaCLMatrix B)
Definition: blas3.cpp:118
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::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
ViennaCLGenericFailure
Definition: viennacl.hpp:100
direct_solve.hpp
Implementations of dense direct solvers are found here.
ViennaCLHostScalar_impl
Definition: viennacl_private.hpp:67
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::linalg::unit_lower_tag
A tag class representing a lower triangular matrix with unit diagonal.
Definition: forwards.h:859
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
ViennaCLNoTrans
Definition: viennacl.hpp:71
ViennaCLUpper
Definition: viennacl.hpp:78
ViennaCLMatrix_impl::precision
ViennaCLPrecision precision
Definition: viennacl_private.hpp:116
viennacl::linalg::prod_impl
void prod_impl(const matrix_base< NumericT > &mat, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
Definition: matrix_operations.hpp:438
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
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