Clover Git
OpenCL 1.1 software implementation
Public Types | Public Member Functions | Private Member Functions | Private Attributes

Coal::MemObject Class Reference

Base class for all the memory objects. More...

#include <memobject.h>

Inheritance diagram for Coal::MemObject:
Collaboration diagram for Coal::MemObject:

List of all members.

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.
DeviceBufferdeviceBuffer (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

Detailed Description

Base class for all the memory objects.

Definition at line 50 of file memobject.h.


Member Enumeration Documentation

Type of memory object.

Enumerator:
Buffer 
SubBuffer 
Image2D 
Image3D 

Reimplemented from Coal::Object.

Definition at line 56 of file memobject.h.


Constructor & Destructor Documentation

MemObject::MemObject ( Context ctx,
cl_mem_flags  flags,
void *  host_ptr,
cl_int *  errcode_ret 
)

Constructor.

Parameters:
ctxparent Coal::Context
flagsmemory object flags
host_ptrhost pointer used by some flags (see the OpenCL spec)
errcode_retreturn value
Note:
Don't do any initialization here, but in init(). We only fill the private variables and check the values passed in argument.
See also:
init

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.


Member Function Documentation

bool MemObject::allocate ( DeviceInterface device) [virtual]
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
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
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);
Parameters:
param_nameName of the property to retrieve
param_value_sizeSize of the application-allocated buffer in which to put the value.
param_valuePointer to an application-allocated buffer where the property data will be stored. Ignored if NULL.
param_value_size_retSize of the value retrieved, ignored if NULL.
Returns:
CL_SUCCESS in case of success, otherwise a CL error code.

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.

Returns:
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.

Parameters:
pfn_notifyfunction to call when the memory object is deleted
user_datauser 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]
virtual Type Coal::MemObject::type ( ) const [pure virtual]
Coal::MemObject::void ( CL_CALLBACK *  p_dtor_callback) [private]

Referenced by deviceAllocated().


Member Data Documentation

Definition at line 131 of file memobject.h.

Referenced by deviceBuffer(), init(), and ~MemObject().

Definition at line 128 of file memobject.h.

Referenced by deviceAllocated(), and init().

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().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines