Clover Git
OpenCL 1.1 software implementation
|
Base class for all the memory objects. More...
#include <memobject.h>
Public Types | |
enum | Type { Buffer, SubBuffer, Image2D, Image3D } |
Type of memory object. More... | |
Public Member Functions | |
MemObject (Context *ctx, cl_mem_flags flags, void *host_ptr, cl_int *errcode_ret) | |
Constructor. | |
~MemObject () | |
virtual cl_int | init () |
Initialize the memory object. | |
virtual bool | allocate (DeviceInterface *device) |
Allocate this memory object on the given device . | |
virtual size_t | size () const =0 |
Device-independent size of the memory object. | |
virtual Type | type () const =0 |
Type of the memory object. | |
cl_mem_flags | flags () const |
Flags. | |
void * | host_ptr () const |
Host pointer. | |
DeviceBuffer * | deviceBuffer (DeviceInterface *device) const |
Coal::DeviceBuffer for the given device | |
void | deviceAllocated (DeviceBuffer *buffer) |
Is the Coal::DeviceBuffer for buffer allocated ? | |
void | setDestructorCallback (void(CL_CALLBACK *pfn_notify)(cl_mem memobj, void *user_data), void *user_data) |
Set a destructor callback for this memory object. | |
cl_int | info (cl_mem_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) const |
Get information about this memory object. | |
Private Member Functions | |
void (CL_CALLBACK *p_dtor_callback)(cl_mem memobj | |
Private Attributes | |
unsigned int | p_num_devices |
unsigned int | p_devices_to_allocate |
cl_mem_flags | p_flags |
void * | p_host_ptr |
DeviceBuffer ** | p_devicebuffers |
void * | user_data |
void * | p_dtor_userdata |
Base class for all the memory objects.
Definition at line 50 of file memobject.h.
MemObject::MemObject | ( | Context * | ctx, |
cl_mem_flags | flags, | ||
void * | host_ptr, | ||
cl_int * | errcode_ret | ||
) |
Constructor.
ctx | parent Coal::Context |
flags | memory object flags |
host_ptr | host pointer used by some flags (see the OpenCL spec) |
errcode_ret | return value |
init()
. We only fill the private variables and check the values passed in argument. Definition at line 48 of file memobject.cpp.
MemObject::~MemObject | ( | ) |
Definition at line 90 of file memobject.cpp.
References p_devicebuffers, p_dtor_userdata, and p_num_devices.
bool MemObject::allocate | ( | DeviceInterface * | device | ) | [virtual] |
Allocate this memory object on the given device
.
Reimplemented in Coal::SubBuffer.
Definition at line 202 of file memobject.cpp.
References Coal::DeviceBuffer::allocate(), Coal::DeviceBuffer::allocated(), and deviceBuffer().
Referenced by Coal::SubBuffer::allocate(), Coal::BufferEvent::BufferEvent(), Coal::CPUKernelWorkGroup::callArgs(), Coal::CopyBufferEvent::CopyBufferEvent(), Coal::CopyBufferRectEvent::CopyBufferRectEvent(), and init().
void MemObject::deviceAllocated | ( | DeviceBuffer * | buffer | ) |
Is the Coal::DeviceBuffer
for buffer
allocated ?
Definition at line 247 of file memobject.cpp.
References p_devices_to_allocate, p_flags, p_host_ptr, p_num_devices, and void().
Referenced by Coal::CPUBuffer::allocate().
DeviceBuffer * MemObject::deviceBuffer | ( | DeviceInterface * | device | ) | const |
Coal::DeviceBuffer
for the given device
Definition at line 236 of file memobject.cpp.
References p_devicebuffers, and p_num_devices.
Referenced by allocate(), Coal::CPUKernelWorkGroup::callArgs(), Coal::CPUBuffer::CPUBuffer(), Coal::CPUKernelWorkGroup::getImageData(), Coal::CPUDevice::initEventDeviceData(), Coal::NativeKernelEvent::NativeKernelEvent(), and worker().
cl_mem_flags MemObject::flags | ( | ) | const |
Flags.
Definition at line 214 of file memobject.cpp.
References p_flags.
Referenced by Coal::CPUBuffer::allocate(), Coal::CPUBuffer::CPUBuffer(), and Coal::SubBuffer::SubBuffer().
void * MemObject::host_ptr | ( | ) | const |
Host pointer.
Definition at line 219 of file memobject.cpp.
References host_ptr(), Coal::SubBuffer::offset(), p_host_ptr, Coal::SubBuffer::parent(), and type().
Referenced by Coal::CPUBuffer::allocate(), Coal::CPUBuffer::CPUBuffer(), host_ptr(), and info().
cl_int MemObject::info | ( | cl_mem_info | param_name, |
size_t | param_value_size, | ||
void * | param_value, | ||
size_t * | param_value_size_ret | ||
) | const |
Get information about this memory object.
This function is used to retrieve information about an object. Sometimes, the size of the data retrieved is unknown (for example, a string). The application can call this function twice, the first time to get the size, then it allocates a buffer, and finally get the data.
const char *string = 0; size_t len; object->info(FOO_PROPERTY_STRING, 0, 0, &len); string = std::malloc(len); object->info(FOO_PROPERTY_STRING, len, string, 0);
param_name | Name of the property to retrieve |
param_value_size | Size of the application-allocated buffer in which to put the value. |
param_value | Pointer to an application-allocated buffer where the property data will be stored. Ignored if NULL. |
param_value_size_ret | Size of the value retrieved, ignored if NULL. |
Definition at line 277 of file memobject.cpp.
References host_ptr(), Coal::SubBuffer::offset(), p_flags, Coal::SubBuffer::parent(), Coal::Object::parent(), Coal::Object::references(), SIMPLE_ASSIGN, size(), SubBuffer, and type().
Referenced by init().
cl_int MemObject::init | ( | ) | [virtual] |
Initialize the memory object.
Memory objects are device-independent classes. This function creates one Coal::DeviceBuffer
per device present in the context by calling Coal::DeviceInterface::createDeviceBuffer()
.
If there is only one device, its Coal::DeviceBuffer
is directly allocated. If there are more than one device, the allocation is deferred until a Coal::Event
is pushed for this device.
CL_SUCCESS
if success, an error code otherwise Definition at line 105 of file memobject.cpp.
References allocate(), Coal::DeviceInterface::createDeviceBuffer(), info(), p_devicebuffers, p_devices_to_allocate, p_flags, p_host_ptr, p_num_devices, Coal::Object::parent(), and size().
Referenced by clCreateBuffer(), clCreateImage2D(), clCreateImage3D(), and clCreateSubBuffer().
void MemObject::setDestructorCallback | ( | void(CL_CALLBACK *pfn_notify)(cl_mem memobj,void *user_data) | , |
void * | user_data | ||
) |
Set a destructor callback for this memory object.
This callback is called when this memory object is deleted. It is currently called from the destructor, so the memory object is already invalid, but as OpenCL objects are immutable, the callback cannot use its memobj
parameter except in a pointer comparison, and there is no problem.
pfn_notify | function to call when the memory object is deleted |
user_data | user data to pass to this function |
Definition at line 266 of file memobject.cpp.
References p_dtor_userdata, and user_data.
virtual size_t Coal::MemObject::size | ( | ) | const [pure virtual] |
Device-independent size of the memory object.
Implemented in Coal::Buffer, Coal::SubBuffer, Coal::Image2D, and Coal::Image3D.
Referenced by Coal::CPUBuffer::allocate(), Coal::CopyBufferEvent::CopyBufferEvent(), Coal::CopyBufferRectEvent::CopyBufferRectEvent(), Coal::CopyBufferToImageEvent::CopyBufferToImageEvent(), Coal::CopyImageToBufferEvent::CopyImageToBufferEvent(), info(), init(), Coal::MapBufferEvent::MapBufferEvent(), Coal::ReadWriteBufferEvent::ReadWriteBufferEvent(), and Coal::ReadWriteBufferRectEvent::ReadWriteBufferRectEvent().
virtual Type Coal::MemObject::type | ( | ) | const [pure virtual] |
Type of the memory object.
Reimplemented from Coal::Object.
Implemented in Coal::Buffer, Coal::SubBuffer, Coal::Image2D, and Coal::Image3D.
Referenced by Coal::CPUBuffer::allocate(), clCreateSubBuffer(), Coal::CPUBuffer::CPUBuffer(), host_ptr(), info(), and Coal::BufferEvent::isSubBufferAligned().
Coal::MemObject::void | ( | CL_CALLBACK * | p_dtor_callback | ) | [private] |
Referenced by deviceAllocated().
DeviceBuffer** Coal::MemObject::p_devicebuffers [private] |
Definition at line 131 of file memobject.h.
Referenced by deviceBuffer(), init(), and ~MemObject().
unsigned int Coal::MemObject::p_devices_to_allocate [private] |
Definition at line 128 of file memobject.h.
Referenced by deviceAllocated(), and init().
void* Coal::MemObject::p_dtor_userdata [private] |
Definition at line 134 of file memobject.h.
Referenced by setDestructorCallback(), and ~MemObject().
cl_mem_flags Coal::MemObject::p_flags [private] |
Definition at line 129 of file memobject.h.
Referenced by deviceAllocated(), flags(), info(), and init().
void* Coal::MemObject::p_host_ptr [private] |
Definition at line 130 of file memobject.h.
Referenced by deviceAllocated(), host_ptr(), and init().
unsigned int Coal::MemObject::p_num_devices [private] |
Definition at line 128 of file memobject.h.
Referenced by deviceAllocated(), deviceBuffer(), init(), and ~MemObject().
void* Coal::MemObject::user_data [private] |
Definition at line 133 of file memobject.h.
Referenced by setDestructorCallback().