...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::compute::mapped_view — A mapped view of host memory.
// In header: <boost/compute/container/mapped_view.hpp> template<typename T> class mapped_view { public: // types typedef T value_type; typedef size_t size_type; typedef ptrdiff_t difference_type; typedef buffer_iterator< T > iterator; typedef buffer_iterator< T > const_iterator; // construct/copy/destruct mapped_view(); mapped_view(T *, size_type, const context & = system::default_context()); mapped_view(const T *, size_type, const context & = system::default_context()); mapped_view(const mapped_view< T > &); mapped_view< T > & operator=(const mapped_view< T > &); ~mapped_view(); // public member functions iterator begin(); const_iterator begin() const; const_iterator cbegin() const; iterator end(); const_iterator end() const; const_iterator cend() const; size_type size() const; T * get_host_ptr(); const T * get_host_ptr() const; void resize(size_type); bool empty() const; const buffer & get_buffer() const; void map(cl_map_flags, command_queue &); void map(command_queue &); void unmap(command_queue &); };
The mapped_view class simplifies mapping host-memory to a compute device. This allows for host-allocated memory to be used with the Boost.Compute algorithms.
The following example shows how to map a simple C-array containing data on the host to the device and run the reduce() algorithm to calculate the sum:
See Also:
buffer
mapped_view
public
construct/copy/destructmapped_view();Creates a null
mapped_view
object. mapped_view(T * host_ptr, size_type n, const context & context = system::default_context());
Creates a mapped_view
for host_ptr
with n
elements. After constructing a mapped_view
the data is available for use by a compute device. Use the unmap()
method to make the updated data available to the host.
mapped_view(const T * host_ptr, size_type n, const context & context = system::default_context());
Creates a read-only mapped_view
for host_ptr
with n
elements. After constructing a mapped_view
the data is available for use by a compute device. Use the unmap()
method to make the updated data available to the host.
mapped_view(const mapped_view< T > & other);Creates a copy of
other
. mapped_view< T > & operator=(const mapped_view< T > & other);Copies the mapped buffer from
other
. ~mapped_view();Destroys the
mapped_view
object. mapped_view
public member functionsiterator begin();Returns an iterator to the first element in the
mapped_view
. const_iterator begin() const;Returns a const_iterator to the first element in the
mapped_view
. const_iterator cbegin() const;Returns a const_iterator to the first element in the
mapped_view
. iterator end();Returns an iterator to one past the last element in the
mapped_view
. const_iterator end() const;Returns a const_iterator to one past the last element in the
mapped_view
. const_iterator cend() const;Returns a const_iterator to one past the last element in the
mapped_view
. size_type size() const;Returns the number of elements in the
mapped_view
. T * get_host_ptr();Returns the host data pointer.
const T * get_host_ptr() const;Returns the host data pointer.
void resize(size_type size);Resizes the
mapped_view
to size
elements. bool empty() const;Returns
true
if the mapped_view
is empty. const buffer & get_buffer() const;Returns the mapped buffer.
void map(cl_map_flags flags, command_queue & queue);
Maps the buffer into the host address space.
See the documentation for clEnqueueMapBuffer() for more information.
void map(command_queue & queue);
Maps the buffer into the host address space for reading and writing.
Equivalent to:
map(CL_MAP_READ | CL_MAP_WRITE, queue);
void unmap(command_queue & queue);
Unmaps the buffer from the host address space.
See the documentation for clEnqueueUnmapMemObject() for more information.