boost::compute::buffer — A memory buffer on a compute device.
// In header: <boost/compute/buffer.hpp> class buffer : public boost::compute::memory_object { public: // construct/copy/destruct buffer(); explicit buffer(cl_mem, bool = true); buffer(const context &, size_t, cl_mem_flags = read_write, void * = 0); buffer(const buffer &); buffer(buffer &&) noexcept; buffer & operator=(const buffer &); buffer & operator=(buffer &&) noexcept; ~buffer(); // public member functions size_t size() const; template<typename T> T get_info(cl_mem_info) const; template<int Enum> unspecified get_info() const; buffer clone(command_queue &) const; buffer create_subbuffer(cl_mem_flags, size_t, size_t); };
The buffer class represents a memory buffer on a compute device.
Buffers are allocated within a compute context. For example, to allocate a memory buffer for 32 float's:
boost::compute::buffer buf(context, 32 * sizeof(float));
Once created, data can be copied to and from the buffer using the enqueue_*_buffer
() methods in the command_queue class. For example, to copy a set of int
values from the host to the device:
int data[] = { 1, 2, 3, 4 }; queue.enqueue_write_buffer(buf, 0, 4 * sizeof(int), data);
Also see the copy() algorithm for a higher-level interface to copying data between the host and the device. For a higher-level, dynamically-resizable, type-safe container for data on a compute device, use the vector<T> class.
Buffer objects have reference semantics. Creating a copy of a buffer object simply creates another reference to the underlying OpenCL memory object. To create an actual copy use the buffer::clone() method.
See Also:
buffer
public
construct/copy/destructbuffer();Creates a null buffer object.
explicit buffer(cl_mem mem, bool retain = true);
Creates a buffer object for mem
. If retain
is true
, the reference count for mem
will be incremented.
buffer(const context & context, size_t size, cl_mem_flags flags = read_write, void * host_ptr = 0);
Create a new memory buffer in of size
with flags
in context
.
See the documentation for clCreateBuffer() for more information.
buffer(const buffer & other);Creates a new buffer object as a copy of
other
. buffer(buffer && other) noexcept;Move-constructs a new buffer object from
other
. buffer & operator=(const buffer & other);Copies the buffer object from
other
to *this
. buffer & operator=(buffer && other) noexcept;Move-assigns the buffer from
other
to *this
. ~buffer();Destroys the buffer object.
buffer
public member functionssize_t size() const;Returns the size of the buffer in bytes.
template<typename T> T get_info(cl_mem_info info) const;
Returns information about the buffer.
See the documentation for clGetMemObjectInfo() for more information.
template<int Enum> unspecified get_info() const;
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
buffer clone(command_queue & queue) const;
Creates a new buffer with a copy of the data in *this
. Uses queue
to perform the copy.
buffer create_subbuffer(cl_mem_flags flags, size_t origin, size_t size);
Creates a new buffer out of this buffer. The new buffer is a sub region of this buffer. flags
The mem_flags which should be used to create the new buffer origin
The start index in this buffer size
The size of the new sub buffer
See the documentation for clCreateSubBuffer() for more information.
![]() |
Warning |
---|---|
This method is only available if the OpenCL version is 1.1 or later. |