All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
execute_matrix_dispatcher.hpp
Go to the documentation of this file.
#ifndef VIENNACL_SCHEDULER_EXECUTE_MATRIX_DISPATCHER_HPP
#define VIENNACL_SCHEDULER_EXECUTE_MATRIX_DISPATCHER_HPP
/* =========================================================================
Copyright (c) 2010-2016, 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 manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
#include <assert.h>
#include "viennacl/forwards.h"
#include "viennacl/scheduler/forwards.h"
#include "viennacl/scheduler/execute_util.hpp"
#include "viennacl/linalg/matrix_operations.hpp"
namespace viennacl
{
namespace scheduler
{
namespace detail
{
template<typename ScalarType1>
void am(lhs_rhs_element & mat1,
lhs_rhs_element const & mat2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
{
assert( mat1.type_family == MATRIX_TYPE_FAMILY && mat2.type_family == MATRIX_TYPE_FAMILY
&& bool("Arguments are not matrix types!"));
assert(mat1.numeric_type == mat2.numeric_type && bool("Matrices do not have the same scalar type"));
if (mat1.subtype == DENSE_MATRIX_TYPE)
{
switch (mat1.numeric_type)
{
case FLOAT_TYPE:
viennacl::linalg::am(*mat1.matrix_float,
*mat2.matrix_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha);
break;
case DOUBLE_TYPE:
viennacl::linalg::am(*mat1.matrix_double,
*mat2.matrix_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha);
break;
default:
throw statement_not_supported_exception("Invalid arguments in scheduler when calling am()");
}
}
else
throw statement_not_supported_exception("Invalid arguments in scheduler when calling am()");
}
template<typename ScalarType1, typename ScalarType2>
void ambm(lhs_rhs_element & mat1,
lhs_rhs_element const & mat2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
lhs_rhs_element const & mat3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
{
assert( mat1.type_family == MATRIX_TYPE_FAMILY
&& mat2.type_family == MATRIX_TYPE_FAMILY
&& mat3.type_family == MATRIX_TYPE_FAMILY
&& bool("Arguments are not matrix types!"));
assert( (mat1.subtype == mat2.subtype)
&& (mat2.subtype == mat3.subtype)
&& bool("Matrices do not have the same layout"));
assert( (mat1.numeric_type == mat2.numeric_type)
&& (mat2.numeric_type == mat3.numeric_type)
&& bool("Matrices do not have the same scalar type"));
if (mat1.subtype == DENSE_MATRIX_TYPE)
{
switch (mat1.numeric_type)
{
case FLOAT_TYPE:
viennacl::linalg::ambm(*mat1.matrix_float,
*mat2.matrix_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
*mat3.matrix_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta);
break;
case DOUBLE_TYPE:
viennacl::linalg::ambm(*mat1.matrix_double,
*mat2.matrix_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
*mat3.matrix_double, convert_to_double(beta), len_beta, reciprocal_beta, flip_sign_beta);
break;
default:
throw statement_not_supported_exception("Invalid arguments in scheduler when calling ambm()");
}
}
else
throw statement_not_supported_exception("Invalid arguments in scheduler when calling ambm()");
}
template<typename ScalarType1, typename ScalarType2>
void ambm_m(lhs_rhs_element & mat1,
lhs_rhs_element const & mat2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
lhs_rhs_element const & mat3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
{
assert( mat1.type_family == MATRIX_TYPE_FAMILY
&& mat2.type_family == MATRIX_TYPE_FAMILY
&& mat3.type_family == MATRIX_TYPE_FAMILY
&& bool("Arguments are not matrix types!"));
assert( (mat1.subtype == mat2.subtype)
&& (mat2.subtype == mat3.subtype)
&& bool("Matrices do not have the same layout"));
assert( (mat1.numeric_type == mat2.numeric_type)
&& (mat2.numeric_type == mat3.numeric_type)
&& bool("Matrices do not have the same scalar type"));
if (mat1.subtype == DENSE_MATRIX_TYPE)
{
switch (mat1.numeric_type)
{
case FLOAT_TYPE:
viennacl::linalg::ambm_m(*mat1.matrix_float,
*mat2.matrix_float, convert_to_float(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
*mat3.matrix_float, convert_to_float(beta), len_beta, reciprocal_beta, flip_sign_beta);
break;
case DOUBLE_TYPE:
viennacl::linalg::ambm_m(*mat1.matrix_double,
*mat2.matrix_double, convert_to_double(alpha), len_alpha, reciprocal_alpha, flip_sign_alpha,
*mat3.matrix_double, convert_to_double(beta), len_beta, reciprocal_beta, flip_sign_beta);
break;
default:
throw statement_not_supported_exception("Invalid arguments in scheduler when calling ambm_m()");
}
}
else
throw statement_not_supported_exception("Invalid arguments in scheduler when calling ambm_m()");
}
inline void assign_trans(lhs_rhs_element const & A,
lhs_rhs_element const & B)
{
assert( A.type_family == MATRIX_TYPE_FAMILY && B.type_family == MATRIX_TYPE_FAMILY
&& bool("Arguments are not matrix types!"));
assert(A.numeric_type == B.numeric_type && bool("Matrices do not have the same scalar type"));
if (A.subtype == DENSE_MATRIX_TYPE)
{
switch (A.numeric_type)
{
case FLOAT_TYPE:
*A.matrix_float = viennacl::trans(*B.matrix_float);
break;
case DOUBLE_TYPE:
*A.matrix_double = viennacl::trans(*B.matrix_double);
break;
default:
throw statement_not_supported_exception("Invalid arguments in scheduler when calling assign_trans()");
}
}
else
throw statement_not_supported_exception("Invalid arguments in scheduler when calling assign_trans()");
}
} // namespace detail
} // namespace scheduler
} // namespace viennacl
#endif
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
matrix_operations.hpp
Implementations of dense matrix related operations including matrix-vector products.
viennacl::scheduler::detail::assign_trans
void assign_trans(lhs_rhs_element const &A, lhs_rhs_element const &B)
Scheduler unwrapper for A =/+=/-= trans(B)
Definition: execute_matrix_dispatcher.hpp:154
viennacl::scheduler::DOUBLE_TYPE
Definition: forwards.h:300
viennacl::linalg::am
void am(matrix_base< NumericT > &mat1, matrix_base< NumericT > const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: matrix_operations.hpp:111
viennacl::scheduler::detail::ambm
void ambm(lhs_rhs_element &mat1, lhs_rhs_element const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, lhs_rhs_element const &mat3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Wrapper for viennacl::linalg::avbv(), taking care of the argument unwrapping.
Definition: execute_matrix_dispatcher.hpp:73
viennacl::scheduler::detail::convert_to_double
double convert_to_double(float d)
Definition: execute_util.hpp:89
viennacl::scheduler::lhs_rhs_element::subtype
statement_node_subtype subtype
Definition: forwards.h:340
viennacl::linalg::ambm
void ambm(matrix_base< NumericT > &mat1, matrix_base< NumericT > const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, matrix_base< NumericT > const &mat3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: matrix_operations.hpp:139
viennacl::scheduler::MATRIX_TYPE_FAMILY
Definition: forwards.h:260
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::scheduler::lhs_rhs_element::type_family
statement_node_type_family type_family
Definition: forwards.h:339
viennacl::scheduler::lhs_rhs_element
A class representing the 'data' for the LHS or RHS operand of the respective node.
Definition: forwards.h:337
viennacl::scheduler::detail::am
void am(lhs_rhs_element &mat1, lhs_rhs_element const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Wrapper for viennacl::linalg::av(), taking care of the argument unwrapping.
Definition: execute_matrix_dispatcher.hpp:42
viennacl::scheduler::lhs_rhs_element::matrix_double
viennacl::matrix_base< double > * matrix_double
Definition: forwards.h:410
viennacl::scheduler::DENSE_MATRIX_TYPE
Definition: forwards.h:274
viennacl::scheduler::lhs_rhs_element::numeric_type
statement_node_numeric_type numeric_type
Definition: forwards.h:341
viennacl::scheduler::lhs_rhs_element::matrix_float
viennacl::matrix_base< float > * matrix_float
Definition: forwards.h:409
viennacl::scheduler::detail::ambm_m
void ambm_m(lhs_rhs_element &mat1, lhs_rhs_element const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, lhs_rhs_element const &mat3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Wrapper for viennacl::linalg::avbv_v(), taking care of the argument unwrapping.
Definition: execute_matrix_dispatcher.hpp:114
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
forwards.h
Provides the datastructures for dealing with a single statement such as 'x = y + z;'.
viennacl::scheduler::detail::convert_to_float
float convert_to_float(float f)
Definition: execute_util.hpp:76
viennacl::scheduler::FLOAT_TYPE
Definition: forwards.h:299
viennacl::linalg::ambm_m
void ambm_m(matrix_base< NumericT > &mat1, matrix_base< NumericT > const &mat2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, matrix_base< NumericT > const &mat3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: matrix_operations.hpp:174
execute_util.hpp
Provides various utilities for implementing the execution of statements.
viennacl::scheduler::statement_not_supported_exception
Exception for the case the scheduler is unable to deal with the operation.
Definition: forwards.h:38