All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scalar_operations.hpp
Go to the documentation of this file.
#ifndef VIENNACL_LINALG_SCALAR_OPERATIONS_HPP
#define VIENNACL_LINALG_SCALAR_OPERATIONS_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 "viennacl/forwards.h"
#include "viennacl/tools/tools.hpp"
#include "viennacl/meta/predicate.hpp"
#include "viennacl/meta/enable_if.hpp"
#include "viennacl/traits/size.hpp"
#include "viennacl/traits/start.hpp"
#include "viennacl/traits/handle.hpp"
#include "viennacl/traits/stride.hpp"
#include "viennacl/linalg/host_based/scalar_operations.hpp"
#ifdef VIENNACL_WITH_OPENCL
#include "viennacl/linalg/opencl/scalar_operations.hpp"
#endif
#ifdef VIENNACL_WITH_CUDA
#include "viennacl/linalg/cuda/scalar_operations.hpp"
#endif
namespace viennacl
{
namespace linalg
{
template<typename S1,
typename S2, typename ScalarType1>
typename viennacl::enable_if< viennacl::is_scalar<S1>::value
&& viennacl::is_scalar<S2>::value
&& viennacl::is_any_scalar<ScalarType1>::value
>::type
as(S1 & s1,
S2 const & s2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
{
switch (viennacl::traits::handle(s1).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::as(s1, s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::as(s1, s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::as(s1, s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename S1,
typename S2, typename ScalarType1,
typename S3, typename ScalarType2>
typename viennacl::enable_if< viennacl::is_scalar<S1>::value
&& viennacl::is_scalar<S2>::value
&& viennacl::is_scalar<S3>::value
&& viennacl::is_any_scalar<ScalarType1>::value
&& viennacl::is_any_scalar<ScalarType2>::value
>::type
asbs(S1 & s1,
S2 const & s2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
S3 const & s3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
{
switch (viennacl::traits::handle(s1).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::asbs(s1,
s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
s3, beta, len_beta, reciprocal_beta, flip_sign_beta);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::asbs(s1,
s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
s3, beta, len_beta, reciprocal_beta, flip_sign_beta);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::asbs(s1,
s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
s3, beta, len_beta, reciprocal_beta, flip_sign_beta);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename S1,
typename S2, typename ScalarType1,
typename S3, typename ScalarType2>
typename viennacl::enable_if< viennacl::is_scalar<S1>::value
&& viennacl::is_scalar<S2>::value
&& viennacl::is_scalar<S3>::value
&& viennacl::is_any_scalar<ScalarType1>::value
&& viennacl::is_any_scalar<ScalarType2>::value
>::type
asbs_s(S1 & s1,
S2 const & s2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
S3 const & s3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
{
switch (viennacl::traits::handle(s1).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::asbs_s(s1,
s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
s3, beta, len_beta, reciprocal_beta, flip_sign_beta);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::asbs_s(s1,
s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
s3, beta, len_beta, reciprocal_beta, flip_sign_beta);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::asbs_s(s1,
s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
s3, beta, len_beta, reciprocal_beta, flip_sign_beta);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename S1, typename S2>
typename viennacl::enable_if< viennacl::is_scalar<S1>::value
&& viennacl::is_scalar<S2>::value
>::type
swap(S1 & s1, S2 & s2)
{
switch (viennacl::traits::handle(s1).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::swap(s1, s2);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::swap(s1, s2);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::swap(s1, s2);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
} //namespace linalg
} //namespace viennacl
#endif
viennacl::enable_if
Simple enable-if variant that uses the SFINAE pattern.
Definition: enable_if.hpp:30
viennacl::linalg::as
viennacl::enable_if< viennacl::is_scalar< S1 >::value &&viennacl::is_scalar< S2 >::value &&viennacl::is_any_scalar< ScalarType1 >::value >::type as(S1 &s1, S2 const &s2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Interface for the generic operation s1 = s2 @ alpha, where s1 and s2 are GPU scalars, @ denotes multiplication or division, and alpha is either a GPU or a CPU scalar.
Definition: scalar_operations.hpp:65
scalar_operations.hpp
Implementations of scalar operations using OpenCL.
viennacl::memory_exception
Exception class in case of memory errors.
Definition: forwards.h:572
size.hpp
Generic size and resize functionality for different vector and matrix types.
viennacl::linalg::opencl::swap
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value >::type swap(ScalarT1 &s1, ScalarT2 &s2)
Swaps the contents of two scalars, data is copied.
Definition: scalar_operations.hpp:182
start.hpp
Extracts the underlying OpenCL start index handle from a vector, a matrix, an expression etc...
tools.hpp
Various little tools used here and there in ViennaCL.
viennacl::linalg::host_based::swap
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value >::type swap(ScalarT1 &s1, ScalarT2 &s2)
Swaps the contents of two scalars, data is copied.
Definition: scalar_operations.hpp:143
viennacl::OPENCL_MEMORY
Definition: forwards.h:349
scalar_operations.hpp
Implementations of scalar operations using CUDA.
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
stride.hpp
Determines row and column increments for matrices and matrix proxies.
scalar_operations.hpp
Implementations of scalar operations using a plain single-threaded or OpenMP-enabled execution on CPU...
s2
viennacl::scalar< int > s2
Definition: global_variables.cpp:58
s1
viennacl::scalar< float > s1
Definition: global_variables.cpp:57
viennacl::linalg::cuda::asbs
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value &&viennacl::is_scalar< ScalarT3 >::value &&viennacl::is_any_scalar< NumericT1 >::value &&viennacl::is_any_scalar< NumericT2 >::value >::type asbs(ScalarT1 &s1, ScalarT2 const &s2, NumericT1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, ScalarT3 const &s3, NumericT2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: scalar_operations.hpp:191
viennacl::linalg::opencl::asbs_s
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value &&viennacl::is_scalar< ScalarT3 >::value &&viennacl::is_any_scalar< NumericT2 >::value &&viennacl::is_any_scalar< NumericT3 >::value >::type asbs_s(ScalarT1 &s1, ScalarT2 const &s2, NumericT2 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, ScalarT3 const &s3, NumericT3 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: scalar_operations.hpp:135
viennacl::MEMORY_NOT_INITIALIZED
Definition: forwards.h:347
viennacl::CUDA_MEMORY
Definition: forwards.h:350
viennacl::linalg::swap
viennacl::enable_if< viennacl::is_scalar< S1 >::value &&viennacl::is_scalar< S2 >::value >::type swap(S1 &s1, S2 &s2)
Swaps the contents of two scalars.
Definition: scalar_operations.hpp:213
viennacl::is_any_scalar
Helper struct for checking whether the provided type represents a scalar (either host, from ViennaCL, or a flip-sign proxy)
Definition: forwards.h:469
viennacl::linalg::host_based::asbs
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value &&viennacl::is_scalar< ScalarT3 >::value &&viennacl::is_any_scalar< FactorT2 >::value &&viennacl::is_any_scalar< FactorT3 >::value >::type asbs(ScalarT1 &s1, ScalarT2 const &s2, FactorT2 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, ScalarT3 const &s3, FactorT3 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)
Definition: scalar_operations.hpp:73
viennacl::linalg::host_based::as
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value &&viennacl::is_any_scalar< FactorT >::value >::type as(ScalarT1 &s1, ScalarT2 const &s2, FactorT const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: scalar_operations.hpp:46
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
viennacl::linalg::asbs
viennacl::enable_if< viennacl::is_scalar< S1 >::value &&viennacl::is_scalar< S2 >::value &&viennacl::is_scalar< S3 >::value &&viennacl::is_any_scalar< ScalarType1 >::value &&viennacl::is_any_scalar< ScalarType2 >::value >::type asbs(S1 &s1, S2 const &s2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, S3 const &s3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Interface for the generic operation s1 = s2 @ alpha + s3 @ beta, where s1, s2 and s3 are GPU scalars...
Definition: scalar_operations.hpp:114
viennacl::linalg::opencl::asbs
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value &&viennacl::is_scalar< ScalarT3 >::value &&viennacl::is_any_scalar< NumericT2 >::value &&viennacl::is_any_scalar< NumericT3 >::value >::type asbs(ScalarT1 &s1, ScalarT2 const &s2, NumericT2 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, ScalarT3 const &s3, NumericT3 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: scalar_operations.hpp:86
viennacl::linalg::cuda::swap
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value >::type swap(ScalarT1 &s1, ScalarT2 &s2)
Swaps the contents of two scalars, data is copied.
Definition: scalar_operations.hpp:361
viennacl::linalg::cuda::asbs_s
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value &&viennacl::is_scalar< ScalarT3 >::value &&viennacl::is_any_scalar< NumericT1 >::value &&viennacl::is_any_scalar< NumericT2 >::value >::type asbs_s(ScalarT1 &s1, ScalarT2 const &s2, NumericT1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, ScalarT3 const &s3, NumericT2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: scalar_operations.hpp:314
viennacl::linalg::opencl::as
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value &&viennacl::is_any_scalar< NumericT >::value >::type as(ScalarT1 &s1, ScalarT2 const &s2, NumericT const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: scalar_operations.hpp:54
predicate.hpp
All the predicates used within ViennaCL. Checks for expressions to be vectors, etc.
viennacl::MAIN_MEMORY
Definition: forwards.h:348
viennacl::linalg::asbs_s
viennacl::enable_if< viennacl::is_scalar< S1 >::value &&viennacl::is_scalar< S2 >::value &&viennacl::is_scalar< S3 >::value &&viennacl::is_any_scalar< ScalarType1 >::value &&viennacl::is_any_scalar< ScalarType2 >::value >::type asbs_s(S1 &s1, S2 const &s2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, S3 const &s3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Interface for the generic operation s1 += s2 @ alpha + s3 @ beta, where s1, s2 and s3 are GPU scalars...
Definition: scalar_operations.hpp:170
viennacl::is_scalar
Helper struct for checking whether a type is a viennacl::scalar<>
Definition: forwards.h:455
viennacl::linalg::cuda::as
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value &&viennacl::is_any_scalar< NumericT >::value >::type as(ScalarT1 &s1, ScalarT2 const &s2, NumericT const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: scalar_operations.hpp:77
handle.hpp
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
viennacl::traits::handle
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
enable_if.hpp
Simple enable-if variant that uses the SFINAE pattern.
viennacl::linalg::host_based::asbs_s
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value &&viennacl::is_scalar< ScalarT3 >::value &&viennacl::is_any_scalar< FactorT2 >::value &&viennacl::is_any_scalar< FactorT3 >::value >::type asbs_s(ScalarT1 &s1, ScalarT2 const &s2, FactorT2 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, ScalarT3 const &s3, FactorT3 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)
Definition: scalar_operations.hpp:108