1 #ifndef VIENNACL_VECTOR_PROXY_HPP_
2 #define VIENNACL_VECTOR_PROXY_HPP_
37 template <
typename VectorType>
38 class vector_range :
public vector_base<typename VectorType::cpu_value_type>
40 typedef vector_range<VectorType> self_type;
41 typedef vector_base<typename VectorType::cpu_value_type> base_type;
50 typedef typename VectorType::iterator
iterator;
60 using base_type::operator=;
70 template <
typename VectorType,
typename SCALARTYPE>
71 void copy(
const VectorType & cpu_vector,
74 assert(cpu_vector.end() - cpu_vector.begin() >= 0 && bool(
"Range must have nonnegative length!"));
76 if (cpu_vector.end() - cpu_vector.begin() > 0)
79 std::vector<SCALARTYPE> temp_buffer(cpu_vector.end() - cpu_vector.begin());
80 std::copy(cpu_vector.begin(), cpu_vector.end(), temp_buffer.begin());
81 viennacl::backend::memory_write(gpu_vector_range.handle(),
sizeof(SCALARTYPE)*gpu_vector_range.start(),
sizeof(SCALARTYPE)*temp_buffer.size(), &(temp_buffer[0]));
91 template <
typename CPUVECTOR,
typename VectorType>
102 template <
typename SCALARTYPE,
typename VectorType>
104 VectorType & cpu_vector)
106 assert(cpu_vector.end() - cpu_vector.begin() >= 0 && bool(
"Range must have nonnegative length!"));
108 if (cpu_vector.end() > cpu_vector.begin())
110 std::vector<SCALARTYPE> temp_buffer(cpu_vector.end() - cpu_vector.begin());
111 viennacl::backend::memory_read(gpu_vector_range.handle(),
sizeof(SCALARTYPE)*gpu_vector_range.start(),
sizeof(SCALARTYPE)*temp_buffer.size(), &(temp_buffer[0]));
114 std::copy(temp_buffer.begin(), temp_buffer.end(), cpu_vector.begin());
124 template <
typename VectorType,
typename CPUVECTOR>
126 CPUVECTOR & cpu_vec )
136 template <
typename VectorType>
142 template <
typename VectorType>
145 assert(r1.
size() <= vec.
size() && bool(
"Size of range invalid!"));
163 template <
typename VectorType>
164 class vector_slice :
public vector_base<typename VectorType::cpu_value_type>
166 typedef vector_slice<VectorType> self_type;
167 typedef vector_base<typename VectorType::cpu_value_type> base_type;
186 using base_type::operator=;
195 template <
typename VectorType,
typename SCALARTYPE>
196 void copy(
const VectorType & cpu_vector,
199 if (cpu_vector.size() > 0)
201 std::vector<SCALARTYPE> temp_buffer(gpu_vector_slice.stride() * gpu_vector_slice.size());
203 viennacl::backend::memory_read(gpu_vector_slice.handle(),
sizeof(SCALARTYPE)*gpu_vector_slice.start(),
sizeof(SCALARTYPE)*temp_buffer.size(), &(temp_buffer[0]));
205 for (
vcl_size_t i=0; i<cpu_vector.size(); ++i)
206 temp_buffer[i * gpu_vector_slice.stride()] = cpu_vector[i];
208 viennacl::backend::memory_write(gpu_vector_slice.handle(),
sizeof(SCALARTYPE)*gpu_vector_slice.start(),
sizeof(SCALARTYPE)*temp_buffer.size(), &(temp_buffer[0]));
219 template <
typename VectorType,
typename SCALARTYPE>
221 VectorType & cpu_vector)
223 assert(gpu_vector_slice.end() - gpu_vector_slice.begin() >= 0 && bool(
"Range must have nonnegative length!"));
225 if (gpu_vector_slice.end() - gpu_vector_slice.begin() > 0)
227 std::vector<SCALARTYPE> temp_buffer(gpu_vector_slice.stride() * gpu_vector_slice.size());
228 viennacl::backend::memory_read(gpu_vector_slice.handle(),
sizeof(SCALARTYPE)*gpu_vector_slice.start(),
sizeof(SCALARTYPE)*temp_buffer.size(), &(temp_buffer[0]));
230 for (
vcl_size_t i=0; i<cpu_vector.size(); ++i)
231 cpu_vector[i] = temp_buffer[i * gpu_vector_slice.stride()];
242 template <
typename VectorType>
245 assert(s1.
size() <= vec.size() && bool(
"Size of slice larger than vector size!"));
249 template <
typename VectorType>
252 assert(s1.
size() <= vec.
size() && bool(
"Size of slice larger than vector proxy!"));
258 template <
typename VectorType>
261 assert(r1.
size() <= vec.
size() && bool(
"Size of slice larger than vector proxy!"));
265 template <
typename VectorType>
268 assert(s1.
size() <= vec.
size() && bool(
"Size of slice larger than vector proxy!"));
VectorType::cpu_value_type cpu_value_type
Definition: vector_proxy.hpp:178
std::size_t vcl_size_t
Definition: forwards.h:58
Class for representing non-strided subvectors of a bigger vector x.
Definition: forwards.h:349
value_type reference
Definition: vector_proxy.hpp:173
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'.
Definition: memory.hpp:220
VectorType::cpu_value_type cpu_value_type
Definition: vector_proxy.hpp:52
basic_slice slice
Definition: forwards.h:344
slice::difference_type difference_type
Definition: vector_proxy.hpp:172
difference_type stride() const
Definition: slice.hpp:55
matrix_range< MatrixType > project(MatrixType &A, viennacl::range const &r1, viennacl::range const &r2)
Definition: matrix_proxy.hpp:251
A proxy class for entries in a vector.
A range class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
Definition: forwards.h:339
VectorType::const_iterator const_iterator
Definition: vector_proxy.hpp:49
size_type start() const
Definition: range.hpp:55
range::size_type size_type
Definition: vector_proxy.hpp:45
This file provides the forward declarations for the main types used within ViennaCL.
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.
Definition: memory.hpp:261
slice::size_type size_type
Definition: vector_proxy.hpp:171
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:29
range::difference_type difference_type
Definition: vector_proxy.hpp:46
SizeType size_type
Definition: slice.hpp:42
static const int alignment
Definition: vector_proxy.hpp:180
size_type size() const
Definition: slice.hpp:56
size_type size() const
Definition: range.hpp:56
VectorType::value_type value_type
Definition: vector_proxy.hpp:170
void copy(std::vector< SCALARTYPE > &cpu_vec, circulant_matrix< SCALARTYPE, ALIGNMENT > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
Definition: circulant_matrix.hpp:150
size_type size() const
Returns the length of the vector (cf. std::vector)
Definition: vector.hpp:837
SizeType size_type
Definition: range.hpp:42
DistanceType difference_type
Definition: slice.hpp:43
static const int alignment
Definition: vector_proxy.hpp:54
size_type start() const
Returns the offset within the buffer.
Definition: vector.hpp:845
value_type reference
Definition: vector_proxy.hpp:47
void copy(vector_slice< vector< SCALARTYPE > > const &gpu_vector_slice, VectorType &cpu_vector)
Definition: vector_proxy.hpp:220
A vector class representing a linear memory sequence on the GPU. Inspired by boost::numeric::ublas::v...
Definition: forwards.h:208
VectorType::iterator iterator
Definition: vector_proxy.hpp:176
VectorType::iterator iterator
Definition: vector_proxy.hpp:50
vector_slice(VectorType &v, slice const &entry_slice)
Definition: vector_proxy.hpp:182
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
const value_type & const_reference
Definition: vector_proxy.hpp:48
Implementation of a slice object for use with proxy objects.
size_type start() const
Definition: slice.hpp:54
VectorType::const_iterator const_iterator
Definition: vector_proxy.hpp:175
const handle_type & handle() const
Returns the memory handle.
Definition: vector.hpp:856
DistanceType difference_type
Definition: range.hpp:43
vector_range(VectorType &v, range const &entry_range)
Definition: vector_proxy.hpp:56
Class for representing strided subvectors of a bigger vector x.
Definition: forwards.h:352
Implementation of a range object for use with proxy objects.
basic_range range
Definition: forwards.h:339
void fast_copy(const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_begin, const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_end, CPU_ITERATOR cpu_begin)
STL-like transfer of a GPU vector to the CPU. The cpu type is assumed to reside in a linear piece of ...
Definition: vector.hpp:1262
A slice class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
Definition: forwards.h:344
const value_type & const_reference
Definition: vector_proxy.hpp:174
size_type stride() const
Returns the stride within the buffer (in multiples of sizeof(SCALARTYPE))
Definition: vector.hpp:849
VectorType::value_type value_type
Definition: vector_proxy.hpp:44