1 #ifndef VIENNACL_LINALG_OPENCL_VECTOR_OPERATIONS_HPP_
2 #define VIENNACL_LINALG_OPENCL_VECTOR_OPERATIONS_HPP_
54 template<
typename NumericT,
typename ScalarT1>
58 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(y).
context() &&
bool(
"Vectors do not reside in the same OpenCL context. Automatic migration not yet supported!"));
59 std::string kernel_name(
"assign_*v_**00");
61 kernel_name[7] = is_scalar_cpu ?
'h' :
'd';
62 kernel_name[10] = flip_sign_alpha ?
'1' :
'0';
63 kernel_name[11] = reciprocal_alpha ?
'1' :
'0';
70 template<
typename NumericT,
typename ScalarT1,
typename ScalarT2>
75 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(y).
context() &&
bool(
"Vectors do not reside in the same OpenCL context. Automatic migration not yet supported!"));
76 assert(viennacl::traits::opencl_handle(y).
context() == viennacl::traits::opencl_handle(z).
context() &&
bool(
"Vectors do not reside in the same OpenCL context. Automatic migration not yet supported!"));
78 std::string kernel_name(
"assign_*v*v_****");
81 kernel_name[7] = is_scalar_cpu1 ?
'h' :
'd';
82 kernel_name[9] = is_scalar_cpu2 ?
'h' :
'd';
83 kernel_name[12] = flip_sign_alpha ?
'1' :
'0';
84 kernel_name[13] = reciprocal_alpha ?
'1' :
'0';
85 kernel_name[14] = flip_sign_beta ?
'1' :
'0';
86 kernel_name[15] = reciprocal_beta ?
'1' :
'0';
93 template<
typename NumericT,
typename ScalarT1,
typename ScalarT2>
98 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(y).
context() &&
bool(
"Vectors do not reside in the same OpenCL context. Automatic migration not yet supported!"));
99 assert(viennacl::traits::opencl_handle(y).
context() == viennacl::traits::opencl_handle(z).
context() &&
bool(
"Vectors do not reside in the same OpenCL context. Automatic migration not yet supported!"));
101 std::string kernel_name(
"ip_add_*v*v_****");
104 kernel_name[7] = is_scalar_cpu1 ?
'h' :
'd';
105 kernel_name[9] = is_scalar_cpu2 ?
'h' :
'd';
106 kernel_name[12] = flip_sign_alpha ?
'1' :
'0';
107 kernel_name[13] = reciprocal_alpha ?
'1' :
'0';
108 kernel_name[14] = flip_sign_beta ?
'1' :
'0';
109 kernel_name[15] = reciprocal_beta ?
'1' :
'0';
122 template<
typename NumericT>
138 template<
typename NumericT>
141 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(y).
context() &&
bool(
"Vectors do not reside in the same OpenCL context. Automatic migration not yet supported!"));
153 template<
typename NumericT,
typename OP>
157 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(proxy.lhs()).
context() && bool(
"Vectors do not reside in the same OpenCL context. Automatic migration not yet supported!"));
158 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(proxy.rhs()).
context() && bool(
"Vectors do not reside in the same OpenCL context. Automatic migration not yet supported!"));
172 template<
typename NumericT,
typename OP>
176 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(proxy.lhs()).
context() && bool(
"Vectors do not reside in the same OpenCL context. Automatic migration not yet supported!"));
177 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(proxy.rhs()).
context() && bool(
"Vectors do not reside in the same OpenCL context. Automatic migration not yet supported!"));
193 template<
typename NumericT>
198 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(y).
context() &&
bool(
"Vectors do not reside in the same OpenCL context. Automatic migration not yet supported!"));
199 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(result).
context() &&
bool(
"Operands do not reside in the same OpenCL context. Automatic migration not yet supported!"));
207 template<
typename NumericT>
225 template<
typename NumericT>
230 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(result).
context() &&
bool(
"Operands do not reside in the same OpenCL context. Automatic migration not yet supported!"));
234 while (current_index < vec_tuple.
const_size())
240 std::string kernel_prefix;
241 if (diff>=8) upper_bound = 8, kernel_prefix =
"inner_prod_8";
242 else if (diff>=4) upper_bound = 4, kernel_prefix =
"inner_prod_4";
243 else if (diff>=3) upper_bound = 3, kernel_prefix =
"inner_prod_3";
244 else if (diff>=2) upper_bound = 2, kernel_prefix =
"inner_prod_2";
245 else upper_bound = 1, kernel_prefix =
"inner_prod_1";
247 std::vector<range_t> ranges;
248 ranges.reserve(upper_bound);
249 for (
unsigned int i = 0; i < upper_bound; ++i)
250 ranges.push_back(range_t(result,
viennacl::range(current_index+i, current_index+i+1)));
252 for (
unsigned int i = 0; i < upper_bound; ++i)
256 current_index += upper_bound;
261 template<
typename NumericT>
279 template<
typename NumericT>
283 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(result).
context() &&
bool(
"Operands do not reside in the same OpenCL context. Automatic migration not yet supported!"));
294 template<
typename NumericT>
313 template<
typename NumericT>
317 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(result).
context() &&
bool(
"Operands do not reside in the same OpenCL context. Automatic migration not yet supported!"));
328 template<
typename NumericT>
346 template<
typename NumericT>
350 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(result).
context() &&
bool(
"Operands do not reside in the same OpenCL context. Automatic migration not yet supported!"));
361 template<
typename NumericT>
381 template<
typename NumericT>
387 NumericT host_result = result;
388 return static_cast<cl_uint
>(host_result);
398 template<
typename NumericT>
402 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(result).
context() &&
bool(
"Operands do not reside in the same OpenCL context. Automatic migration not yet supported!"));
413 template<
typename NumericT>
430 template<
typename NumericT>
434 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(result).
context() &&
bool(
"Operands do not reside in the same OpenCL context. Automatic migration not yet supported!"));
445 template<
typename NumericT>
466 template<
typename NumericT>
469 NumericT alpha, NumericT beta)
471 assert(viennacl::traits::opencl_handle(x).
context() == viennacl::traits::opencl_handle(y).
context() &&
bool(
"Operands do not reside in the same OpenCL context. Automatic migration not yet supported!"));
void min_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the supremum-norm of a vector.
cl_uint stride
Increment between integers.
void norm_2_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the l^1-norm of a vector with final reduction on CPU.
vcl_size_t const_size() const
static device_specific::execution_handler & execution_handler(viennacl::ocl::context &ctx)
Helper class for packing four cl_uint numbers into a uint4 type for access inside an OpenCL kernel...
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
void norm_1_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the l^1-norm of a vector with final reduction on CPU.
Represents an OpenCL device within ViennaCL.
void inner_prod_cpu(vector_base< NumericT > const &x, vector_base< NumericT > const &y, NumericT &result)
Generic size and resize functionality for different vector and matrix types.
void plane_rotation(vector_base< NumericT > &x, vector_base< NumericT > &y, NumericT alpha, NumericT beta)
Computes a plane rotation of two vectors.
void norm_inf_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the supremum-norm of a vector.
Extracts the underlying OpenCL start index handle from a vector, a matrix, an expression etc...
statement inner_prod(ScalarT const *s, vector_base< NumericT > const *x, vector_base< NumericT > const *y)
cl_uint start
Starting value of the integer stride.
cl_uint index_norm_inf(vector_base< NumericT > const &x)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
void norm_1_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the l^1-norm of a vector.
void avbv_v(vector_base< NumericT > &x, vector_base< NumericT > const &y, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< NumericT > const &z, ScalarT2 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)
result_of::size_type< viennacl::vector_base< T > >::type stride(viennacl::vector_base< T > const &s)
This file provides the forward declarations for the main types used within ViennaCL.
Determines row and column increments for matrices and matrix proxies.
void min_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the minimum of a vector.
statement max(scalar< NumericT > const *s, vector_base< NumericT > const *x)
vcl_size_t internal_size(vector_base< NumericT > const &vec)
Helper routine for obtaining the buffer length of a ViennaCL vector.
An expression template class that represents a binary operation that yields a vector.
scheduler::statement avbv(scheduler::operation_node_type ASSIGN_OP, NumericT const *x, NumericT const *y, ScalarT1 const *a, bool flip_a, bool reciprocal_a, NumericT const *z, ScalarT2 const *b, bool flip_b, bool reciprocal_b)
statement norm_2(scalar< NumericT > const *s, vector_base< NumericT > const *x)
static device_specific::execution_handler & execution_handler(viennacl::ocl::context &ctx)
void vector_assign(vector_base< NumericT > &x, const NumericT &alpha, bool up_to_internal_size=false)
Assign a constant value to a vector (-range/-slice)
cl_uint internal_size
Internal length of the buffer. Might be larger than 'size' due to padding.
Common implementations shared by OpenCL-based operations.
void element_op(matrix_base< NumericT > &A, matrix_expression< const matrix_base< NumericT >, const matrix_base< NumericT >, op_element_binary< OpT > > const &proxy)
Implementation of binary element-wise operations A = OP(B,C)
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
statement min(scalar< NumericT > const *s, vector_base< NumericT > const *x)
statement binary_element_op(NumericT const *x, NumericT const *y, NumericT const *z, scheduler::operation_node_type TYPE)
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
void max_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the maximum of a vector.
Helper struct for checking whether a type is a host scalar type (e.g. float, double) ...
Class for representing non-strided subvectors of a bigger vector x.
void max_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the supremum-norm of a vector.
Tuple class holding pointers to multiple vectors. Mainly used as a temporary object returned from vie...
void norm_2_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the l^2-norm of a vector - implementation using OpenCL summation at second step...
OpenCL kernel file for vector operations.
void inner_prod_impl(vector_base< NumericT > const &x, vector_base< NumericT > const &y, scalar< NumericT > &result)
Computes the inner product of two vectors - implementation. Library users should call inner_prod(x...
Implementation of a smart-pointer-like class for handling OpenCL handles.
result_of::size_type< T >::type start(T const &obj)
template_base * template_of(std::string const &key)
statement index_norm_inf(scalar< NumericT > const *s, vector_base< NumericT > const *x)
statement norm_1(scalar< NumericT > const *s, vector_base< NumericT > const *x)
statement norm_inf(scalar< NumericT > const *s, vector_base< NumericT > const *x)
statement unary_element_op(NumericT const *x, NumericT const *y, scheduler::operation_node_type TYPE)
scheduler::statement av(scheduler::operation_node_type ASSIGN_OP, NumericT const *x, NumericT const *y, ScalarT1 const *a, bool flip_a, bool reciprocal_a)
std::list< scheduler::statement > data_type
void norm_inf_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the supremum-norm of a vector.
operation_node_type
Enumeration for identifying the possible operations.
void vector_swap(vector_base< NumericT > &x, vector_base< NumericT > &y)
Swaps the contents of two vectors, data is copied.
All the predicates used within ViennaCL. Checks for expressions to be vectors, etc.
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
void av(vector_base< NumericT > &x, vector_base< NumericT > const &y, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha)
Representation of an OpenCL kernel in ViennaCL.
Represents a vector consisting of scalars 's' only, i.e. v[i] = s for all i. To be used as an initial...
device_specific::statements_container swap(NumericT const *x, NumericT const *y)
A range class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
static device_specific::execution_handler & execution_handler(viennacl::ocl::context &ctx)
void avbv(vector_base< NumericT > &x, vector_base< NumericT > const &y, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< NumericT > const &z, ScalarT2 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)
VectorType const & const_at(vcl_size_t i) const
viennacl::ocl::packed_cl_uint make_layout(vector_base< NumericT > const &vec)
void execute(container_type::key_type const &key, statements_container const &statements)
A tag class representing element-wise binary operations (like multiplication) on vectors or matrices...
The main class for representing a statement such as x = inner_prod(y,z); at runtime.
Forward declarations of the implicit_vector_base, vector_base class.
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
scheduler::statement assign_cpu(vector_base< NumericT > const *x, implicit_vector_base< NumericT > const *y)
device_specific::statements_container plane_rotation(vector_base< NumericT > const *x, vector_base< NumericT > const *y, NumericT const *a, NumericT const *b)
const char * operator_string(scheduler::operation_node_type type)
ScalarType diff(ScalarType &s1, viennacl::scalar< ScalarType > &s2)
A tag class representing element-wise unary operations (like sin()) on vectors or matrices...
Implementation of the ViennaCL scalar class.
Simple enable-if variant that uses the SFINAE pattern.
cl_uint size
Number of values in the stride.