-
Notifications
You must be signed in to change notification settings - Fork 0
Buffer
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.
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
- Get / set pointer to host data:
void* getPtr();
void setPtr(void* data_ptr);
Note: You can use any host ptr to store data!
- Get buffer size:
std::size_t getSize() const;
- Get buffer access type:
ACCESS getAccess() const;
- Get buffer by context:
cl_mem getBuffer(cl_context context) const;
Also you can use (copy / move) (constructors / operators=):
- 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
- 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`
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
:
Twitter: Architector
e-mail: olegsajaxov@yandex.ru
Wiki
Getting started
API