1 #ifndef VIENNACL_SCALAR_HPP_
2 #define VIENNACL_SCALAR_HPP_
33 #ifdef VIENNACL_WITH_OPENCL
46 template<
typename LHS,
typename RHS,
typename OP>
47 class scalar_expression
49 typedef typename LHS::value_type DummyType;
56 LHS &
lhs()
const {
return lhs_; }
58 RHS &
rhs()
const {
return rhs_; }
81 template<
typename LHS,
typename RHS>
91 LHS &
lhs()
const {
return lhs_; }
93 RHS &
rhs()
const {
return rhs_; }
114 template<
typename LHS,
typename RHS>
124 LHS &
lhs()
const {
return lhs_; }
126 RHS &
rhs()
const {
return rhs_; }
146 template<
typename LHS,
typename RHS>
156 LHS &
lhs()
const {
return lhs_; }
158 RHS &
rhs()
const {
return rhs_; }
179 template<
typename LHS,
typename RHS>
189 LHS &
lhs()
const {
return lhs_; }
191 RHS &
rhs()
const {
return rhs_; }
211 template<
typename LHS,
typename RHS>
221 LHS &
lhs()
const {
return lhs_; }
223 RHS &
rhs()
const {
return rhs_; }
244 template<
typename LHS,
typename RHS>
254 LHS &
lhs()
const {
return lhs_; }
256 RHS &
rhs()
const {
return rhs_; }
276 template<
typename LHS,
typename RHS>
286 LHS &
lhs()
const {
return lhs_; }
288 RHS &
rhs()
const {
return rhs_; }
309 template<
typename LHS,
typename RHS>
319 LHS &
lhs()
const {
return lhs_; }
321 RHS &
rhs()
const {
return rhs_; }
346 template<
class NumericT>
349 typedef scalar<NumericT> self_type;
366 #ifdef VIENNACL_WITH_OPENCL
375 val_.opencl_handle() = mem;
376 val_.opencl_handle().inc();
381 template<
typename T1,
typename T2,
typename OP>
485 template<
typename T1,
typename T2>
495 template<
typename T1,
typename T2>
505 template<
typename T1,
typename T2>
515 template<
typename T1,
typename T2>
525 template<
typename T1,
typename T2>
535 template<
typename T1,
typename T2>
545 template<
typename T1,
typename T2>
556 template<
typename T1,
typename T2>
566 template<
typename T1,
typename T2>
582 *
this,
NumericT(1.0), 1,
false,
false,
583 other,
NumericT(1.0), 1,
false,
false);
592 *
this,
NumericT(1.0), 1,
false,
false,
593 other,
NumericT(1.0), 1,
false,
false);
604 *
this,
NumericT(1.0), 1,
false,
false,
605 other,
NumericT(-1.0), 1,
false,
false);
614 *
this,
NumericT(1.0), 1,
false,
false,
615 other,
NumericT(-1.0), 1,
false,
false);
626 *
this, other, 1,
false,
false);
635 *
this, other, 1,
false,
false);
647 *
this, other, 1,
true,
false);
656 *
this, other, 1,
true,
false);
670 *
this,
NumericT(1.0), 1,
false,
false,
671 other,
NumericT(1.0), 1,
false,
false);
676 template<
typename T1,
typename T2,
typename OP>
684 *
this,
NumericT(1.0), 1,
false,
false,
685 result,
NumericT(1.0), 1,
false,
false);
697 *
this,
NumericT(1.0), 1,
false,
false,
698 other,
NumericT(1.0), 1,
false,
false);
721 *
this,
NumericT(1.0), 1,
false,
false,
722 other,
NumericT(-1.0), 1,
false,
false);
727 template<
typename T1,
typename T2,
typename OP>
735 *
this,
NumericT(1.0), 1 ,
false,
false,
736 result,
NumericT(-1.0), 1,
false,
false);
748 *
this,
NumericT(1.0), 1,
false,
false,
749 other,
NumericT(-1.0), 1,
false,
false);
763 *
this, other, 1,
false,
false);
768 template<
typename T1,
typename T2,
typename OP>
776 *
this, result, 1,
false,
false);
788 *
this, other, 1,
false,
false);
802 *
this, other, 1,
true,
false);
807 template<
typename T1,
typename T2,
typename OP>
815 *
this, result, 1,
true,
false);
827 *
this, other, 1,
true,
false);
854 template<
class NumericT>
855 std::ostream & operator<<(std::ostream & s, const scalar<NumericT> & val)
863 template<
class NumericT>
void norm_frobenius_cpu(matrix_base< T > const &vec, T &result)
Computes the Frobenius norm of a vector with final reduction on the CPU.
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.
scalar_expression(LHS &lhs, RHS &rhs)
void memory_write(mem_handle &dst_buffer, vcl_size_t dst_offset, vcl_size_t bytes_to_write, const void *ptr, bool async=false)
Writes data from main RAM identified by 'ptr' to the buffer identified by 'dst_buffer'.
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
void inner_prod_cpu(vector_base< T > const &vec1, vector_base< T > const &vec2, T &result)
Computes the inner product of two vectors with the final reduction step on the CPU - dispatcher inter...
A tag class representing the summation of a vector.
void min_cpu(vector_base< T > const &vec, T &result)
Computes the minimum of a vector with final reduction on the CPU.
scalar_expression(LHS &lhs, RHS &rhs)
scalar()
Creates the scalar object, but does not yet allocate memory. Thus, scalar<> can also be a global vari...
scalar(NumericT val, viennacl::context ctx=viennacl::context())
Allocates the memory for the scalar and sets it to the supplied value.
scalar_expression< const self_type, const self_type, op_flip_sign > operator-() const
Sign flip of the scalar. Does not evaluate immediately, but instead returns an expression template ob...
void max_cpu(vector_base< T > const &vec, T &result)
Computes the maximum of a vector with final reduction on the CPU.
handle_type & handle()
Returns the memory handle, non-const version.
scalar_expression(LHS &lhs, RHS &rhs)
Implementations of scalar operations.
scalar(scalar_expression< T1, T2, OP > const &proxy)
Allocates memory for the scalar and sets it to the result of supplied expression. ...
void sum_impl(vector_base< T > const &vec, scalar< T > &result)
self_type & operator/=(scalar< NumericT > const &other)
Inplace division with a ViennaCL scalar.
void norm_2_cpu(vector_base< T > const &vec, T &result)
Computes the l^2-norm of a vector with final reduction on the CPU - dispatcher interface.
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
self_type operator*(scalar< NumericT > const &other) const
Multiplication of two ViennaCL scalars.
This file provides the forward declarations for the main types used within ViennaCL.
RHS & rhs() const
Returns the left hand side operand.
void memory_read(mem_handle const &src_buffer, vcl_size_t src_offset, vcl_size_t bytes_to_read, void *ptr, bool async=false)
Reads data from a buffer back to main RAM.
self_type & operator-=(scalar< NumericT > const &other)
Inplace subtraction of a ViennaCL scalar.
A proxy for scalar expressions (e.g. from inner vector products)
NumericT value_type
Returns the underlying host scalar type.
A tag class representing the maximum of a vector.
scalar_expression(LHS &lhs, RHS &rhs)
RHS & rhs() const
Returns the left hand side operand.
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
void norm_2_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the l^2-norm of a vector - dispatcher interface.
RHS & rhs() const
Returns the left hand side operand.
void norm_frobenius_impl(matrix_base< T > const &vec, scalar< T > &result)
Computes the Frobenius norm of a matrix - dispatcher interface.
scalar_expression(LHS &lhs, RHS &rhs)
void max_impl(vector_base< T > const &vec, scalar< T > &result)
vcl_size_t index() const
Returns the index of the represented element.
scalar_expression(LHS &lhs, RHS &rhs)
scalar(const scalar &other)
Copy constructor. Allocates new memory for the scalar and copies the value of the supplied scalar...
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
void inner_prod_impl(vector_base< T > const &vec1, vector_base< T > const &vec2, scalar< T > &result)
Computes the inner product of two vectors - dispatcher interface.
self_type operator/(scalar< NumericT > const &other) const
Division of two ViennaCL scalars.
self_type & operator+=(scalar< NumericT > const &other)
Inplace addition of a ViennaCL scalar.
LHS & lhs() const
Returns the left hand side operand.
self_type & operator=(entry_proxy< NumericT > const &other)
Assigns a vector entry.
scalar_expression(LHS &lhs, RHS &rhs)
void norm_1_cpu(vector_base< T > const &vec, T &result)
Computes the l^1-norm of a vector with final reduction on the CPU.
LHS & lhs() const
Returns the left hand side operand.
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
const handle_type & handle() const
Returns the memory handle, const version.
std::istream & operator>>(std::istream &s, const scalar< NumericT > &val)
Allows to directly read a value of a scalar from an input stream.
void norm_inf_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the supremum-norm of a vector.
void norm_1_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the l^1-norm of a vector - dispatcher interface.
RHS & rhs() const
Returns the left hand side operand.
self_type & operator*=(scalar< NumericT > const &other)
Inplace multiplication with a ViennaCL scalar.
LHS & lhs() const
Returns the left hand side operand.
viennacl::result_of::cpu_value_type< DummyType >::type ScalarType
void min_impl(vector_base< T > const &vec, scalar< T > &result)
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...
LHS & lhs() const
Returns the left hand side operand.
A tag class representing the minimum of a vector.
T::ERROR_CANNOT_DEDUCE_CPU_SCALAR_TYPE_FOR_T type
Implementations of the OpenCL backend, where all contexts are stored in.
LHS & lhs() const
Returns the left hand side operand.
RHS & rhs() const
Returns the left hand side operand.
handle_type const & handle() const
Returns the memory viennacl::ocl::handle.
void switch_active_handle_id(memory_types new_id)
Switches the currently active handle. If no support for that backend is provided, an exception is thr...
A tag class representing the 1-norm of a vector.
void memory_copy(mem_handle const &src_buffer, mem_handle &dst_buffer, vcl_size_t src_offset, vcl_size_t dst_offset, vcl_size_t bytes_to_copy)
Copies 'bytes_to_copy' bytes from address 'src_buffer + src_offset' to memory starting at address 'ds...
self_type operator+(scalar< NumericT > const &other)
Addition of two ViennaCL scalars.
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
void sum_cpu(vector_base< T > const &vec, T &result)
Computes the sum of a vector with final reduction on the CPU.
LHS & lhs() const
Returns the left hand side operand.
LHS & lhs() const
Returns the left hand side operand.
viennacl::backend::mem_handle handle_type
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
scalar_expression(LHS &lhs, RHS &rhs)
A tag class representing the Frobenius-norm of a matrix.
void memory_create(mem_handle &handle, vcl_size_t size_in_bytes, viennacl::context const &ctx, const void *host_ptr=NULL)
Creates an array of the specified size. If the second argument is provided, the buffer is initialized...
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
A tag class representing inner products of two vectors.
RHS & rhs() const
Returns the left hand side operand.
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
A tag class representing the inf-norm of a vector.
LHS & lhs() const
Returns the left hand side operand.
RHS & rhs() const
Returns the left hand side operand.
RHS & rhs() const
Returns the left hand side operand.
A tag class representing the 2-norm of a vector.
void norm_inf_cpu(vector_base< T > const &vec, T &result)
Computes the supremum-norm of a vector with final reduction on the CPU.
A collection of compile time type deductions.
LHS & lhs() const
Returns the left hand side operand.
Main interface routines for memory management.
scalar_expression(LHS &lhs, RHS &rhs)
RHS & rhs() const
Returns the left hand side operand.
memory_types get_active_handle_id() const
Returns an ID for the currently active memory buffer. Other memory buffers might contain old or no da...