Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Class template mapped_view

boost::compute::mapped_view — A mapped view of host memory.

Synopsis

// 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 &);
};

Description

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/destruct

  1. mapped_view();
    Creates a null mapped_view object.
  2. 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.

  3. 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.

  4. mapped_view(const mapped_view< T > & other);
    Creates a copy of other.
  5. mapped_view< T > & operator=(const mapped_view< T > & other);
    Copies the mapped buffer from other.
  6. ~mapped_view();
    Destroys the mapped_view object.

mapped_view public member functions

  1. iterator begin();
    Returns an iterator to the first element in the mapped_view.
  2. const_iterator begin() const;
    Returns a const_iterator to the first element in the mapped_view.
  3. const_iterator cbegin() const;
    Returns a const_iterator to the first element in the mapped_view.
  4. iterator end();
    Returns an iterator to one past the last element in the mapped_view.
  5. const_iterator end() const;
    Returns a const_iterator to one past the last element in the mapped_view.
  6. const_iterator cend() const;
    Returns a const_iterator to one past the last element in the mapped_view.
  7. size_type size() const;
    Returns the number of elements in the mapped_view.
  8. T * get_host_ptr();
    Returns the host data pointer.
  9. const T * get_host_ptr() const;
    Returns the host data pointer.
  10. void resize(size_type size);
    Resizes the mapped_view to size elements.
  11. bool empty() const;
    Returns true if the mapped_view is empty.
  12. const buffer & get_buffer() const;
    Returns the mapped buffer.
  13. 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.

  14. 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);
    

  15. void unmap(command_queue & queue);

    Unmaps the buffer from the host address space.

    See the documentation for clEnqueueUnmapMemObject() for more information.


PrevUpHomeNext