ViennaCL - The Vienna Computing Library  1.5.2
Public Types | Public Member Functions
vector< SCALARTYPE, ALIGNMENT > Class Template Reference

A vector class representing a linear memory sequence on the GPU. Inspired by boost::numeric::ublas::vector. More...

#include <forwards.h>

Inheritance diagram for vector< SCALARTYPE, ALIGNMENT >:
vector_base< SCALARTYPE >

Public Types

typedef base_type::size_type size_type
 
typedef base_type::difference_type difference_type
 
- Public Types inherited from vector_base< SCALARTYPE >
typedef scalar< SCALARTYPE > value_type
 
typedef SCALARTYPE cpu_value_type
 
typedef
viennacl::backend::mem_handle 
handle_type
 
typedef vcl_size_t size_type
 
typedef vcl_ptrdiff_t difference_type
 
typedef const_vector_iterator
< SCALARTYPE, 1 > 
const_iterator
 
typedef vector_iterator
< SCALARTYPE, 1 > 
iterator
 

Public Member Functions

 vector ()
 Default constructor in order to be compatible with various containers. More...
 
 vector (size_type vec_size)
 An explicit constructor for the vector, allocating the given amount of memory (plus a padding specified by 'ALIGNMENT') More...
 
 vector (size_type vec_size, viennacl::context ctx)
 
 vector (SCALARTYPE *ptr_to_mem, viennacl::memory_types mem_type, size_type vec_size, size_type start=0, difference_type stride=1)
 
template<typename LHS , typename RHS , typename OP >
 vector (vector_expression< const LHS, const RHS, OP > const &proxy)
 
 vector (const base_type &v)
 
 vector (const self_type &v)
 
 vector (unit_vector< SCALARTYPE > const &v)
 Creates the vector from the supplied unit vector. More...
 
 vector (zero_vector< SCALARTYPE > const &v)
 Creates the vector from the supplied zero vector. More...
 
 vector (scalar_vector< SCALARTYPE > const &v)
 Creates the vector from the supplied scalar vector. More...
 
template<typename T >
self_typeoperator= (T const &other)
 
void resize (size_type new_size, bool preserve=true)
 Resizes the allocated memory for the vector. Pads the memory to be a multiple of 'ALIGNMENT'. More...
 
void resize (size_type new_size, viennacl::context ctx, bool preserve=true)
 
self_typefast_swap (self_type &other)
 Swaps the handles of two vectors by swapping the OpenCL handles only, no data copy. More...
 
void switch_memory_context (viennacl::context new_ctx)
 
- Public Member Functions inherited from vector_base< SCALARTYPE >
 vector_base ()
 Default constructor in order to be compatible with various containers. More...
 
 vector_base (viennacl::backend::mem_handle &h, size_type vec_size, size_type vec_start, difference_type vec_stride)
 An explicit constructor for wrapping an existing vector into a vector_range or vector_slice. More...
 
 vector_base (size_type vec_size, viennacl::context ctx=viennacl::context())
 Creates a vector and allocates the necessary memory. More...
 
 vector_base (SCALARTYPE *ptr_to_mem, viennacl::memory_types mem_type, size_type vec_size, vcl_size_t start=0, difference_type stride=1)
 
 vector_base (vector_expression< const LHS, const RHS, OP > const &proxy)
 Creates the vector from the supplied random vector. More...
 
self_typeoperator= (const self_type &vec)
 Assignment operator. Other vector needs to be of the same size, or this vector is not yet initialized. More...
 
self_typeoperator= (const vector_expression< const LHS, const RHS, OP > &proxy)
 Implementation of the operation v1 = v2 @ alpha, where @ denotes either multiplication or division, and alpha is either a CPU or a GPU scalar. More...
 
self_typeoperator= (const vector_base< T > &v1)
 
self_typeoperator= (unit_vector< SCALARTYPE > const &v)
 Creates the vector from the supplied unit vector. More...
 
self_typeoperator= (zero_vector< SCALARTYPE > const &v)
 Creates the vector from the supplied zero vector. More...
 
self_typeoperator= (scalar_vector< SCALARTYPE > const &v)
 Creates the vector from the supplied scalar vector. More...
 
self_typeoperator= (const viennacl::vector_expression< const matrix_base< SCALARTYPE, F >, const vector_base< SCALARTYPE >, viennacl::op_prod > &proxy)
 Operator overload for v1 = A * v2, where v1, v2 are vectors and A is a dense matrix. More...
 
self_typeoperator= (const vector_expression< const matrix_expression< const matrix_base< SCALARTYPE, F >, const matrix_base< SCALARTYPE, F >, op_trans >, const vector_base< SCALARTYPE >, op_prod > &proxy)
 Operator overload for v1 = trans(A) * v2, where v1, v2 are vectors and A is a dense matrix. More...
 
entry_proxy< SCALARTYPE > operator() (size_type index)
 Read-write access to a single element of the vector. More...
 
const_entry_proxy< SCALARTYPE > operator() (size_type index) const
 Read access to a single element of the vector. More...
 
entry_proxy< SCALARTYPE > operator[] (size_type index)
 Read-write access to a single element of the vector. More...
 
const_entry_proxy< SCALARTYPE > operator[] (size_type index) const
 Read access to a single element of the vector. More...
 
self_typeoperator+= (const self_type &vec)
 
self_typeoperator-= (const self_type &vec)
 
self_typeoperator*= (SCALARTYPE val)
 Scales a vector (or proxy) by a CPU scalar value. More...
 
