1 #ifndef VIENNACL_VECTOR_PROXY_HPP_
2 #define VIENNACL_VECTOR_PROXY_HPP_
38 template<
typename VectorType>
39 class vector_range :
public vector_base<typename VectorType::cpu_value_type>
41 typedef vector_range<VectorType> self_type;
42 typedef vector_base<typename VectorType::cpu_value_type> base_type;
51 typedef typename VectorType::iterator
iterator;
68 using base_type::operator=;
71 template<
typename VectorType>
92 template<
typename VectorType,
typename NumericT>
93 void copy(
const VectorType & cpu_vector,
96 assert(cpu_vector.end() - cpu_vector.begin() >= 0 && bool(
"Range must have nonnegative length!"));
98 if (cpu_vector.end() - cpu_vector.begin() > 0)
101 std::vector<NumericT> temp_buffer(static_cast<vcl_size_t>(cpu_vector.end() - cpu_vector.begin()));
102 std::copy(cpu_vector.begin(), cpu_vector.end(), temp_buffer.begin());
103 viennacl::backend::memory_write(gpu_vector_range.handle(),
sizeof(NumericT)*gpu_vector_range.start(),
sizeof(NumericT)*temp_buffer.size(), &(temp_buffer[0]));
113 template<
typename CPUVECTOR,
typename VectorType>
124 template<
typename NumericT,
typename VectorType>
126 VectorType & cpu_vector)
128 assert(cpu_vector.end() - cpu_vector.begin() >= 0 && bool(
"Range must have nonnegative length!"));
130 if (cpu_vector.end() > cpu_vector.begin())
132 std::vector<NumericT> temp_buffer(static_cast<vcl_size_t>(cpu_vector.end() - cpu_vector.begin()));
133 viennacl::backend::memory_read(gpu_vector_range.handle(),
sizeof(NumericT)*gpu_vector_range.start(),
sizeof(NumericT)*temp_buffer.size(), &(temp_buffer[0]));
136 std::copy(temp_buffer.begin(), temp_buffer.end(), cpu_vector.begin());
146 template<
typename VectorType,
typename CPUVECTOR>
148 CPUVECTOR & cpu_vec )
158 template<
typename VectorType>
164 template<
typename VectorType>
167 assert(r1.
size() <= vec.
size() && bool(
"Size of range invalid!"));
185 template<
typename VectorType>
186 class vector_slice :
public vector_base<typename VectorType::cpu_value_type>
188 typedef vector_slice<VectorType> self_type;
189 typedef vector_base<typename VectorType::cpu_value_type> base_type;
215 using base_type::operator=;
220 template<
typename VectorType>
241 template<
typename VectorType,
typename NumericT>
242 void copy(
const VectorType & cpu_vector,
245 if (cpu_vector.size() > 0)
247 std::vector<NumericT> temp_buffer(gpu_vector_slice.stride() * gpu_vector_slice.size());
249 viennacl::backend::memory_read(gpu_vector_slice.handle(),
sizeof(NumericT)*gpu_vector_slice.start(),
sizeof(NumericT)*temp_buffer.size(), &(temp_buffer[0]));
251 for (
vcl_size_t i=0; i<cpu_vector.size(); ++i)
252 temp_buffer[i * gpu_vector_slice.stride()] = cpu_vector[i];
254 viennacl::backend::memory_write(gpu_vector_slice.handle(),
sizeof(NumericT)*gpu_vector_slice.start(),
sizeof(NumericT)*temp_buffer.size(), &(temp_buffer[0]));
265 template<
typename VectorType,
typename NumericT>
267 VectorType & cpu_vector)
269 assert(gpu_vector_slice.end() - gpu_vector_slice.begin() >= 0 && bool(
"Range must have nonnegative length!"));
271 if (gpu_vector_slice.end() - gpu_vector_slice.begin() > 0)
273 std::vector<NumericT> temp_buffer(gpu_vector_slice.stride() * gpu_vector_slice.size());
274 viennacl::backend::memory_read(gpu_vector_slice.handle(),
sizeof(NumericT)*gpu_vector_slice.start(),
sizeof(NumericT)*temp_buffer.size(), &(temp_buffer[0]));
276 for (
vcl_size_t i=0; i<cpu_vector.size(); ++i)
277 cpu_vector[i] = temp_buffer[i * gpu_vector_slice.stride()];
288 template<
typename VectorType>
291 assert(s1.
size() <= vec.size() && bool(
"Size of slice larger than vector size!"));
295 template<
typename VectorType>
298 assert(s1.
size() <= vec.
size() && bool(
"Size of slice larger than vector proxy!"));
304 template<
typename VectorType>
307 assert(r1.
size() <= vec.
size() && bool(
"Size of slice larger than vector proxy!"));
311 template<
typename VectorType>
314 assert(s1.
size() <= vec.
size() && bool(
"Size of slice larger than vector proxy!"));
viennacl::tools::shared_ptr< char > handle_type
DistanceT difference_type
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'.
VectorType::handle_type handle_type
VectorType::handle_type handle_type
VectorType::handle_type handle_type
slice::difference_type difference_type
A proxy class for entries in a vector.
This file provides the forward declarations for the main types used within ViennaCL.
vector_slice(VectorType const &v, slice const &entry_slice)
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.
VectorType::value_type value_type
viennacl::scalar< float > s1
VectorType::const_iterator const_iterator
size_type stride() const
Returns the stride within the buffer (in multiples of sizeof(NumericT))
vector_range(vector_range< VectorType > const &v, range const &entry_range)
VectorType::value_type value_type
Class for representing non-strided subvectors of a bigger vector x.
vector_range(VectorType const &v, range const &entry_range)
const value_type & const_reference
Class for representing strided subvectors of a bigger vector x.
Common base class for dense vectors, vector ranges, and vector slices.
matrix_range< MatrixType > project(MatrixType const &A, viennacl::range const &r1, viennacl::range const &r2)
void copy(vector_slice< vector< NumericT > > const &gpu_vector_slice, VectorType &cpu_vector)
VectorType::iterator iterator
VectorType::const_iterator const_iterator
vector_slice(self_type const &v, slice const &entry_slice)
VectorType::iterator iterator
vector_range(self_type const &other)
vector_range(self_type const &v, range const &entry_range)
VectorType::cpu_value_type cpu_value_type
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
Implementation of a slice object for use with proxy objects.
size_type size() const
Returns the length of the vector (cf. std::vector)
vector_range(VectorType const &v, range const &entry_range)
A range class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
vector_slice(VectorType const &v, slice const &entry_slice)
range::size_type size_type
slice::size_type size_type
Implementation of a range object for use with proxy objects.
DistanceT difference_type
VectorType::handle_type handle_type
size_type start() const
Returns the offset within the buffer.
A slice class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
const value_type & const_reference
range::difference_type difference_type
const handle_type & handle() const
Returns the memory handle.
vector_slice(vector_slice< VectorType > const &v, slice const &entry_slice)
VectorType::cpu_value_type cpu_value_type
vector_slice(self_type const &other)
void fast_copy(const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_begin, const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_end, CPU_ITERATOR cpu_begin)