Skip to content
Architector edited this page Apr 19, 2019 · 18 revisions

The buffer is an abstraction that allows you to manage data between host and the device.

Constructor

ecl::Buffer(void* ptr, std::size_t size, ecl::ACCESS access); 

Note: Creating new buffer means create some abstract object. Physically, memory will allocate on device when method createBuffer will be called!

Example:

int A[] = {1, 2, 3};
auto buf = ecl::Buffer(A, 3 * sizeof(int), ecl::ACCESS::READ_WRITE);

Note:

ecl::ACCESS::READ; // read-only data
ecl::ACCESS::WRITE; // write-only data
ecl::ACCESS::READ_WRITE; // default

Getters / setters:

  1. Get / set pointer to host data:
void* getPtr();
void setPtr(void* data_ptr);

Note: You can use any host ptr to store data!

  1. Get buffer size:
std::size_t getSize() const;
  1. Get buffer access type:
ACCESS getAccess() const;
  1. Get buffer by context:
cl_mem getBuffer(cl_context context) const;

Copy / move

Also you can use (copy / move) (constructors / operators=):

  1. Copy:
Buffer(const Buffer&);
buffer = const Buffer&;

Example:

int A[] = {1, 2, 3};
auto buf = ecl::Buffer(A, 3 * sizeof(int), ecl::ACCESS::READ_WRITE);
auto buf2 = buf; // same pointer, new buffer
  1. Move:
Buffer(Buffer&&);
buffer = std::move(Buffer&&);

Example:

int A[] = {1, 2, 3};
auto buf = ecl::Buffer(A, 3 * sizeof(int), ecl::ACCESS::READ_WRITE);
auto buf2 = std::move(buf); // just grabs buffer from `buf`

Device context

bool checkBuffer(cl_context context) const; // check if buffer created for current context
void createBuffer(cl_context context); // create buffer for current context (if not created yet)
void releaseBuffer(cl_context context); // clear buffer for current context

Totally, ecl::Buffer is still a low-level abstraction in EasyCL API. There are two different high-level containers that are inherited from Buffer:

Clone this wiki locally