1 #ifndef VIENNACL_BACKEND_MEM_HANDLE_HPP
2 #define VIENNACL_BACKEND_MEM_HANDLE_HPP
31 #ifdef VIENNACL_WITH_OPENCL
35 #ifdef VIENNACL_WITH_CUDA
47 #ifdef VIENNACL_WITH_CUDA
49 #elif defined(VIENNACL_WITH_OPENCL)
76 #ifdef VIENNACL_WITH_OPENCL
83 #ifdef VIENNACL_WITH_CUDA
96 if (new_id != active_handle_)
99 active_handle_ = new_id;
102 active_handle_ = new_id;
106 #ifdef VIENNACL_WITH_OPENCL
107 active_handle_ = new_id;
109 throw "compiled without OpenCL suppport!";
114 #ifdef VIENNACL_WITH_CUDA
115 active_handle_ = new_id;
117 throw "compiled without CUDA suppport!";
121 throw "invalid new memory region!";
128 if (active_handle_ != other.active_handle_)
131 switch (active_handle_)
134 return ram_handle_.
get() == other.ram_handle_.
get();
135 #ifdef VIENNACL_WITH_OPENCL
137 return opencl_handle_.get() == other.opencl_handle_.get();
139 #ifdef VIENNACL_WITH_CUDA
141 return cuda_handle_.get() == other.cuda_handle_.get();
154 if (active_handle_ != other.active_handle_)
157 switch (active_handle_)
160 return ram_handle_.
get() < other.ram_handle_.
get();
161 #ifdef VIENNACL_WITH_OPENCL
163 return opencl_handle_.get() < other.opencl_handle_.get();
165 #ifdef VIENNACL_WITH_CUDA
167 return cuda_handle_.get() < other.cuda_handle_.get();
183 other.active_handle_ = active_handle_;
184 active_handle_ = active_handle_tmp;
188 other.ram_handle_ = ram_handle_;
189 ram_handle_ = ram_handle_tmp;
192 #ifdef VIENNACL_WITH_OPENCL
193 opencl_handle_.
swap(other.opencl_handle_);
195 #ifdef VIENNACL_WITH_CUDA
197 other.cuda_handle_ = cuda_handle_;
198 cuda_handle_ = cuda_handle_tmp;
211 #ifdef VIENNACL_WITH_OPENCL
214 #ifdef VIENNACL_WITH_CUDA
std::size_t vcl_size_t
Definition: forwards.h:58
Definition: forwards.h:478
ram_handle_type & ram_handle()
Returns the handle to a buffer in CPU RAM. NULL is returned if no such buffer has been allocated...
Definition: mem_handle.hpp:72
viennacl::tools::shared_ptr< char > cuda_handle_type
Definition: mem_handle.hpp:66
void raw_size(vcl_size_t new_size)
Sets the size of the currently active buffer. Use with care!
Definition: mem_handle.hpp:206
This file provides the forward declarations for the main types used within ViennaCL.
bool operator==(mem_handle const &other) const
Compares the two handles and returns true if the active memory handles in the two mem_handles point t...
Definition: mem_handle.hpp:126
Definition: forwards.h:481
memory_types
Definition: forwards.h:476
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
Implementation of a shared pointer class (cf. std::shared_ptr, boost::shared_ptr). Will be used until C++11 is widely available.
bool operator!=(mem_handle const &other) const
Definition: mem_handle.hpp:176
Definition: forwards.h:480
Implementations for the OpenCL backend functionality.
viennacl::tools::shared_ptr< char > ram_handle_type
Definition: mem_handle.hpp:65
bool operator<(mem_handle const &other) const
Compares the two handles and returns true if the active memory handles in the two mem_handles point a...
Definition: mem_handle.hpp:152
Implementations for the CUDA backend functionality.
mem_handle()
Default CTOR. No memory is allocated.
Definition: mem_handle.hpp:69
memory_types default_memory_type()
Definition: mem_handle.hpp:52
ram_handle_type const & ram_handle() const
Returns the handle to a buffer in CPU RAM. NULL is returned if no such buffer has been allocated...
Definition: mem_handle.hpp:74
vcl_size_t raw_size() const
Returns the number of bytes of the currently active buffer.
Definition: mem_handle.hpp:203
Definition: forwards.h:479
void swap(mem_handle &other)
Implements a fast swapping method. No data is copied, only the handles are exchanged.
Definition: mem_handle.hpp:179
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:62
void switch_active_handle_id(memory_types new_id)
Switches the currently active handle. If no support for that backend is provided, an exception is thr...
Definition: mem_handle.hpp:94
Implementations for the OpenCL backend functionality.