ViennaCL - The Vienna Computing Library: viennacl/linalg/scalar_operations.hpp Source File

ViennaCL - The Vienna Computing Library 1.7.1 Free open-source GPU-accelerated linear algebra and solver library. |

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scalar_operations.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_SCALAR_OPERATIONS_HPP
2 #define VIENNACL_LINALG_SCALAR_OPERATIONS_HPP
3
4 /* =========================================================================
5 Copyright (c) 2010-2016, Institute for Microelectronics,
6 Institute for Analysis and Scientific Computing,
7 TU Wien.
8 Portions of this software are copyright by UChicago Argonne, LLC.
9
10 -----------------
11 ViennaCL - The Vienna Computing Library
12 -----------------
13
14 Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15
16 (A list of authors and contributors can be found in the manual)
17
18 License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20
25 #include "viennacl/forwards.h"
26 #include "viennacl/tools/tools.hpp"
27 #include "viennacl/meta/predicate.hpp"
28 #include "viennacl/meta/enable_if.hpp"
29 #include "viennacl/traits/size.hpp"
30 #include "viennacl/traits/start.hpp"
31 #include "viennacl/traits/handle.hpp"
32 #include "viennacl/traits/stride.hpp"
33 #include "viennacl/linalg/host_based/scalar_operations.hpp"
34
35 #ifdef VIENNACL_WITH_OPENCL
36 #include "viennacl/linalg/opencl/scalar_operations.hpp"
37 #endif
38
39 #ifdef VIENNACL_WITH_CUDA
40 #include "viennacl/linalg/cuda/scalar_operations.hpp"
41 #endif
42
43
44
45 namespace viennacl
46 {
47 namespace linalg
48 {
49
59 template<typename S1,
60 typename S2, typename ScalarType1>
61 typename viennacl::enable_if< viennacl::is_scalar<S1>::value
62 && viennacl::is_scalar<S2>::value
63 && viennacl::is_any_scalar<ScalarType1>::value
64 >::type
65 as(S1 & s1,
66 S2 const & s2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
67 {
68 switch (viennacl::traits::handle(s1).get_active_handle_id())
69 {
70 case viennacl::MAIN_MEMORY:
71 viennacl::linalg::host_based::as(s1, s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
72 break;
73 #ifdef VIENNACL_WITH_OPENCL
74 case viennacl::OPENCL_MEMORY:
75 viennacl::linalg::opencl::as(s1, s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
76 break;
77 #endif
78 #ifdef VIENNACL_WITH_CUDA
79 case viennacl::CUDA_MEMORY:
80 viennacl::linalg::cuda::as(s1, s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
81 break;
82 #endif
83 case viennacl::MEMORY_NOT_INITIALIZED:
84 throw memory_exception("not initialised!");
85 default:
86 throw memory_exception("not implemented");
87 }
88 }
89
90
105 template<typename S1,
106 typename S2, typename ScalarType1,
107 typename S3, typename ScalarType2>
108 typename viennacl::enable_if< viennacl::is_scalar<S1>::value
109 && viennacl::is_scalar<S2>::value
110 && viennacl::is_scalar<S3>::value
111 && viennacl::is_any_scalar<ScalarType1>::value
112 && viennacl::is_any_scalar<ScalarType2>::value
113 >::type
114 asbs(S1 & s1,
115 S2 const & s2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
116 S3 const & s3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
117 {
118 switch (viennacl::traits::handle(s1).get_active_handle_id())
119 {
120 case viennacl::MAIN_MEMORY:
121 viennacl::linalg::host_based::asbs(s1,
122 s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
123 s3, beta, len_beta, reciprocal_beta, flip_sign_beta);
124 break;
125 #ifdef VIENNACL_WITH_OPENCL
126 case viennacl::OPENCL_MEMORY:
127 viennacl::linalg::opencl::asbs(s1,
128 s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
129 s3, beta, len_beta, reciprocal_beta, flip_sign_beta);
130 break;
131 #endif
132 #ifdef VIENNACL_WITH_CUDA
133 case viennacl::CUDA_MEMORY:
134 viennacl::linalg::cuda::asbs(s1,
135 s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
136 s3, beta, len_beta, reciprocal_beta, flip_sign_beta);
137 break;
138 #endif
139 case viennacl::MEMORY_NOT_INITIALIZED:
140 throw memory_exception("not initialised!");
141 default:
142 throw memory_exception("not implemented");
143 }
144 }
145
146
161 template<typename S1,
162 typename S2, typename ScalarType1,
163 typename S3, typename ScalarType2>
164 typename viennacl::enable_if< viennacl::is_scalar<S1>::value
165 && viennacl::is_scalar<S2>::value
166 && viennacl::is_scalar<S3>::value
167 && viennacl::is_any_scalar<ScalarType1>::value
168 && viennacl::is_any_scalar<ScalarType2>::value
169 >::type
170 asbs_s(S1 & s1,
171 S2 const & s2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
172 S3 const & s3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
173 {
174 switch (viennacl::traits::handle(s1).get_active_handle_id())
175 {
176 case viennacl::MAIN_MEMORY:
177 viennacl::linalg::host_based::asbs_s(s1,
178 s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
179 s3, beta, len_beta, reciprocal_beta, flip_sign_beta);
180 break;
181 #ifdef VIENNACL_WITH_OPENCL
182 case viennacl::OPENCL_MEMORY:
183 viennacl::linalg::opencl::asbs_s(s1,
184 s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
185 s3, beta, len_beta, reciprocal_beta, flip_sign_beta);
186 break;
187 #endif
188 #ifdef VIENNACL_WITH_CUDA
189 case viennacl::CUDA_MEMORY:
190 viennacl::linalg::cuda::asbs_s(s1,
191 s2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
192 s3, beta, len_beta, reciprocal_beta, flip_sign_beta);
193 break;
194 #endif
195 case viennacl::MEMORY_NOT_INITIALIZED:
196 throw memory_exception("not initialised!");
197 default:
198 throw memory_exception("not implemented");
199 }
200 }
201
202
203
209 template<typename S1, typename S2>
210 typename viennacl::enable_if< viennacl::is_scalar<S1>::value
211 && viennacl::is_scalar<S2>::value
212 >::type
213 swap(S1 & s1, S2 & s2)
214 {
215 switch (viennacl::traits::handle(s1).get_active_handle_id())
216 {
217 case viennacl::MAIN_MEMORY:
218 viennacl::linalg::host_based::swap(s1, s2);
219 break;
220 #ifdef VIENNACL_WITH_OPENCL
221 case viennacl::OPENCL_MEMORY:
222 viennacl::linalg::opencl::swap(s1, s2);
223 break;
224 #endif
225 #ifdef VIENNACL_WITH_CUDA
226 case viennacl::CUDA_MEMORY:
227 viennacl::linalg::cuda::swap(s1, s2);
228 break;
229 #endif
230 case viennacl::MEMORY_NOT_INITIALIZED:
231 throw memory_exception("not initialised!");
232 default:
233 throw memory_exception("not implemented");
234 }
235 }
236
237
238 } //namespace linalg
239 } //namespace viennacl
240
241
242 #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