1 #ifndef VIENNACL_BACKEND_UTIL_HPP
2 #define VIENNACL_BACKEND_UTIL_HPP
31 #ifdef VIENNACL_WITH_OPENCL
54 #ifdef VIENNACL_WITH_OPENCL
56 struct convert_to_opencl<unsigned int>
64 struct convert_to_opencl<int>
73 struct convert_to_opencl<unsigned long>
75 typedef cl_ulong
type;
81 struct convert_to_opencl<long>
94 template <typename T, bool special = detail::convert_to_opencl<T>::special>
117 buffer_size_ =
sizeof(cpu_type) * num;
122 delete[] bytes_buffer_;
124 bytes_buffer_ =
new char[buffer_size_];
136 bytes_buffer_[i] = 0;
144 template <
typename U>
147 reinterpret_cast<cpu_type *
>(bytes_buffer_)[index] = static_cast<cpu_type>(value);
150 void *
get() {
return reinterpret_cast<void *
>(bytes_buffer_); }
153 assert(index <
size() &&
bool(
"index out of bounds"));
155 return reinterpret_cast<cpu_type *
>(bytes_buffer_)[index];
161 return sizeof(cpu_type);
166 char * bytes_buffer_;
174 template <
typename T>
197 buffer_size_ =
sizeof(cpu_type) * num;
200 #ifdef VIENNACL_WITH_OPENCL
207 convert_to_opencl_ =
true;
208 buffer_size_ =
sizeof(target_type) * num;
215 delete[] bytes_buffer_;
217 bytes_buffer_ =
new char[buffer_size_];
229 bytes_buffer_[i] = 0;
237 template <
typename U>
240 #ifdef VIENNACL_WITH_OPENCL
241 if (convert_to_opencl_)
242 reinterpret_cast<target_type *
>(bytes_buffer_)[index] = static_cast<target_type>(value);
245 reinterpret_cast<cpu_type *
>(bytes_buffer_)[index] = static_cast<cpu_type>(value);
248 void *
get() {
return reinterpret_cast<void *
>(bytes_buffer_); }
251 assert(index <
size() &&
bool(
"index out of bounds"));
252 #ifdef VIENNACL_WITH_OPENCL
253 if (convert_to_opencl_)
254 return static_cast<cpu_type
>(
reinterpret_cast<target_type *
>(bytes_buffer_)[index]);
256 return reinterpret_cast<cpu_type *
>(bytes_buffer_)[index];
262 #ifdef VIENNACL_WITH_OPENCL
263 if (convert_to_opencl_)
264 return sizeof(target_type);
266 return sizeof(cpu_type);
271 bool convert_to_opencl_;
272 char * bytes_buffer_;
T type
Definition: util.hpp:50
Helper class implementing an array on the host. Default case: No conversion necessary.
Definition: util.hpp:95
vcl_size_t raw_size() const
Definition: util.hpp:259
std::size_t vcl_size_t
Definition: forwards.h:58
Definition: forwards.h:478
vcl_size_t size() const
Definition: util.hpp:163
void set(vcl_size_t index, U value)
Definition: util.hpp:238
typesafe_host_array(mem_handle const &handle, vcl_size_t num=0)
Definition: util.hpp:103
cpu_type operator[](vcl_size_t index) const
Definition: util.hpp:249
cpu_type operator[](vcl_size_t index) const
Definition: util.hpp:151
This file provides the forward declarations for the main types used within ViennaCL.
vcl_size_t raw_size() const
Definition: util.hpp:158
memory_types
Definition: forwards.h:476
~typesafe_host_array()
Definition: util.hpp:108
void set(vcl_size_t index, U value)
Definition: util.hpp:145
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...
Definition: mem_handle.hpp:91
~typesafe_host_array()
Definition: util.hpp:188
void resize(mem_handle const &handle, vcl_size_t num)
Resize including initialization of new memory (cf. std::vector<>)
Definition: util.hpp:129
Definition: forwards.h:480
Implements the multi-memory-domain handle.
memory_types default_memory_type()
Definition: mem_handle.hpp:52
void resize(mem_handle const &handle, vcl_size_t num)
Resize including initialization of new memory (cf. std::vector<>)
Definition: util.hpp:222
typesafe_host_array()
Definition: util.hpp:101
vcl_size_t element_size() const
Definition: util.hpp:260
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:62
vcl_size_t size() const
Definition: util.hpp:268
typesafe_host_array(mem_handle const &handle, vcl_size_t num=0)
Definition: util.hpp:183
Implementations for the OpenCL backend functionality.
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
typesafe_host_array()
Definition: util.hpp:181
void raw_resize(mem_handle const &, vcl_size_t num)
Resize without initializing the new memory.
Definition: util.hpp:115
void raw_resize(mem_handle const &handle, vcl_size_t num)
Resize without initializing the new memory.
Definition: util.hpp:195
vcl_size_t element_size() const
Definition: util.hpp:159
Helper struct for converting a type to its OpenCL pendant.
Definition: util.hpp:48