ViennaCL - The Vienna Computing Library
1.5.2
|
A STL-type const-iterator for vector elements. Elements can be accessed, but cannot be manipulated. VERY SLOW!! More...
#include <vector.hpp>
Public Types | |
typedef scalar< SCALARTYPE > | value_type |
typedef vcl_ptrdiff_t | difference_type |
typedef viennacl::backend::mem_handle | handle_type |
Public Member Functions | |
const_vector_iterator (vector_base< SCALARTYPE > const &vec, vcl_size_t index, vcl_size_t start=0, vcl_ptrdiff_t stride=1) | |
Constructor. | |
const_vector_iterator (handle_type const &elements, vcl_size_t index, vcl_size_t start=0, vcl_ptrdiff_t stride=1) | |
Constructor for vector-like treatment of arbitrary buffers. | |
value_type | operator* (void) const |
Dereferences the iterator and returns the value of the element. For convenience only, performance is poor due to OpenCL overhead! | |
self_type | operator++ (void) |
self_type | operator++ (int) |
bool | operator== (self_type const &other) const |
bool | operator!= (self_type const &other) const |
difference_type | operator- (self_type const &other) const |
self_type | operator+ (difference_type diff) const |
vcl_size_t | offset () const |
Offset of the current element index with respect to the beginning of the buffer. | |
vcl_size_t | stride () const |
Index increment in the underlying buffer when incrementing the iterator to the next element. | |
handle_type const & | handle () const |
Protected Attributes | |
handle_type const & | elements_ |
The index of the entry the iterator is currently pointing to. | |
vcl_size_t | index_ |
vcl_size_t | start_ |
vcl_ptrdiff_t | stride_ |
A STL-type const-iterator for vector elements. Elements can be accessed, but cannot be manipulated. VERY SLOW!!
Every dereference operation initiates a transfer from the GPU to the CPU. The overhead of such a transfer is around 50us, so 20.000 dereferences take one second. This is four orders of magnitude slower than similar dereferences on the CPU. However, increments and comparisons of iterators is as fast as for CPU types. If you need a fast iterator, copy the whole vector to the CPU first and iterate over the CPU object, e.g. std::vector<float> temp; copy(gpu_vector, temp); for (std::vector<float>::const_iterator iter = temp.begin(); iter != temp.end(); ++iter) { //do something } Note that you may obtain inconsistent data if entries of gpu_vector are manipulated elsewhere in the meanwhile.
SCALARTYPE | The underlying floating point type (either float or double) |
ALIGNMENT | Alignment of the underlying vector, |
typedef vcl_ptrdiff_t difference_type |
Reimplemented in vector_iterator< SCALARTYPE, ALIGNMENT >.
Reimplemented in vector_iterator< SCALARTYPE, ALIGNMENT >.
typedef scalar<SCALARTYPE> value_type |
const_vector_iterator | ( | vector_base< SCALARTYPE > const & | vec, |
vcl_size_t | index, | ||
vcl_size_t | start = 0 , |
||
vcl_ptrdiff_t | stride = 1 |
||
) | [inline] |
Constructor.
vec | The vector over which to iterate |
index | The starting index of the iterator |
start | First index of the element in the vector pointed to be the iterator (for vector_range and vector_slice) |
stride | Stride for the support of vector_slice |
const_vector_iterator | ( | handle_type const & | elements, |
vcl_size_t | index, | ||
vcl_size_t | start = 0 , |
||
vcl_ptrdiff_t | stride = 1 |
||
) | [inline] |
Constructor for vector-like treatment of arbitrary buffers.
elements | The buffer over which to iterate |
index | The starting index of the iterator |
start | First index of the element in the vector pointed to be the iterator (for vector_range and vector_slice) |
stride | Stride for the support of vector_slice |
handle_type const& handle | ( | ) | const [inline] |
Reimplemented in vector_iterator< SCALARTYPE, ALIGNMENT >.
vcl_size_t offset | ( | ) | const [inline] |
Offset of the current element index with respect to the beginning of the buffer.
bool operator!= | ( | self_type const & | other | ) | const [inline] |
value_type operator* | ( | void | ) | const [inline] |
Dereferences the iterator and returns the value of the element. For convenience only, performance is poor due to OpenCL overhead!
self_type operator+ | ( | difference_type | diff | ) | const [inline] |
Reimplemented in vector_iterator< SCALARTYPE, ALIGNMENT >.
self_type operator++ | ( | void | ) | [inline] |
self_type operator++ | ( | int | ) | [inline] |
difference_type operator- | ( | self_type const & | other | ) | const [inline] |
Reimplemented in vector_iterator< SCALARTYPE, ALIGNMENT >.
bool operator== | ( | self_type const & | other | ) | const [inline] |
vcl_size_t stride | ( | ) | const [inline] |
Index increment in the underlying buffer when incrementing the iterator to the next element.
handle_type const& elements_ [protected] |
The index of the entry the iterator is currently pointing to.
vcl_size_t index_ [protected] |
vcl_size_t start_ [protected] |
vcl_ptrdiff_t stride_ [protected] |