self_typeoperator/= (SCALARTYPE val)
 Scales this vector by a CPU scalar value. More...
 
vector_expression< const
self_type, const SCALARTYPE,
op_mult
operator* (SCALARTYPE value) const
 Scales the vector by a CPU scalar 'alpha' and returns an expression template. More...
 
vector_expression< const
self_type, const SCALARTYPE,
op_div
operator/ (SCALARTYPE value) const
 Scales the vector by a CPU scalar 'alpha' and returns an expression template. More...
 
vector_expression< const
self_type, const SCALARTYPE,
op_mult
operator- () const
 Sign flip for the vector. Emulated to be equivalent to -1.0 * vector. More...
 
iterator begin ()
 Returns an iterator pointing to the beginning of the vector (STL like) More...
 
const_iterator begin () const
 Returns a const-iterator pointing to the beginning of the vector (STL like) More...
 
iterator end ()
 Returns an iterator pointing to the end of the vector (STL like) More...
 
const_iterator end () const
 Returns a const-iterator pointing to the end of the vector (STL like) More...
 
self_typeswap (self_type &other)
 Swaps the entries of the two vectors. More...
 
size_type size () const
 Returns the length of the vector (cf. std::vector) More...
 
size_type internal_size () const
 Returns the internal length of the vector, which is given by size() plus the extra memory due to padding the memory with zeros up to a multiple of 'ALIGNMENT'. More...
 
size_type start () const
 Returns the offset within the buffer. More...
 
size_type stride () const
 Returns the stride within the buffer (in multiples of sizeof(SCALARTYPE)) More...
 
bool empty () const
 Returns true is the size is zero. More...
 
const handle_typehandle () const
 Returns the memory handle. More...
 
handle_typehandle ()
 Returns the memory handle. More...
 
void clear ()
 Resets all entries to zero. Does not change the size of the vector. More...
 
viennacl::memory_types memory_domain () const
 

Additional Inherited Members

- Static Public Attributes inherited from vector_base< SCALARTYPE >
static const size_type alignment
 
- Protected Member Functions inherited from vector_base< SCALARTYPE >
void set_handle (viennacl::backend::mem_handle const &h)
 
self_typefast_swap (self_type &other)
 Swaps the handles of two vectors by swapping the OpenCL handles only, no data copy. More...
 
void pad ()
 Pads vectors with alignment > 1 with trailing zeros if the internal size is larger than the visible size. More...
 
void switch_memory_context (viennacl::context new_ctx)
 
void resize (size_type new_size, bool preserve=true)
 Resizes the allocated memory for the vector. Pads the memory to be a multiple of 'ALIGNMENT'. More...
 
void resize (size_type new_size, viennacl::context ctx, bool preserve=true)
 Resizes the allocated memory for the vector. Convenience function for setting an OpenCL context in case reallocation is needed. More...
 

Detailed Description

template<class SCALARTYPE, unsigned int ALIGNMENT = 1>
class viennacl::vector< SCALARTYPE, ALIGNMENT >

A vector class representing a linear memory sequence on the GPU. Inspired by boost::numeric::ublas::vector.

This is the basic vector type of ViennaCL. It is similar to std::vector and boost::numeric::ublas::vector and supports various linear algebra operations. By default, the internal length of the vector is padded to a multiple of 'ALIGNMENT' in order to speed up several GPU viennacl::ocl::kernels.

Template Parameters
SCALARTYPEThe floating point type, either 'float' or 'double'
ALIGNMENTThe internal memory size is given by (size()/ALIGNMENT + 1) * ALIGNMENT. ALIGNMENT must be a power of two. Best values or usually 4, 8 or 16, higher values are usually a waste of memory.

Member Typedef Documentation

Constructor & Destructor Documentation

vector ( )
inlineexplicit

Default constructor in order to be compatible with various containers.

vector ( size_type  vec_size)
inlineexplicit

An explicit constructor for the vector, allocating the given amount of memory (plus a padding specified by 'ALIGNMENT')

Parameters
vec_sizeThe length (i.e. size) of the vector.
vector ( size_type  vec_size,
viennacl::context  ctx 
)
inlineexplicit
vector ( SCALARTYPE *  ptr_to_mem,
viennacl::memory_types  mem_type,
size_type  vec_size,
size_type  start = 0,
difference_type  stride = 1 
)
inlineexplicit
vector ( vector_expression< const LHS, const RHS, OP > const &  proxy)
inline
vector ( const base_type v)
inline
vector ( const self_type v)
inline
vector ( unit_vector< SCALARTYPE > const &  v)
inline

Creates the vector from the supplied unit vector.

vector ( zero_vector< SCALARTYPE > const &  v)
inline

Creates the vector from the supplied zero vector.

vector ( scalar_vector< SCALARTYPE > const &  v)
inline

Creates the vector from the supplied scalar vector.

Member Function Documentation

self_type& fast_swap ( self_type other)
inline

Swaps the handles of two vectors by swapping the OpenCL handles only, no data copy.

self_type& operator= ( T const &  other)
inline
void resize ( size_type  new_size,
bool  preserve = true 
)
inline

Resizes the allocated memory for the vector. Pads the memory to be a multiple of 'ALIGNMENT'.

Parameters
new_sizeThe new size of the vector
preserveIf true, old entries of the vector are preserved, otherwise eventually discarded.
void resize ( size_type  new_size,
viennacl::context  ctx,
bool  preserve = true 
)
inline
void switch_memory_context ( viennacl::context  new_ctx)
inline

The documentation for this class was generated from the following files: